2022-01-08 14:09:27 +00:00
|
|
|
package file
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Xhofe/alist/drivers/base"
|
|
|
|
"github.com/Xhofe/alist/drivers/operate"
|
|
|
|
"github.com/Xhofe/alist/server/common"
|
|
|
|
"github.com/Xhofe/alist/utils"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DeleteFilesReq struct {
|
|
|
|
Path string `json:"path"`
|
|
|
|
Names []string `json:"names"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeleteFiles(c *gin.Context) {
|
|
|
|
var req DeleteFilesReq
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
|
|
|
common.ErrorResp(c, err, 400)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(req.Names) == 0 {
|
2022-01-13 13:23:27 +00:00
|
|
|
common.ErrorStrResp(c, "Empty file names", 400)
|
2022-01-08 14:09:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
for i, name := range req.Names {
|
|
|
|
account, path_, driver, err := common.ParsePath(utils.Join(req.Path, name))
|
|
|
|
if err != nil {
|
|
|
|
common.ErrorResp(c, err, 500)
|
|
|
|
return
|
|
|
|
}
|
2022-01-13 13:23:27 +00:00
|
|
|
if path_ == "/" {
|
|
|
|
common.ErrorStrResp(c, "Delete root folder is not allowed", 400)
|
|
|
|
return
|
|
|
|
}
|
2022-01-08 14:09:27 +00:00
|
|
|
clearCache := false
|
|
|
|
if i == len(req.Names)-1 {
|
|
|
|
clearCache = true
|
|
|
|
}
|
|
|
|
err = operate.Delete(driver, account, path_, clearCache)
|
|
|
|
if err != nil {
|
2022-01-11 15:45:12 +00:00
|
|
|
if i == 0 {
|
|
|
|
_ = base.DeleteCache(utils.Dir(path_), account)
|
|
|
|
}
|
2022-01-08 14:09:27 +00:00
|
|
|
common.ErrorResp(c, err, 500)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
common.SuccessResp(c)
|
|
|
|
}
|