From 9516ac6718109fff38eb5d1d95768a94b1291e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= Date: Thu, 20 Jan 2022 19:58:25 +0800 Subject: [PATCH] :sparkler: finish move api --- drivers/operate/operate.go | 4 ++++ server/controllers/file/folder.go | 4 ++-- server/controllers/file/move.go | 5 +++++ server/controllers/path.go | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/operate/operate.go b/drivers/operate/operate.go index b7de3ebd..67bc93b8 100644 --- a/drivers/operate/operate.go +++ b/drivers/operate/operate.go @@ -8,6 +8,7 @@ import ( ) func MakeDir(driver base.Driver, account *model.Account, path string, clearCache bool) error { + log.Debugf("mkdir: %s", path) err := driver.MakeDir(path, account) if err == nil && clearCache { _ = base.DeleteCache(utils.Dir(path), account) @@ -19,6 +20,7 @@ func MakeDir(driver base.Driver, account *model.Account, path string, clearCache } func Move(driver base.Driver, account *model.Account, src, dst string, clearCache bool) error { + log.Debugf("move %s to %s", src, dst) rename := false if utils.Dir(src) == utils.Dir(dst) { rename = true @@ -42,6 +44,7 @@ func Move(driver base.Driver, account *model.Account, src, dst string, clearCach } func Copy(driver base.Driver, account *model.Account, src, dst string, clearCache bool) error { + log.Debugf("copy %s to %s", src, dst) err := driver.Copy(src, dst, account) if err == nil && clearCache { _ = base.DeleteCache(utils.Dir(dst), account) @@ -53,6 +56,7 @@ func Copy(driver base.Driver, account *model.Account, src, dst string, clearCach } func Delete(driver base.Driver, account *model.Account, path string, clearCache bool) error { + log.Debugf("delete %s", path) err := driver.Delete(path, account) if err == nil && clearCache { _ = base.DeleteCache(utils.Dir(path), account) diff --git a/server/controllers/file/folder.go b/server/controllers/file/folder.go index 27775744..601d8f5a 100644 --- a/server/controllers/file/folder.go +++ b/server/controllers/file/folder.go @@ -16,9 +16,9 @@ func Folder(c *gin.Context) { common.ErrorResp(c, err, 400) return } - var files []model.File + var files = make([]model.File, 0) var err error - if model.AccountsCount() > 1 && req.Path == "/" { + if model.AccountsCount() > 1 && (req.Path == "/" || req.Path == "") { files, err = model.GetAccountFiles() if err != nil { common.ErrorResp(c, err, 500) diff --git a/server/controllers/file/move.go b/server/controllers/file/move.go index dbc6a262..a4715ce2 100644 --- a/server/controllers/file/move.go +++ b/server/controllers/file/move.go @@ -3,6 +3,7 @@ package file import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/drivers/operate" + "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/server/common" "github.com/Xhofe/alist/utils" "github.com/gin-gonic/gin" @@ -24,6 +25,10 @@ func Move(c *gin.Context) { common.ErrorStrResp(c, "Empty file names", 400) return } + if model.AccountsCount() > 1 && (req.SrcDir == "/" || req.DstDir == "/") { + common.ErrorStrResp(c, "Can't operate root folder", 400) + return + } srcAccount, srcPath, srcDriver, err := common.ParsePath(utils.Join(req.SrcDir, req.Names[0])) if err != nil { common.ErrorResp(c, err, 500) diff --git a/server/controllers/path.go b/server/controllers/path.go index c0623bad..e4982dc2 100644 --- a/server/controllers/path.go +++ b/server/controllers/path.go @@ -77,7 +77,7 @@ func Path(c *gin.Context) { if meta != nil && meta.Upload { upload = true } - if model.AccountsCount() > 1 && req.Path == "/" { + if model.AccountsCount() > 1 && (req.Path == "/" || req.Path == "") { files, err := model.GetAccountFiles() if err != nil { common.ErrorResp(c, err, 500)