chore: initial commit before Kratos migration

This commit is contained in:
向宁 2026-05-25 12:29:31 +08:00
parent 3a18ca0579
commit 654b7d9bb6
4 changed files with 2930 additions and 14 deletions

File diff suppressed because it is too large Load Diff

View File

@ -123,11 +123,13 @@ func (e *FolderEndpoint) UploadToFolder(c *gin.Context) {
s3Bucket := c.DefaultPostForm("bucket", "default")
cmd := handlers.UploadToFolderCommand{
FolderID: folderID,
FileName: header.Filename,
Data: file,
S3Bucket: s3Bucket,
OwnerID: ownerID,
FolderID: folderID,
FileName: header.Filename,
Data: file,
S3Bucket: s3Bucket,
OwnerID: ownerID,
Size: header.Size,
ContentType: header.Header.Get("Content-Type"),
}
result, err := mediator.Send[handlers.UploadToFolderCommand, *model.FileMeta](e.Mediator, c.Request.Context(), cmd)

View File

@ -14,11 +14,13 @@ import (
)
type UploadToFolderCommand struct {
FolderID string
FileName string
Data io.Reader
S3Bucket string
OwnerID string
FolderID string
FileName string
Data io.Reader
S3Bucket string
OwnerID string
Size int64
ContentType string
}
type MoveFileCommand struct {
@ -60,6 +62,11 @@ func (h *UploadToFolderHandler) Handle(ctx context.Context, cmd UploadToFolderCo
return nil, fmt.Errorf("S3 upload failed: %w", err)
}
contentType := cmd.ContentType
if contentType == "" {
contentType = "application/octet-stream"
}
now := time.Now()
fileMeta := &model.FileMeta{
ID: uuid.New().String(),
@ -67,7 +74,8 @@ func (h *UploadToFolderHandler) Handle(ctx context.Context, cmd UploadToFolderCo
Name: cmd.FileName,
S3Key: s3Key,
S3Bucket: cmd.S3Bucket,
ContentType: "application/octet-stream",
Size: cmd.Size,
ContentType: contentType,
OwnerID: cmd.OwnerID,
CreatedAt: now,
UpdatedAt: now,

View File

@ -7,14 +7,13 @@ import (
)
const API_KEY_HEADER = "X-API-Key"
const APIKeyUserID = "api-key-user"
// AuthMiddleware 验证API密钥的中间件
func AuthMiddleware(apiKey string) gin.HandlerFunc {
return func(c *gin.Context) {
// 从请求头中获取API密钥
key := c.GetHeader(API_KEY_HEADER)
// 验证密钥是否正确
if key != apiKey {
c.JSON(http.StatusUnauthorized, gin.H{
"code": http.StatusUnauthorized,
@ -25,7 +24,8 @@ func AuthMiddleware(apiKey string) gin.HandlerFunc {
return
}
// 密钥验证通过,继续处理请求
c.Set(ContextKeyUserID, APIKeyUserID)
c.Set(ContextKeyUsername, "api-key-user")
c.Next()
}
}