Fix: while placeholder file got conflict, original file might be deleted
This commit is contained in:
parent
0650684dd9
commit
9136f3caec
4 changed files with 18 additions and 1 deletions
|
@ -267,6 +267,10 @@ func (handler Driver) Source(
|
|||
|
||||
// Token 获取上传策略和认证Token,本地策略直接返回空值
|
||||
func (handler Driver) Token(ctx context.Context, ttl int64, uploadSession *serializer.UploadSession, file fsctx.FileHeader) (*serializer.UploadCredential, error) {
|
||||
if util.Exists(uploadSession.SavePath) {
|
||||
return nil, errors.New("placeholder file already exist")
|
||||
}
|
||||
|
||||
return &serializer.UploadCredential{
|
||||
SessionID: uploadSession.Key,
|
||||
ChunkSize: handler.Policy.OptionsSerialized.ChunkSize,
|
||||
|
|
|
@ -178,7 +178,7 @@ func (fs *FileSystem) CreateUploadSession(ctx context.Context, file *fsctx.FileS
|
|||
fs.Use("AfterUpload", HookClearFileHeaderSize)
|
||||
}
|
||||
|
||||
fs.Use("AfterUpload", GenericAfterUpload)
|
||||
// 验证文件规格
|
||||
if err := fs.Upload(ctx, file); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -201,6 +201,12 @@ func (fs *FileSystem) CreateUploadSession(ctx context.Context, file *fsctx.FileS
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// 创建占位符
|
||||
fs.Use("AfterUpload", GenericAfterUpload)
|
||||
if err := fs.Upload(ctx, file); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 创建回调会话
|
||||
err = cache.Set(
|
||||
UploadSessionCachePrefix+callbackKey,
|
||||
|
|
|
@ -54,6 +54,8 @@ const (
|
|||
CodeNoPermissionErr = 403
|
||||
// CodeNotFound 资源未找到
|
||||
CodeNotFound = 404
|
||||
// CodeConflict 资源冲突
|
||||
CodeConflict = 409
|
||||
// CodeUploadFailed 上传出错
|
||||
CodeUploadFailed = 40002
|
||||
// CodeCredentialInvalid 凭证无效
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/task"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/task/slavetask"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/util"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jinzhu/gorm"
|
||||
"net/http"
|
||||
|
@ -172,6 +173,10 @@ type SlaveCreateUploadSessionService struct {
|
|||
|
||||
// Create 从机创建上传会话
|
||||
func (service *SlaveCreateUploadSessionService) Create(ctx context.Context, c *gin.Context) serializer.Response {
|
||||
if util.Exists(service.Session.SavePath) {
|
||||
return serializer.Err(serializer.CodeConflict, "placeholder file already exist", nil)
|
||||
}
|
||||
|
||||
err := cache.Set(
|
||||
filesystem.UploadSessionCachePrefix+service.Session.Key,
|
||||
service.Session,
|
||||
|
|
Loading…
Add table
Reference in a new issue