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

@@ -434,7 +434,7 @@ service auth {
// 文件上传配置请求参数
type (
StorageConfigRequest {
Type string `json:"type"`
Provider string `json:"provider"`
AccessKey string `json:"access_key"`
SecretKey string `json:"secret_key"`
Endpoint string `json:"endpoint"`
@@ -664,11 +664,10 @@ type (
}
// 搜索图片请求参数
SearchImageRequest {
Type string `json:"type"`
Keyword string `json:"keyword"`
Provider string `json:"provider"`
Bucket string `json:"bucket"`
InputImage string `json:"input_image,omitempty"`
Type string `json:"type"`
Keyword string `json:"keyword"`
Provider string `json:"provider"`
Bucket string `json:"bucket"`
}
// 搜索图片相应参数
SearchImageResponse {
@@ -689,6 +688,23 @@ type (
Provider string `json:"provider"`
Bucket string `json:"bucket"`
}
StorageConfigMeta {
ID int64 `json:"id"`
Provider string `json:"provider"`
Endpoint string `json:"endpoint"`
Bucket string `json:"bucket"`
Region string `json:"region"`
Capacity int64 `json:"capacity"`
CreatedAt string `json:"created_at"`
}
StorageConfigListResponse {
Records []StorageConfigMeta `json:"records"`
}
DeleteStorageConfigRequest {
ID int64 `json:"id"`
Provider string `json:"provider"`
Bucket string `json:"bucket"`
}
)
// 文件上传
@@ -710,7 +726,7 @@ service auth {
// 设置存储配置
@handler setStorageConfig
post /config (StorageConfigRequest) returns (string)
post /config/add (StorageConfigRequest) returns (string)
// 获取人脸样本库列表
@handler getFaceSampleLibraryList
@@ -811,6 +827,14 @@ service auth {
// 添加图片到相册
@handler addImageToAlbum
post /album/add/image (AddImageToAlbumRequest) returns (string)
//列举用户所有存储商
@handler listUserStorage
post /user/storage/list returns (StorageConfigListResponse)
// 删除存储配置
@handler deleteStorageConfig
post /config/delete (DeleteStorageConfigRequest) returns (string)
}
type (

View File

@@ -309,9 +309,14 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/config",
Path: "/config/add",
Handler: storage.SetStorageConfigHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/config/delete",
Handler: storage.DeleteStorageConfigHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/delete/record",
@@ -392,6 +397,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/user/config/list",
Handler: storage.GetUserStorageListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/user/storage/list",
Handler: storage.ListUserStorageHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),

View File

@@ -0,0 +1,29 @@
package storage
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/storage"
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
"schisandra-album-cloud-microservices/common/xhttp"
)
func DeleteStorageConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteStorageConfigRequest
if err := httpx.Parse(r, &req); err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
return
}
l := storage.NewDeleteStorageConfigLogic(r.Context(), svcCtx)
resp, err := l.DeleteStorageConfig(&req)
if err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
} else {
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,21 @@
package storage
import (
"net/http"
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/storage"
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
"schisandra-album-cloud-microservices/common/xhttp"
)
func ListUserStorageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := storage.NewListUserStorageLogic(r.Context(), svcCtx)
resp, err := l.ListUserStorage()
if err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
} else {
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
}
}
}

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,

View File

@@ -182,6 +182,12 @@ type DeleteShareRecordRequest struct {
AlbumID int64 `json:"album_id"`
}
type DeleteStorageConfigRequest struct {
ID int64 `json:"id"`
Provider string `json:"provider"`
Bucket string `json:"bucket"`
}
type DownloadAlbumRequest struct {
ID int64 `json:"id"`
Provider string `json:"provider"`
@@ -384,11 +390,10 @@ type SearchAlbumResponse struct {
}
type SearchImageRequest struct {
Type string `json:"type"`
Keyword string `json:"keyword"`
Provider string `json:"provider"`
Bucket string `json:"bucket"`
InputImage string `json:"input_image,omitempty"`
Type string `json:"type"`
Keyword string `json:"keyword"`
Provider string `json:"provider"`
Bucket string `json:"bucket"`
}
type SearchImageResponse struct {
@@ -495,8 +500,22 @@ type SmsSendRequest struct {
Key string `json:"key"`
}
type StorageConfigListResponse struct {
Records []StorageConfigMeta `json:"records"`
}
type StorageConfigMeta struct {
ID int64 `json:"id"`
Provider string `json:"provider"`
Endpoint string `json:"endpoint"`
Bucket string `json:"bucket"`
Region string `json:"region"`
Capacity int64 `json:"capacity"`
CreatedAt string `json:"created_at"`
}
type StorageConfigRequest struct {
Type string `json:"type"`
Provider string `json:"provider"`
AccessKey string `json:"access_key"`
SecretKey string `json:"secret_key"`
Endpoint string `json:"endpoint"`