mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: rename file
This commit is contained in:
@@ -14,6 +14,12 @@ type ItemMoveService struct {
|
||||
Dst string `json:"dst" binding:"required,min=1,max=65535"`
|
||||
}
|
||||
|
||||
// ItemRenameService 处理多文件/目录重命名
|
||||
type ItemRenameService struct {
|
||||
Src string `json:"src" binding:"required,min=1,max=65535,ne=/"`
|
||||
NewName string `json:"new_name" binding:"required,min=1,max=255"`
|
||||
}
|
||||
|
||||
// ItemService 处理多文件/目录相关服务
|
||||
type ItemService struct {
|
||||
Items []string `json:"items" binding:"exists,dive,ne=/"`
|
||||
@@ -73,7 +79,7 @@ func (service *ItemMoveService) Copy(ctx context.Context, c *gin.Context) serial
|
||||
return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err)
|
||||
}
|
||||
|
||||
// 移动对象
|
||||
// 复制对象
|
||||
err = fs.Copy(ctx, service.Src.Dirs, service.Src.Items, service.SrcDir, service.Dst)
|
||||
if err != nil {
|
||||
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
||||
@@ -84,3 +90,22 @@ func (service *ItemMoveService) Copy(ctx context.Context, c *gin.Context) serial
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Rename 重命名对象
|
||||
func (service *ItemRenameService) Rename(ctx context.Context, c *gin.Context) serializer.Response {
|
||||
// 创建文件系统
|
||||
fs, err := filesystem.NewFileSystemFromContext(c)
|
||||
if err != nil {
|
||||
return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err)
|
||||
}
|
||||
|
||||
// 重命名对象
|
||||
err = fs.Rename(ctx, service.Src, service.NewName)
|
||||
if err != nil {
|
||||
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
||||
}
|
||||
|
||||
return serializer.Response{
|
||||
Code: 0,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user