Feat: support chunk size option in policy

pull/1146/head
HFO4 3 years ago
parent de9c41082c
commit 8443a30fb1

@ -58,6 +58,8 @@ type PolicyOption struct {
Region string `json:"region,omitempty"`
// ServerSideEndpoint 服务端请求使用的 Endpoint为空时使用 Policy.Server 字段
ServerSideEndpoint string `json:"server_side_endpoint,omitempty"`
// 分片上传的分片大小
ChunkSize uint64 `json:"chunk_size,omitempty"`
}
var thumbSuffix = map[string][]string{

@ -184,6 +184,7 @@ func (fs *FileSystem) CreateUploadSession(ctx context.Context, path string, size
Name: name,
Size: size,
SavePath: savePath,
ChunkSize: fs.Policy.OptionsSerialized.ChunkSize,
}
// 获取上传凭证

@ -51,6 +51,7 @@ type PolicySummary struct {
Type string `json:"type"`
MaxSize uint64 `json:"max_size"`
FileType []string `json:"file_type"`
ChunkSize uint64 `json:"chunk_size"`
}
// BuildObjectList 构建列目录响应
@ -70,6 +71,7 @@ func BuildObjectList(parent uint, objects []Object, policy *model.Policy) Object
Type: policy.Type,
MaxSize: policy.MaxSize,
FileType: policy.OptionsSerialized.FileType,
ChunkSize: policy.OptionsSerialized.ChunkSize,
}
}

@ -38,6 +38,7 @@ type UploadSession struct {
Name string
Size uint64
SavePath string
ChunkSize uint64
}
// UploadCallback 上传回调正文

@ -4,6 +4,7 @@ import (
"context"
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem"
"github.com/cloudreve/Cloudreve/v3/pkg/hashid"
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
"github.com/gin-gonic/gin"
)
@ -13,7 +14,7 @@ type UploadSessionService struct {
Path string `json:"path" binding:"required"`
Size uint64 `json:"size" binding:"min=0"`
Name string `json:"name" binding:"required"`
PolicyID uint `json:"policy_id" binding:"required"`
PolicyID string `json:"policy_id" binding:"required"`
}
// Create 创建新的上传会话
@ -24,7 +25,13 @@ func (service *UploadSessionService) Create(ctx context.Context, c *gin.Context)
return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err)
}
if fs.Policy.ID != service.PolicyID {
// 取得存储策略的ID
rawID, err := hashid.DecodeHashID(service.PolicyID, hashid.PolicyID)
if err != nil {
return serializer.Err(serializer.CodeNotFound, "存储策略不存在", err)
}
if fs.Policy.ID != rawID {
return serializer.Err(serializer.CodePolicyNotAllowed, "存储策略发生变化,请刷新文件列表并重新添加此任务", nil)
}

Loading…
Cancel
Save