mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: after uploading finished hook
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/HFO4/cloudreve/pkg/util"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// GenericBeforeUpload 通用上传前处理钩子,包含数据库操作
|
||||
@@ -36,7 +37,7 @@ func GenericBeforeUpload(ctx context.Context, fs *FileSystem) error {
|
||||
func GenericAfterUploadCanceled(ctx context.Context, fs *FileSystem) error {
|
||||
file := ctx.Value(FileCtx).(FileData)
|
||||
|
||||
filePath := ctx.Value("path").(string)
|
||||
filePath := ctx.Value(SavePathCtx).(string)
|
||||
// 删除临时文件
|
||||
if util.Exists(filePath) {
|
||||
_, err := fs.Handler.Delete(ctx, []string{filePath})
|
||||
@@ -55,13 +56,13 @@ func GenericAfterUploadCanceled(ctx context.Context, fs *FileSystem) error {
|
||||
// GenericAfterUpload 文件上传完成后,包含数据库操作
|
||||
func GenericAfterUpload(ctx context.Context, fs *FileSystem) error {
|
||||
// 获取Gin的上下文
|
||||
//ginCtx := ctx.Value(GinCtx).(*gin.Context)
|
||||
ginCtx := ctx.Value(GinCtx).(*gin.Context)
|
||||
// 文件存放的虚拟路径
|
||||
//virtualPath := ginCtx.GetHeader("X-Path")
|
||||
virtualPath := util.DotPathToStandardPath(ginCtx.GetHeader("X-Path"))
|
||||
|
||||
// 检查路径是否存在
|
||||
if !fs.IsPathExist("/") {
|
||||
return errors.New("sss")
|
||||
if !fs.IsPathExist(virtualPath) {
|
||||
return errors.New("路径\"" + virtualPath + "\"不存在")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user