mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Refactor: use universal FileHeader when handling file upload, remove usage of global ctx with FileHeader, SavePath, DisableOverwrite
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/conf"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/driver/local"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem/fsctx"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
|
||||
"github.com/cloudreve/Cloudreve/v3/service/explorer"
|
||||
@@ -307,12 +306,13 @@ func FileUploadStream(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
fileData := local.FileStream{
|
||||
fileData := fsctx.FileStream{
|
||||
MIMEType: c.Request.Header.Get("Content-Type"),
|
||||
File: c.Request.Body,
|
||||
Size: fileSize,
|
||||
Name: fileName,
|
||||
VirtualPath: filePath,
|
||||
Mode: fsctx.Create,
|
||||
}
|
||||
|
||||
// 创建文件系统
|
||||
@@ -341,9 +341,8 @@ func FileUploadStream(c *gin.Context) {
|
||||
|
||||
// 执行上传
|
||||
ctx = context.WithValue(ctx, fsctx.ValidateCapacityOnceCtx, &sync.Once{})
|
||||
ctx = context.WithValue(ctx, fsctx.DisableOverwrite, true)
|
||||
uploadCtx := context.WithValue(ctx, fsctx.GinCtx, c)
|
||||
err = fs.Upload(uploadCtx, fileData)
|
||||
err = fs.Upload(uploadCtx, &fileData)
|
||||
if err != nil {
|
||||
c.JSON(200, serializer.Err(serializer.CodeUploadFailed, err.Error(), err))
|
||||
return
|
||||
|
||||
@@ -60,7 +60,7 @@ func SlaveUpload(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
fileData := local.FileStream{
|
||||
fileData := fsctx.FileStream{
|
||||
MIMEType: c.Request.Header.Get("Content-Type"),
|
||||
File: c.Request.Body,
|
||||
Name: fileName,
|
||||
@@ -75,11 +75,11 @@ func SlaveUpload(c *gin.Context) {
|
||||
|
||||
// 是否允许覆盖
|
||||
if c.Request.Header.Get("X-Cr-Overwrite") == "false" {
|
||||
ctx = context.WithValue(ctx, fsctx.DisableOverwrite, true)
|
||||
fileData.Mode = fsctx.Create
|
||||
}
|
||||
|
||||
// 执行上传
|
||||
err = fs.Upload(ctx, fileData)
|
||||
err = fs.Upload(ctx, &fileData)
|
||||
if err != nil {
|
||||
c.JSON(200, serializer.Err(serializer.CodeUploadFailed, err.Error(), err))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user