mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: delete objects
This commit is contained in:
@@ -9,10 +9,10 @@ import (
|
||||
|
||||
// DirectoryService 创建新目录服务
|
||||
type DirectoryService struct {
|
||||
Path string `form:"path" json:"path" binding:"required,min=1,max=65535"`
|
||||
Path string `uri:"path" json:"path" binding:"required,min=1,max=65535"`
|
||||
}
|
||||
|
||||
// ListDirectory 列出目录内容 TODO:test
|
||||
// ListDirectory 列出目录内容
|
||||
func (service *DirectoryService) ListDirectory(c *gin.Context) serializer.Response {
|
||||
// 创建文件系统
|
||||
fs, err := filesystem.NewFileSystemFromContext(c)
|
||||
|
||||
@@ -30,7 +30,7 @@ func (service *FileDownloadService) Download(ctx context.Context, c *gin.Context
|
||||
}
|
||||
|
||||
// 设置文件名
|
||||
c.Header("Content-Disposition", "attachment; filename=\""+fs.Target.Name+"\"")
|
||||
c.Header("Content-Disposition", "attachment; filename=\""+fs.FileTarget[0].Name+"\"")
|
||||
// 发送文件
|
||||
http.ServeContent(c.Writer, c.Request, "", time.Time{}, rs)
|
||||
|
||||
|
||||
34
service/explorer/objects.go
Normal file
34
service/explorer/objects.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package explorer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/HFO4/cloudreve/pkg/filesystem"
|
||||
"github.com/HFO4/cloudreve/pkg/serializer"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// ItemService 处理多文件/目录相关服务
|
||||
type ItemService struct {
|
||||
Items []string `json:"items" binding:"exists"`
|
||||
Dirs []string `json:"dirs" binding:"exists"`
|
||||
}
|
||||
|
||||
// Delete 删除对象
|
||||
func (service *ItemService) Delete(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.Delete(ctx, service.Dirs, service.Items)
|
||||
if err != nil {
|
||||
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
||||
}
|
||||
|
||||
return serializer.Response{
|
||||
Code: 0,
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user