add image clarity detection

This commit is contained in:
2025-03-05 17:43:59 +08:00
parent c0d0d784d6
commit d8d98eb31c
22 changed files with 850 additions and 64 deletions

View File

@@ -0,0 +1,48 @@
package storage
import (
"context"
"errors"
"schisandra-album-cloud-microservices/common/constant"
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteStorageConfigLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteStorageConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteStorageConfigLogic {
return &DeleteStorageConfigLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteStorageConfigLogic) DeleteStorageConfig(req *types.DeleteStorageConfigRequest) (resp string, err error) {
uid, ok := l.ctx.Value("user_id").(string)
if !ok {
return "", errors.New("user_id not found")
}
storageConfig := l.svcCtx.DB.ScaStorageConfig
info, err := storageConfig.Where(storageConfig.ID.Eq(req.ID), storageConfig.UserID.Eq(uid),
storageConfig.Provider.Eq(req.Provider), storageConfig.Bucket.Eq(req.Bucket)).Delete()
if err != nil {
return "", err
}
if info.RowsAffected == 0 {
return "", errors.New("storage config not found")
}
cacheOssConfigKey := constant.UserOssConfigPrefix + uid + ":" + req.Provider
err = l.svcCtx.RedisClient.Del(l.ctx, cacheOssConfigKey).Err()
if err != nil {
return "", err
}
return "success", nil
}

View File

@@ -0,0 +1,63 @@
package storage
import (
"context"
"errors"
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ListUserStorageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewListUserStorageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListUserStorageLogic {
return &ListUserStorageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListUserStorageLogic) ListUserStorage() (resp *types.StorageConfigListResponse, err error) {
uid, ok := l.ctx.Value("user_id").(string)
if !ok {
return nil, errors.New("user_id not found")
}
storageConfig := l.svcCtx.DB.ScaStorageConfig
storageConfigList, err := storageConfig.Select(
storageConfig.ID,
storageConfig.Provider,
storageConfig.Bucket,
storageConfig.Capacity,
storageConfig.CreatedAt,
storageConfig.Region,
storageConfig.Endpoint).
Where(storageConfig.UserID.Eq(uid)).
Order(storageConfig.CreatedAt.Desc()).
Find()
if err != nil {
return nil, err
}
var result []types.StorageConfigMeta
for _, info := range storageConfigList {
result = append(result, types.StorageConfigMeta{
ID: info.ID,
Provider: info.Provider,
Endpoint: info.Endpoint,
Bucket: info.Bucket,
Capacity: info.Capacity,
Region: info.Region,
CreatedAt: info.CreatedAt.Format("2006-01-02"),
})
}
return &types.StorageConfigListResponse{
Records: result,
}, nil
}

View File

@@ -70,7 +70,7 @@ func (l *SearchImageLogic) SearchImage(req *types.SearchImageRequest) (resp *typ
// 标签和分类匹配
addThingQuery(baseQuery, req.Keyword)
case "picture":
// 图片属性匹配(示例:文件类型)
// 图片属性匹配
addPictureQuery(baseQuery, req.Keyword)
case "location":
addLocationQuery(baseQuery, req.Keyword)
@@ -213,8 +213,8 @@ func addTimeRangeQuery(query map[string]interface{}, start, end int64) {
timeQuery := map[string]interface{}{
"range": map[string]interface{}{
"created_at": map[string]interface{}{ // 改为使用 created_at 字段
"gte": start * 1000, // 转换为毫秒(根据格式决定)
"lte": end * 1000,
"gte": start,
"lte": end,
},
},
}
@@ -243,12 +243,12 @@ func addPictureQuery(query map[string]interface{}, keyword string) {
"should": []map[string]interface{}{
{
"wildcard": map[string]interface{}{
"file_name": "*" + strings.ToLower(keyword) + "*",
"tag_name": "*" + strings.ToLower(keyword) + "*",
},
},
{
"term": map[string]interface{}{
"file_type": strings.ToLower(keyword),
"top_category": strings.ToLower(keyword),
},
},
},
@@ -264,13 +264,13 @@ func addPictureQuery(query map[string]interface{}, keyword string) {
// 添加人脸ID查询
func addFaceIDQuery(query map[string]interface{}, faceID int64) {
must := query["query"].(map[string]interface{})["bool"].(map[string]interface{})["must"]
must := query["query"].(map[string]interface{})["bool"].(map[string]interface{})["must"].([]map[string]interface{})
idQuery := map[string]interface{}{
"term": map[string]interface{}{
"face_id": faceID,
},
}
query["query"].(map[string]interface{})["bool"].(map[string]interface{})["must"] = append(must.([]map[string]interface{}), idQuery)
query["query"].(map[string]interface{})["bool"].(map[string]interface{})["must"] = append(must, idQuery)
}
func addLocationQuery(query map[string]interface{}, keyword string) {

View File

@@ -40,7 +40,7 @@ func (l *SetStorageConfigLogic) SetStorageConfig(req *types.StorageConfigRequest
}
ossConfig := &model.ScaStorageConfig{
UserID: uid,
Provider: req.Type,
Provider: req.Provider,
Endpoint: req.Endpoint,
Bucket: req.Bucket,
AccessKey: accessKey,