diff --git a/pkg/filesystem/driver/upyun/handller.go b/pkg/filesystem/driver/upyun/handller.go index 08fa585..c4696b2 100644 --- a/pkg/filesystem/driver/upyun/handller.go +++ b/pkg/filesystem/driver/upyun/handller.go @@ -31,7 +31,7 @@ type UploadPolicy struct { Expiration int64 `json:"expiration"` CallbackURL string `json:"notify-url"` ContentLength uint64 `json:"content-length"` - ContentLengthRange string `json:"content-length-range"` + ContentLengthRange string `json:"content-length-range,omitempty"` AllowFileType string `json:"allow-file-type,omitempty"` } @@ -262,6 +262,8 @@ func (handler Driver) Token(ctx context.Context, TTL int64, key string) (seriali return serializer.UploadCredential{}, errors.New("无法获取文件大小") } + // 检查文件大小 + // 生成回调地址 siteURL := model.GetSiteURL() apiBaseURI, _ := url.Parse("/api/v3/callback/upyun/" + key) diff --git a/pkg/filesystem/upload.go b/pkg/filesystem/upload.go index aefbede..49e6108 100644 --- a/pkg/filesystem/upload.go +++ b/pkg/filesystem/upload.go @@ -151,6 +151,13 @@ func (fs *FileSystem) GetUploadToken(ctx context.Context, path string, size uint var err error + // 检查文件大小 + if fs.User.Policy.MaxSize != 0 { + if size > fs.User.Policy.MaxSize { + return nil, ErrFileSizeTooBig + } + } + // 是否需要预先生成存储路径 var savePath string if fs.User.Policy.IsPathGenerateNeeded() { diff --git a/service/explorer/upload.go b/service/explorer/upload.go index db6fecf..8b219ef 100644 --- a/service/explorer/upload.go +++ b/service/explorer/upload.go @@ -13,6 +13,7 @@ type UploadCredentialService struct { Path string `form:"path" binding:"required"` Size uint64 `form:"size" binding:"min=0"` Name string `form:"name"` + Type string `form:"type"` } // Get 获取新的上传凭证 @@ -23,6 +24,13 @@ func (service *UploadCredentialService) Get(ctx context.Context, c *gin.Context) return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err) } + // 存储策略是否一致 + if service.Type != "" { + if service.Type != fs.User.Policy.Type { + return serializer.Err(serializer.CodePolicyNotAllowed, "存储策略已变更,请刷新页面", nil) + } + } + ctx = context.WithValue(ctx, fsctx.GinCtx, c) credential, err := fs.GetUploadToken(ctx, service.Path, service.Size, service.Name) if err != nil {