chore: initial commit before Kratos migration
This commit is contained in:
parent
3a18ca0579
commit
654b7d9bb6
2906
docs/superpowers/plans/2026-05-25-kratos-watermill-migration.md
Normal file
2906
docs/superpowers/plans/2026-05-25-kratos-watermill-migration.md
Normal file
File diff suppressed because it is too large
Load Diff
@ -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)
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user