Feat: support chunk size option in policy
This commit is contained in:
parent
de9c41082c
commit
8443a30fb1
5 changed files with 25 additions and 12 deletions
|
@ -58,6 +58,8 @@ type PolicyOption struct {
|
||||||
Region string `json:"region,omitempty"`
|
Region string `json:"region,omitempty"`
|
||||||
// ServerSideEndpoint 服务端请求使用的 Endpoint,为空时使用 Policy.Server 字段
|
// ServerSideEndpoint 服务端请求使用的 Endpoint,为空时使用 Policy.Server 字段
|
||||||
ServerSideEndpoint string `json:"server_side_endpoint,omitempty"`
|
ServerSideEndpoint string `json:"server_side_endpoint,omitempty"`
|
||||||
|
// 分片上传的分片大小
|
||||||
|
ChunkSize uint64 `json:"chunk_size,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var thumbSuffix = map[string][]string{
|
var thumbSuffix = map[string][]string{
|
||||||
|
|
|
@ -184,6 +184,7 @@ func (fs *FileSystem) CreateUploadSession(ctx context.Context, path string, size
|
||||||
Name: name,
|
Name: name,
|
||||||
Size: size,
|
Size: size,
|
||||||
SavePath: savePath,
|
SavePath: savePath,
|
||||||
|
ChunkSize: fs.Policy.OptionsSerialized.ChunkSize,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取上传凭证
|
// 获取上传凭证
|
||||||
|
|
|
@ -46,11 +46,12 @@ type Object struct {
|
||||||
|
|
||||||
// PolicySummary 用于前端组件使用的存储策略概况
|
// PolicySummary 用于前端组件使用的存储策略概况
|
||||||
type PolicySummary struct {
|
type PolicySummary struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
MaxSize uint64 `json:"max_size"`
|
MaxSize uint64 `json:"max_size"`
|
||||||
FileType []string `json:"file_type"`
|
FileType []string `json:"file_type"`
|
||||||
|
ChunkSize uint64 `json:"chunk_size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildObjectList 构建列目录响应
|
// BuildObjectList 构建列目录响应
|
||||||
|
@ -65,11 +66,12 @@ func BuildObjectList(parent uint, objects []Object, policy *model.Policy) Object
|
||||||
|
|
||||||
if policy != nil {
|
if policy != nil {
|
||||||
res.Policy = &PolicySummary{
|
res.Policy = &PolicySummary{
|
||||||
ID: hashid.HashID(policy.ID, hashid.PolicyID),
|
ID: hashid.HashID(policy.ID, hashid.PolicyID),
|
||||||
Name: policy.Name,
|
Name: policy.Name,
|
||||||
Type: policy.Type,
|
Type: policy.Type,
|
||||||
MaxSize: policy.MaxSize,
|
MaxSize: policy.MaxSize,
|
||||||
FileType: policy.OptionsSerialized.FileType,
|
FileType: policy.OptionsSerialized.FileType,
|
||||||
|
ChunkSize: policy.OptionsSerialized.ChunkSize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ type UploadSession struct {
|
||||||
Name string
|
Name string
|
||||||
Size uint64
|
Size uint64
|
||||||
SavePath string
|
SavePath string
|
||||||
|
ChunkSize uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// UploadCallback 上传回调正文
|
// UploadCallback 上传回调正文
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem"
|
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem"
|
||||||
|
"github.com/cloudreve/Cloudreve/v3/pkg/hashid"
|
||||||
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
|
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
@ -13,7 +14,7 @@ type UploadSessionService struct {
|
||||||
Path string `json:"path" binding:"required"`
|
Path string `json:"path" binding:"required"`
|
||||||
Size uint64 `json:"size" binding:"min=0"`
|
Size uint64 `json:"size" binding:"min=0"`
|
||||||
Name string `json:"name" binding:"required"`
|
Name string `json:"name" binding:"required"`
|
||||||
PolicyID uint `json:"policy_id" binding:"required"`
|
PolicyID string `json:"policy_id" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create 创建新的上传会话
|
// Create 创建新的上传会话
|
||||||
|
@ -24,7 +25,13 @@ func (service *UploadSessionService) Create(ctx context.Context, c *gin.Context)
|
||||||
return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err)
|
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)
|
return serializer.Err(serializer.CodePolicyNotAllowed, "存储策略发生变化,请刷新文件列表并重新添加此任务", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue