mirror of https://github.com/Xhofe/alist
🎇 file delete
parent
2b97882b42
commit
6613c8a6c1
|
@ -0,0 +1,45 @@
|
|||
package file
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"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 {
|
||||
common.ErrorResp(c, errors.New("empty file names"), 400)
|
||||
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
|
||||
}
|
||||
clearCache := false
|
||||
if i == len(req.Names)-1 {
|
||||
clearCache = true
|
||||
}
|
||||
err = operate.Delete(driver, account, path_, clearCache)
|
||||
if err != nil {
|
||||
_ = base.DeleteCache(utils.Dir(path_), account)
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
}
|
||||
common.SuccessResp(c)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package controllers
|
||||
package file
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -11,7 +11,7 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func UploadFile(c *gin.Context) {
|
||||
func UploadFiles(c *gin.Context) {
|
||||
path := c.PostForm("path")
|
||||
path = utils.ParsePath(path)
|
||||
token := c.GetHeader("Authorization")
|
|
@ -3,6 +3,7 @@ package server
|
|||
import (
|
||||
"github.com/Xhofe/alist/server/common"
|
||||
"github.com/Xhofe/alist/server/controllers"
|
||||
"github.com/Xhofe/alist/server/controllers/file"
|
||||
"github.com/Xhofe/alist/server/middlewares"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -23,7 +24,7 @@ func InitApiRouter(r *gin.Engine) {
|
|||
path.POST("/preview", controllers.Preview)
|
||||
|
||||
//path.POST("/link",middlewares.Auth, controllers.Link)
|
||||
public.POST("/upload", controllers.UploadFile)
|
||||
public.POST("/upload", file.UploadFiles)
|
||||
|
||||
public.GET("/settings", controllers.GetSettingsPublic)
|
||||
}
|
||||
|
@ -49,6 +50,7 @@ func InitApiRouter(r *gin.Engine) {
|
|||
admin.DELETE("/meta", controllers.DeleteMeta)
|
||||
|
||||
admin.POST("/link", controllers.Link)
|
||||
admin.DELETE("/files", file.DeleteFiles)
|
||||
}
|
||||
WebDav(r)
|
||||
Static(r)
|
||||
|
|
Loading…
Reference in New Issue