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,本地策略直接返回空值
|
// Token 获取上传策略和认证Token,本地策略直接返回空值
|
||||||
func (handler Driver) Token(ctx context.Context, ttl int64, uploadSession *serializer.UploadSession, file fsctx.FileHeader) (*serializer.UploadCredential, error) {
|
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{
|
return &serializer.UploadCredential{
|
||||||
SessionID: uploadSession.Key,
|
SessionID: uploadSession.Key,
|
||||||
ChunkSize: handler.Policy.OptionsSerialized.ChunkSize,
|
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", HookClearFileHeaderSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.Use("AfterUpload", GenericAfterUpload)
|
// 验证文件规格
|
||||||
if err := fs.Upload(ctx, file); err != nil {
|
if err := fs.Upload(ctx, file); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -201,6 +201,12 @@ func (fs *FileSystem) CreateUploadSession(ctx context.Context, file *fsctx.FileS
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建占位符
|
||||||
|
fs.Use("AfterUpload", GenericAfterUpload)
|
||||||
|
if err := fs.Upload(ctx, file); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// 创建回调会话
|
// 创建回调会话
|
||||||
err = cache.Set(
|
err = cache.Set(
|
||||||
UploadSessionCachePrefix+callbackKey,
|
UploadSessionCachePrefix+callbackKey,
|
||||||
|
|
|
@ -54,6 +54,8 @@ const (
|
||||||
CodeNoPermissionErr = 403
|
CodeNoPermissionErr = 403
|
||||||
// CodeNotFound 资源未找到
|
// CodeNotFound 资源未找到
|
||||||
CodeNotFound = 404
|
CodeNotFound = 404
|
||||||
|
// CodeConflict 资源冲突
|
||||||
|
CodeConflict = 409
|
||||||
// CodeUploadFailed 上传出错
|
// CodeUploadFailed 上传出错
|
||||||
CodeUploadFailed = 40002
|
CodeUploadFailed = 40002
|
||||||
// CodeCredentialInvalid 凭证无效
|
// CodeCredentialInvalid 凭证无效
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
|
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
|
||||||
"github.com/cloudreve/Cloudreve/v3/pkg/task"
|
"github.com/cloudreve/Cloudreve/v3/pkg/task"
|
||||||
"github.com/cloudreve/Cloudreve/v3/pkg/task/slavetask"
|
"github.com/cloudreve/Cloudreve/v3/pkg/task/slavetask"
|
||||||
|
"github.com/cloudreve/Cloudreve/v3/pkg/util"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -172,6 +173,10 @@ type SlaveCreateUploadSessionService struct {
|
||||||
|
|
||||||
// Create 从机创建上传会话
|
// Create 从机创建上传会话
|
||||||
func (service *SlaveCreateUploadSessionService) Create(ctx context.Context, c *gin.Context) serializer.Response {
|
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(
|
err := cache.Set(
|
||||||
filesystem.UploadSessionCachePrefix+service.Session.Key,
|
filesystem.UploadSessionCachePrefix+service.Session.Key,
|
||||||
service.Session,
|
service.Session,
|
||||||
|
|
Loading…
Add table
Reference in a new issue