Feat: check policy update before upload

This commit is contained in:
HFO4
2020-02-27 17:12:59 +08:00
parent 2f1f619f2f
commit e8c4660c38
3 changed files with 18 additions and 1 deletions

View File

@@ -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 {