feat: add image management functionality

- Implemented image folder repository with CRUD operations.
- Added image reference repository for managing image references to articles.
- Created image repository for handling image assets, including listing, inserting, updating, and deleting images.
- Introduced image usage repository to track storage usage and quotas for tenants.
- Added SQL queries for image assets, folders, references, and usage.
- Developed image handler for HTTP endpoints to manage images and folders.
- Created database migration scripts for image-related tables and structures.
This commit is contained in:
2026-04-16 20:40:41 +08:00
parent 0a3558fc51
commit 27389164b0
57 changed files with 8063 additions and 153 deletions
@@ -158,6 +158,36 @@ func (c *aliyunClient) GetBytes(ctx context.Context, objectKey string) ([]byte,
return data, nil
}
func (c *aliyunClient) Exists(ctx context.Context, objectKey string) (bool, error) {
if err := c.Validate(); err != nil {
return false, err
}
if strings.TrimSpace(objectKey) == "" {
return false, nil
}
bucket, err := c.client.Bucket(c.bucket)
if err != nil {
c.logError(ctx, "aliyun get bucket failed",
zap.String("bucket", c.bucket),
zap.String("object_key", objectKey),
zap.Error(err),
)
return false, fmt.Errorf("get aliyun bucket: %w", err)
}
exists, err := bucket.IsObjectExist(objectKey)
if err != nil {
c.logError(ctx, "aliyun stat object failed",
zap.String("bucket", c.bucket),
zap.String("object_key", objectKey),
zap.Error(err),
)
return false, fmt.Errorf("stat aliyun object: %w", err)
}
return exists, nil
}
func (c *aliyunClient) Delete(ctx context.Context, objectKey string) error {
if err := c.Validate(); err != nil {
return err
@@ -17,6 +17,7 @@ type Client interface {
Validate() error
PutBytes(ctx context.Context, objectKey string, content []byte, contentType string) error
GetBytes(ctx context.Context, objectKey string) ([]byte, error)
Exists(ctx context.Context, objectKey string) (bool, error)
Delete(ctx context.Context, objectKey string) error
PublicURL(objectKey string) (string, error)
}
@@ -54,6 +55,10 @@ func (c disabledClient) GetBytes(context.Context, string) ([]byte, error) {
return nil, c.Validate()
}
func (c disabledClient) Exists(context.Context, string) (bool, error) {
return false, c.Validate()
}
func (c disabledClient) Delete(context.Context, string) error {
return c.Validate()
}
@@ -135,6 +135,32 @@ func (c *minioClient) GetBytes(ctx context.Context, objectKey string) ([]byte, e
return data, nil
}
func (c *minioClient) Exists(ctx context.Context, objectKey string) (bool, error) {
if err := c.Validate(); err != nil {
return false, err
}
if strings.TrimSpace(objectKey) == "" {
return false, nil
}
_, err := c.client.StatObject(ctx, c.bucket, objectKey, minio.StatObjectOptions{})
if err == nil {
return true, nil
}
responseErr := minio.ToErrorResponse(err)
if responseErr.StatusCode == 404 || responseErr.Code == "NoSuchKey" || responseErr.Code == "NoSuchObject" {
return false, nil
}
c.logError(ctx, "minio stat object failed",
zap.String("bucket", c.bucket),
zap.String("object_key", objectKey),
zap.Error(err),
)
return false, fmt.Errorf("stat minio object: %w", err)
}
func (c *minioClient) Delete(ctx context.Context, objectKey string) error {
if err := c.Validate(); err != nil {
return err