🚧 developing...

This commit is contained in:
2025-03-27 01:01:30 +08:00
parent 781a71a27c
commit afcd128256
30 changed files with 1696 additions and 44 deletions

View File

@@ -771,6 +771,32 @@ type (
CoordinateListResponse {
Records []CoordinateMeta `json:"records"`
}
RecoverImageRequest {
ID int64 `json:"id"`
Provider string `json:"provider"`
Bucket string `json:"bucket"`
}
ImageBedUploadResponse {
ID int64 `json:"id"`
}
ImageBedUploadListRequest {
Provider string `json:"provider"`
Bucket string `json:"bucket"`
}
ImageBedUploadMeta {
ID int64 `json:"id"`
FileName string `json:"file_name"`
FileSize int64 `json:"file_size"`
FileType string `json:"file_type"`
Path string `json:"path"`
Thumbnail string `json:"thumbnail"`
CreatedAt string `json:"created_at"`
Width int64 `json:"width"`
Height int64 `json:"height"`
}
ImageBedUploadListResponse {
Records []ImageBedUploadMeta `json:"records"`
}
)
// 文件上传
@@ -921,6 +947,18 @@ service auth {
// 获取图像经纬度列表
@handler getCoordinateList
post /coordinate/list returns (CoordinateListResponse)
// 恢复删除图片
@handler recoverImage
post /image/recover (RecoverImageRequest) returns (string)
// 图床上传图片
@handler imageBedUpload
post /image/bed/upload returns (ImageBedUploadResponse)
// 获取图床上传的图片列表
@handler getImageBedUploadList
post /image/bed/upload/list (ImageBedUploadListRequest) returns (ImageBedUploadListResponse)
}
type (
@@ -1073,18 +1111,115 @@ service auth {
type (
UserMeta {
ID int64 `json:"id"`
Username string `json:"username"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
Email string `json:"email"`
Phone string `json:"phone"`
Status int64 `json:"status"`
CreatedAt string `json:"created_at"`
ID int64 `json:"id"`
UID string `json:"uid"`
Username string `json:"username"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
Email string `json:"email"`
Phone string `json:"phone"`
Gender string `json:"gender"`
Introduce string `json:"introduce"`
Blog string `json:"blog"`
Location string `json:"location"`
Company string `json:"company"`
Status int64 `json:"status"`
CreatedAt string `json:"created_at"`
UpadatedAt string `json:"updated_at"`
DeletedAt string `json:"deleted_at"`
}
UserInfoListResponse {
Records []UserMeta `json:"records"`
}
RoleMeta {
ID int64 `json:"id"`
RoleName string `json:"role_name"`
RoleKey string `json:"role_key"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
DeletedAt string `json:"deleted_at"`
}
RoleListResponse {
Records []RoleMeta `json:"records"`
}
PermissionRuleMeta {
ID int64 `json:"id"`
Ptype string `json:"ptype"`
V0 string `json:"v0"`
V1 string `json:"v1"`
V2 string `json:"v2"`
V3 string `json:"v3"`
V4 string `json:"v4"`
V5 string `json:"v5"`
}
PermissionRuleListResponse {
Records []PermissionRuleMeta `json:"records"`
}
UserLoginLogMeta {
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
IP string `json:"ip"`
Location string `json:"location"`
Agent string `json:"agent"`
CreatedAt string `json:"created_at"`
Browser string `json:"browser"`
OperatingSystem string `json:"operating_system"`
BrowserVersion string `json:"browser_version"`
Mobile string `json:"mobile"`
Bot int64 `json:"bot"`
Mozilla string `json:"mozilla"`
Platform string `json:"platform"`
EngineName string `json:"engine_name"`
EngineVersion string `json:"engine_version"`
UpdatedAt string `json:"updated_at"`
DeletedAt string `json:"deleted_at"`
}
UserLoginLogListResponse {
Records []UserLoginLogMeta `json:"records"`
}
UserThirdPartyLoginMeta {
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
OpenID string `json:"open_id"`
Source string `json:"source"`
Status int64 `json:"status"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
DeletedAt string `json:"deleted_at"`
}
UserThirdPartyLoginListResponse {
Records []UserThirdPartyLoginMeta `json:"records"`
}
AllStorageListResponse {
Records []StorageConfigMeta `json:"records"`
}
CommentReplyMeta {
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
TopicID int64 `json:"topic_id"`
TopicType string `json:"topic_type"`
Content string `json:"content"`
CommentType string `json:"comment_type"`
ReplyTo int64 `json:"reply_to"`
ReplyID int64 `json:"reply_id"`
ReplyUser string `json:"reply_user"`
Author string `json:"author"`
Likes int64 `json:"likes"`
ReplyCount int64 `json:"reply_count"`
ImagePath string `json:"image_path"`
Browser string `json:"browser"`
OperatingSystem string `json:"operating_system"`
BrowserVersion string `json:"browser_version"`
CommentIP string `json:"comment_ip"`
Loaction string `json:"loaction"`
Agent string `json:"agent"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
DeletedAt string `json:"deleted_at"`
}
AllCommentListResponse {
Records []CommentReplyMeta `json:"records"`
}
)
// 系统服务
@@ -1103,5 +1238,29 @@ service auth {
// 获取用户列表
@handler getUserList
post /user/list returns (UserInfoListResponse)
// 获取所有角色列表
@handler getAllRoleList
post /role/list returns (RoleListResponse)
// 获取去权限规则表
@handler getPermissionRuleList
post /permission/rule/list returns (PermissionRuleListResponse)
// 获取用户登录日志列表
@handler getUserLoginLogList
post /user/login/log/list returns (UserLoginLogListResponse)
// 获取用户第三方登录列表
@handler getUserThirdPartyLoginList
post /user/third/party/login/list returns (UserThirdPartyLoginListResponse)
// 获取用户存储配置列表
@handler getAllStorageList
post /user/storage/config/list returns (AllStorageListResponse)
// 获取所有评论列表
@handler getAllCommentList
post /comment/list returns (AllCommentListResponse)
}

View File

@@ -381,6 +381,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/image/all/list",
Handler: storage.QueryAllImageListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/image/bed/upload",
Handler: storage.ImageBedUploadHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/image/bed/upload/list",
Handler: storage.GetImageBedUploadListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/image/delete",
@@ -411,6 +421,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/image/recent/list",
Handler: storage.QueryRecentImageListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/image/recover",
Handler: storage.RecoverImageHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/image/search",
@@ -468,11 +483,41 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.CasbinVerifyMiddleware, serverCtx.NonceMiddleware, serverCtx.AuthMiddleware},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/comment/list",
Handler: system.GetAllCommentListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/permission/rule/list",
Handler: system.GetPermissionRuleListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/role/list",
Handler: system.GetAllRoleListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/user/list",
Handler: system.GetUserListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/user/login/log/list",
Handler: system.GetUserLoginLogListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/user/storage/config/list",
Handler: system.GetAllStorageListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/user/third/party/login/list",
Handler: system.GetUserThirdPartyLoginListHandler(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 GetImageBedUploadListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ImageBedUploadListRequest
if err := httpx.Parse(r, &req); err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
return
}
l := storage.NewGetImageBedUploadListLogic(r.Context(), svcCtx)
resp, err := l.GetImageBedUploadList(&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 ImageBedUploadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := storage.NewImageBedUploadLogic(r.Context(), svcCtx)
resp, err := l.ImageBedUpload(r)
if err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
} else {
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
}
}
}

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 RecoverImageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.RecoverImageRequest
if err := httpx.Parse(r, &req); err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
return
}
l := storage.NewRecoverImageLogic(r.Context(), svcCtx)
resp, err := l.RecoverImage(&req)
if err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
} else {
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,134 @@
package storage
import (
"context"
"encoding/json"
"errors"
"github.com/redis/go-redis/v9"
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
"schisandra-album-cloud-microservices/common/constant"
"schisandra-album-cloud-microservices/common/encrypt"
"schisandra-album-cloud-microservices/common/storage/config"
"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 GetImageBedUploadListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetImageBedUploadListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetImageBedUploadListLogic {
return &GetImageBedUploadListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetImageBedUploadListLogic) GetImageBedUploadList(req *types.ImageBedUploadListRequest) (resp *types.ImageBedUploadListResponse, err error) {
uid, ok := l.ctx.Value("user_id").(string)
if !ok {
return nil, errors.New("user_id not found")
}
storageImgBed := l.svcCtx.DB.ScaStorageImgBed
imgBeds, err := storageImgBed.Where(
storageImgBed.UserID.Eq(uid),
storageImgBed.Provider.Eq(req.Provider),
storageImgBed.Bucket.Eq(req.Bucket)).Find()
if err != nil {
return nil, err
}
cacheKey := constant.UserOssConfigPrefix + uid + ":" + req.Provider
ossConfig, err := l.getOssConfigFromCacheOrDb(cacheKey, uid, req.Provider)
if err != nil {
return nil, errors.New("get oss config failed")
}
//service, err := l.svcCtx.StorageManager.GetStorage(uid, ossConfig)
//if err != nil {
// return nil, errors.New("get storage failed")
//}
var records []types.ImageBedUploadMeta
for _, imgBed := range imgBeds {
records = append(records, types.ImageBedUploadMeta{
ID: imgBed.ID,
FileName: imgBed.FileName,
FileSize: imgBed.FileSize,
FileType: imgBed.FileType,
Path: ossConfig.Endpoint + "/" + ossConfig.BucketName + "/" + imgBed.Path,
Thumbnail: ossConfig.Endpoint + "/" + ossConfig.BucketName + "/" + imgBed.ThumbPath,
CreatedAt: imgBed.CreatedAt.Format("2006-01-02 15:04:05"),
Width: int64(imgBed.Width),
Height: int64(imgBed.Height),
})
}
return &types.ImageBedUploadListResponse{
Records: records,
}, nil
}
// 提取解密操作为函数
func (l *GetImageBedUploadListLogic) decryptConfig(dbConfig *model.ScaStorageConfig) (*config.StorageConfig, error) {
accessKey, err := encrypt.Decrypt(dbConfig.AccessKey, l.svcCtx.Config.Encrypt.Key)
if err != nil {
return nil, errors.New("decrypt access key failed")
}
secretKey, err := encrypt.Decrypt(dbConfig.SecretKey, l.svcCtx.Config.Encrypt.Key)
if err != nil {
return nil, errors.New("decrypt secret key failed")
}
return &config.StorageConfig{
Provider: dbConfig.Provider,
Endpoint: dbConfig.Endpoint,
AccessKey: accessKey,
SecretKey: secretKey,
BucketName: dbConfig.Bucket,
Region: dbConfig.Region,
}, nil
}
// 从缓存或数据库中获取 OSS 配置
func (l *GetImageBedUploadListLogic) getOssConfigFromCacheOrDb(cacheKey, uid, provider string) (*config.StorageConfig, error) {
result, err := l.svcCtx.RedisClient.Get(l.ctx, cacheKey).Result()
if err != nil && !errors.Is(err, redis.Nil) {
return nil, errors.New("get oss config failed")
}
var ossConfig *config.StorageConfig
if result != "" {
var redisOssConfig model.ScaStorageConfig
if err = json.Unmarshal([]byte(result), &redisOssConfig); err != nil {
return nil, errors.New("unmarshal oss config failed")
}
return l.decryptConfig(&redisOssConfig)
}
// 缓存未命中,从数据库中加载
scaOssConfig := l.svcCtx.DB.ScaStorageConfig
dbOssConfig, err := scaOssConfig.Where(scaOssConfig.UserID.Eq(uid), scaOssConfig.Provider.Eq(provider)).First()
if err != nil {
return nil, err
}
// 缓存数据库配置
ossConfig, err = l.decryptConfig(dbOssConfig)
if err != nil {
return nil, err
}
marshalData, err := json.Marshal(dbOssConfig)
if err != nil {
return nil, errors.New("marshal oss config failed")
}
err = l.svcCtx.RedisClient.Set(l.ctx, cacheKey, marshalData, 0).Err()
if err != nil {
return nil, errors.New("set oss config failed")
}
return ossConfig, nil
}

View File

@@ -0,0 +1,177 @@
package storage
import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/ccpwcn/kgo"
"github.com/redis/go-redis/v9"
"net/http"
"path"
"path/filepath"
"schisandra-album-cloud-microservices/app/auth/model/mysql/model"
"schisandra-album-cloud-microservices/common/constant"
"schisandra-album-cloud-microservices/common/encrypt"
"schisandra-album-cloud-microservices/common/storage/config"
"strings"
"time"
"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 ImageBedUploadLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewImageBedUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ImageBedUploadLogic {
return &ImageBedUploadLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ImageBedUploadLogic) ImageBedUpload(r *http.Request) (resp *types.ImageBedUploadResponse, err error) {
uid, ok := l.ctx.Value("user_id").(string)
if !ok {
return nil, errors.New("user_id not found")
}
formValue := r.PostFormValue("data")
var result types.ImageBedMeta
if err := json.Unmarshal([]byte(formValue), &result); err != nil {
return nil, errors.New("invalid result")
}
file, header, err := r.FormFile("file")
if err != nil {
return nil, errors.New("file not found")
}
defer file.Close()
// 解析缩略图
thumbFile, _, err := r.FormFile("thumbnail")
if err != nil {
return nil, errors.New("thumbnail not found")
}
defer thumbFile.Close()
// 上传文件到OSS
cacheKey := constant.UserOssConfigPrefix + uid + ":" + result.Provider
ossConfig, err := l.getOssConfigFromCacheOrDb(cacheKey, uid, result.Provider)
if err != nil {
return nil, errors.New("get oss config failed")
}
service, err := l.svcCtx.StorageManager.GetStorage(uid, ossConfig)
if err != nil {
return nil, errors.New("get storage failed")
}
filePath := path.Join(
constant.ImageBedSpace,
constant.ImageSpace,
uid,
time.Now().Format("2006/01"), // 按年/月划分目录
fmt.Sprintf("%s_%s%s", strings.TrimSuffix(header.Filename, filepath.Ext(header.Filename)), kgo.SimpleUuid(), filepath.Ext(header.Filename)),
)
_, err = service.UploadFileSimple(l.ctx, ossConfig.BucketName, filePath, file, map[string]string{
"Content-Type": header.Header.Get("Content-Type")})
// 上传缩略图到OSS
if err != nil {
return nil, errors.New("upload file failed")
}
thumbFilePath := path.Join(
constant.ImageBedSpace,
constant.ThumbnailSpace,
uid,
time.Now().Format("2006/01"), // 按年/月划分目录
fmt.Sprintf("%s_%s%s", strings.TrimSuffix(header.Filename, filepath.Ext(header.Filename)), kgo.SimpleUuid(), filepath.Ext(header.Filename)),
)
_, err = service.UploadFileSimple(l.ctx, ossConfig.BucketName, thumbFilePath, thumbFile, map[string]string{
"Content-Type": header.Header.Get("Content-Type")})
if err != nil {
return nil, errors.New("upload file failed")
}
imgBed := model.ScaStorageImgBed{
UserID: uid,
Provider: result.Provider,
Bucket: ossConfig.BucketName,
Path: filePath,
ThumbPath: thumbFilePath,
FileSize: header.Size,
FileType: header.Header.Get("Content-Type"),
FileName: header.Filename,
Width: float64(result.Width),
Height: float64(result.Height),
}
err = l.svcCtx.DB.ScaStorageImgBed.Create(&imgBed)
if err != nil {
return nil, errors.New("create image bed failed")
}
return &types.ImageBedUploadResponse{ID: imgBed.ID}, nil
}
// 提取解密操作为函数
func (l *ImageBedUploadLogic) decryptConfig(dbConfig *model.ScaStorageConfig) (*config.StorageConfig, error) {
accessKey, err := encrypt.Decrypt(dbConfig.AccessKey, l.svcCtx.Config.Encrypt.Key)
if err != nil {
return nil, errors.New("decrypt access key failed")
}
secretKey, err := encrypt.Decrypt(dbConfig.SecretKey, l.svcCtx.Config.Encrypt.Key)
if err != nil {
return nil, errors.New("decrypt secret key failed")
}
return &config.StorageConfig{
Provider: dbConfig.Provider,
Endpoint: dbConfig.Endpoint,
AccessKey: accessKey,
SecretKey: secretKey,
BucketName: dbConfig.Bucket,
Region: dbConfig.Region,
}, nil
}
// 从缓存或数据库中获取 OSS 配置
func (l *ImageBedUploadLogic) getOssConfigFromCacheOrDb(cacheKey, uid, provider string) (*config.StorageConfig, error) {
result, err := l.svcCtx.RedisClient.Get(l.ctx, cacheKey).Result()
if err != nil && !errors.Is(err, redis.Nil) {
return nil, errors.New("get oss config failed")
}
var ossConfig *config.StorageConfig
if result != "" {
var redisOssConfig model.ScaStorageConfig
if err = json.Unmarshal([]byte(result), &redisOssConfig); err != nil {
return nil, errors.New("unmarshal oss config failed")
}
return l.decryptConfig(&redisOssConfig)
}
// 缓存未命中,从数据库中加载
scaOssConfig := l.svcCtx.DB.ScaStorageConfig
dbOssConfig, err := scaOssConfig.Where(scaOssConfig.UserID.Eq(uid), scaOssConfig.Provider.Eq(provider)).First()
if err != nil {
return nil, err
}
// 缓存数据库配置
ossConfig, err = l.decryptConfig(dbOssConfig)
if err != nil {
return nil, err
}
marshalData, err := json.Marshal(dbOssConfig)
if err != nil {
return nil, errors.New("marshal oss config failed")
}
err = l.svcCtx.RedisClient.Set(l.ctx, cacheKey, marshalData, 0).Err()
if err != nil {
return nil, errors.New("set oss config failed")
}
return ossConfig, nil
}

View File

@@ -0,0 +1,48 @@
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 RecoverImageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewRecoverImageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RecoverImageLogic {
return &RecoverImageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *RecoverImageLogic) RecoverImage(req *types.RecoverImageRequest) (resp string, err error) {
uid, ok := l.ctx.Value("user_id").(string)
if !ok {
return "", errors.New("user_id not found")
}
storageInfo := l.svcCtx.DB.ScaStorageInfo
info, err := storageInfo.Where(
storageInfo.UserID.Eq(uid),
storageInfo.ID.Eq(req.ID),
storageInfo.Provider.Eq(req.Provider),
storageInfo.Bucket.Eq(req.Bucket),
).Update(storageInfo.DeletedAt, nil)
if err != nil {
return "", err
}
if info.RowsAffected == 0 {
return "", errors.New("image not found")
}
return "success", nil
}

View File

@@ -0,0 +1,36 @@
package system
import (
"context"
"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 GetAllCommentListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetAllCommentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAllCommentListLogic {
return &GetAllCommentListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetAllCommentListLogic) GetAllCommentList() (resp *types.AllCommentListResponse, err error) {
commentReply := l.svcCtx.DB.ScaCommentReply
var records []types.CommentReplyMeta
err = commentReply.Scan(&records)
if err != nil {
return nil, err
}
return &types.AllCommentListResponse{
Records: records,
}, nil
}

View File

@@ -0,0 +1,33 @@
package system
import (
"context"
"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 GetAllRoleListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetAllRoleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAllRoleListLogic {
return &GetAllRoleListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetAllRoleListLogic) GetAllRoleList() (resp *types.RoleListResponse, err error) {
authRole := l.svcCtx.DB.ScaAuthRole
var roles []types.RoleMeta
err = authRole.Scan(&roles)
if err != nil {
return nil, err
}
return &types.RoleListResponse{Records: roles}, nil
}

View File

@@ -0,0 +1,30 @@
package system
import (
"context"
"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 GetAllStorageListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetAllStorageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAllStorageListLogic {
return &GetAllStorageListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetAllStorageListLogic) GetAllStorageList() (resp *types.AllStorageListResponse, err error) {
// todo: add your logic here and delete this line
return
}

View File

@@ -0,0 +1,36 @@
package system
import (
"context"
"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 GetPermissionRuleListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetPermissionRuleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPermissionRuleListLogic {
return &GetPermissionRuleListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetPermissionRuleListLogic) GetPermissionRuleList() (resp *types.PermissionRuleListResponse, err error) {
permissionRule := l.svcCtx.DB.ScaAuthPermissionRule
var permissionRuleList []types.PermissionRuleMeta
err = permissionRule.Scan(&permissionRuleList)
if err != nil {
return nil, err
}
return &types.PermissionRuleListResponse{Records: permissionRuleList}, nil
}

View File

@@ -2,7 +2,6 @@ package system
import (
"context"
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
@@ -24,7 +23,28 @@ func NewGetUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUs
}
func (l *GetUserListLogic) GetUserList() (resp *types.UserInfoListResponse, err error) {
// todo: add your logic here and delete this line
return
authUser := l.svcCtx.DB.ScaAuthUser
var userMetaList []types.UserMeta
err = authUser.Select(
authUser.ID,
authUser.UID,
authUser.Username,
authUser.Nickname,
authUser.Email,
authUser.Phone,
authUser.Gender,
authUser.Avatar,
authUser.Location,
authUser.Company,
authUser.Blog,
authUser.Introduce,
authUser.Status,
authUser.CreatedAt,
authUser.UpdatedAt,
authUser.DeletedAt,
).Scan(&userMetaList)
if err != nil {
return nil, err
}
return &types.UserInfoListResponse{Records: userMetaList}, nil
}

View File

@@ -0,0 +1,35 @@
package system
import (
"context"
"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 GetUserLoginLogListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetUserLoginLogListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserLoginLogListLogic {
return &GetUserLoginLogListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetUserLoginLogListLogic) GetUserLoginLogList() (resp *types.UserLoginLogListResponse, err error) {
userDevice := l.svcCtx.DB.ScaAuthUserDevice
var userLoginLogs []types.UserLoginLogMeta
err = userDevice.Scan(&userLoginLogs)
if err != nil {
return nil, err
}
return &types.UserLoginLogListResponse{Records: userLoginLogs}, nil
}

View File

@@ -0,0 +1,34 @@
package system
import (
"context"
"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 GetUserThirdPartyLoginListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetUserThirdPartyLoginListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserThirdPartyLoginListLogic {
return &GetUserThirdPartyLoginListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetUserThirdPartyLoginListLogic) GetUserThirdPartyLoginList() (resp *types.UserThirdPartyLoginListResponse, err error) {
userSocial := l.svcCtx.DB.ScaAuthUserSocial
var userSocialList []types.UserThirdPartyLoginMeta
err = userSocial.Scan(&userSocialList)
if err != nil {
}
return &types.UserThirdPartyLoginListResponse{Records: userSocialList}, nil
}

View File

@@ -116,3 +116,10 @@ type ZincFileInfo struct {
Province string `json:"province"`
City string `json:"city"`
}
type ImageBedMeta struct {
Provider string `json:"provider"`
Bucket string `json:"bucket"`
Width int64 `json:"width"`
Height int64 `json:"height"`
}

View File

@@ -75,6 +75,10 @@ type AlbumRenameResponse struct {
Name string `json:"name"`
}
type AllCommentListResponse struct {
Records []CommentReplyMeta `json:"records"`
}
type AllImageDetail struct {
Date string `json:"date"`
List []ImageMeta `json:"list"`
@@ -91,6 +95,10 @@ type AllImageListResponse struct {
Records []AllImageDetail `json:"records"`
}
type AllStorageListResponse struct {
Records []StorageConfigMeta `json:"records"`
}
type BucketCapacityRequest struct {
Provider string `json:"provider"`
Bucket string `json:"bucket"`
@@ -149,6 +157,31 @@ type CommentListRequest struct {
IsHot bool `json:"is_hot,default=true,optional"`
}
type CommentReplyMeta struct {
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
TopicID int64 `json:"topic_id"`
TopicType string `json:"topic_type"`
Content string `json:"content"`
CommentType string `json:"comment_type"`
ReplyTo int64 `json:"reply_to"`
ReplyID int64 `json:"reply_id"`
ReplyUser string `json:"reply_user"`
Author string `json:"author"`
Likes int64 `json:"likes"`
ReplyCount int64 `json:"reply_count"`
ImagePath string `json:"image_path"`
Browser string `json:"browser"`
OperatingSystem string `json:"operating_system"`
BrowserVersion string `json:"browser_version"`
CommentIP string `json:"comment_ip"`
Loaction string `json:"loaction"`
Agent string `json:"agent"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
DeletedAt string `json:"deleted_at"`
}
type CommentRequest struct {
Content string `json:"content"`
Images string `json:"images,optional"`
@@ -248,6 +281,31 @@ type HeatmapMeta struct {
Count int64 `json:"count"`
}
type ImageBedUploadListRequest struct {
Provider string `json:"provider"`
Bucket string `json:"bucket"`
}
type ImageBedUploadListResponse struct {
Records []ImageBedUploadMeta `json:"records"`
}
type ImageBedUploadMeta struct {
ID int64 `json:"id"`
FileName string `json:"file_name"`
FileSize int64 `json:"file_size"`
FileType string `json:"file_type"`
Path string `json:"path"`
Thumbnail string `json:"thumbnail"`
CreatedAt string `json:"created_at"`
Width int64 `json:"width"`
Height int64 `json:"height"`
}
type ImageBedUploadResponse struct {
ID int64 `json:"id"`
}
type ImageMeta struct {
ID int64 `json:"id"`
FileName string `json:"file_name"`
@@ -325,6 +383,21 @@ type OAuthWechatRequest struct {
ClientId string `json:"client_id"`
}
type PermissionRuleListResponse struct {
Records []PermissionRuleMeta `json:"records"`
}
type PermissionRuleMeta struct {
ID int64 `json:"id"`
Ptype string `json:"ptype"`
V0 string `json:"v0"`
V1 string `json:"v1"`
V2 string `json:"v2"`
V3 string `json:"v3"`
V4 string `json:"v4"`
V5 string `json:"v5"`
}
type PhoneLoginRequest struct {
Phone string `json:"phone"`
Captcha string `json:"captcha"`
@@ -367,6 +440,12 @@ type RecentListResponse struct {
Records []AllImageDetail `json:"records"`
}
type RecoverImageRequest struct {
ID int64 `json:"id"`
Provider string `json:"provider"`
Bucket string `json:"bucket"`
}
type RefreshTokenResponse struct {
AccessToken string `json:"access_token"`
ExpireAt int64 `json:"expire_at"`
@@ -409,6 +488,19 @@ type ResetPasswordRequest struct {
Repassword string `json:"repassword"`
}
type RoleListResponse struct {
Records []RoleMeta `json:"records"`
}
type RoleMeta struct {
ID int64 `json:"id"`
RoleName string `json:"role_name"`
RoleKey string `json:"role_key"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
DeletedAt string `json:"deleted_at"`
}
type RotateCaptchaResponse struct {
Key string `json:"key"`
Image string `json:"image"`
@@ -638,15 +730,47 @@ type UserInfoListResponse struct {
Records []UserMeta `json:"records"`
}
type UserLoginLogListResponse struct {
Records []UserLoginLogMeta `json:"records"`
}
type UserLoginLogMeta struct {
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
IP string `json:"ip"`
Location string `json:"location"`
Agent string `json:"agent"`
CreatedAt string `json:"created_at"`
Browser string `json:"browser"`
OperatingSystem string `json:"operating_system"`
BrowserVersion string `json:"browser_version"`
Mobile string `json:"mobile"`
Bot int64 `json:"bot"`
Mozilla string `json:"mozilla"`
Platform string `json:"platform"`
EngineName string `json:"engine_name"`
EngineVersion string `json:"engine_version"`
UpdatedAt string `json:"updated_at"`
DeletedAt string `json:"deleted_at"`
}
type UserMeta struct {
ID int64 `json:"id"`
Username string `json:"username"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
Email string `json:"email"`
Phone string `json:"phone"`
Status int64 `json:"status"`
CreatedAt string `json:"created_at"`
ID int64 `json:"id"`
UID string `json:"uid"`
Username string `json:"username"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
Email string `json:"email"`
Phone string `json:"phone"`
Gender string `json:"gender"`
Introduce string `json:"introduce"`
Blog string `json:"blog"`
Location string `json:"location"`
Company string `json:"company"`
Status int64 `json:"status"`
CreatedAt string `json:"created_at"`
UpadatedAt string `json:"updated_at"`
DeletedAt string `json:"deleted_at"`
}
type UserSecuritySettingResponse struct {
@@ -659,6 +783,21 @@ type UserSecuritySettingResponse struct {
SetPassword bool `json:"set_password,default=false"`
}
type UserThirdPartyLoginListResponse struct {
Records []UserThirdPartyLoginMeta `json:"records"`
}
type UserThirdPartyLoginMeta struct {
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
OpenID string `json:"open_id"`
Source string `json:"source"`
Status int64 `json:"status"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
DeletedAt string `json:"deleted_at"`
}
type UserUploadInfoResponse struct {
ImageCount int64 `json:"image_count"`
TodayUploadCount int64 `json:"today_upload_count"`
@@ -673,8 +812,3 @@ type WechatOffiaccountLoginRequest struct {
Openid string `json:"openid"`
ClientId string `json:"client_id"`
}
type ImageStreamResponse struct {
ContentType string `json:"content_type"`
Size int64 `json:"size"`
}