mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: file uploading token sign for remote policy
This commit is contained in:
35
service/explorer/upload.go
Normal file
35
service/explorer/upload.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package explorer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/HFO4/cloudreve/pkg/filesystem"
|
||||
"github.com/HFO4/cloudreve/pkg/filesystem/fsctx"
|
||||
"github.com/HFO4/cloudreve/pkg/serializer"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// UploadCredentialService 获取上传凭证服务
|
||||
type UploadCredentialService struct {
|
||||
Path string `form:"path" binding:"required"`
|
||||
Size uint64 `form:"size" binding:"required,min=0"`
|
||||
}
|
||||
|
||||
// Get 获取新的上传凭证
|
||||
func (service *UploadCredentialService) Get(ctx context.Context, c *gin.Context) serializer.Response {
|
||||
// 创建文件系统
|
||||
fs, err := filesystem.NewFileSystemFromContext(c)
|
||||
if err != nil {
|
||||
return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err)
|
||||
}
|
||||
|
||||
ctx = context.WithValue(ctx, fsctx.GinCtx, c)
|
||||
credential, err := fs.GetUploadToken(ctx, service.Path, service.Size)
|
||||
if err != nil {
|
||||
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
||||
}
|
||||
|
||||
return serializer.Response{
|
||||
Code: 0,
|
||||
Data: credential,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user