feat: 更新用户上下文处理,服务方法显式接受用户参数,简化上下文调用

This commit is contained in:
2025-12-30 23:01:35 +08:00
parent 54de243fa1
commit e6a8e3f321
7 changed files with 211 additions and 156 deletions

View File

@@ -5,10 +5,9 @@ import (
"quyun/v2/app/http/v1/dto"
"quyun/v2/app/services"
"quyun/v2/pkg/consts"
"quyun/v2/database/models"
"github.com/gofiber/fiber/v3"
"github.com/spf13/cast"
)
// @provider
@@ -25,13 +24,18 @@ type Common struct{}
// @Param file formData file true "File"
// @Param type formData string false "Type enum(image, video, audio)"
// @Success 200 {object} dto.UploadResult
// @Bind user local key(__ctx_user)
// @Bind file file
// @Bind typeArg body key(type)
func (c *Common) Upload(ctx fiber.Ctx, file *multipart.FileHeader, typeArg *string) (*dto.UploadResult, error) {
func (c *Common) Upload(
ctx fiber.Ctx,
user *models.User,
file *multipart.FileHeader,
typeArg *string,
) (*dto.UploadResult, error) {
val := ""
if typeArg != nil {
val = *typeArg
}
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
return services.Common.Upload(ctx.Context(), uid, file, val)
return services.Common.Upload(ctx.Context(), user.ID, file, val)
}