mirror of https://github.com/Xhofe/alist
🎇 finish move api
parent
de638c7c36
commit
9516ac6718
|
@ -8,6 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func MakeDir(driver base.Driver, account *model.Account, path string, clearCache bool) error {
|
func MakeDir(driver base.Driver, account *model.Account, path string, clearCache bool) error {
|
||||||
|
log.Debugf("mkdir: %s", path)
|
||||||
err := driver.MakeDir(path, account)
|
err := driver.MakeDir(path, account)
|
||||||
if err == nil && clearCache {
|
if err == nil && clearCache {
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
_ = 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 {
|
func Move(driver base.Driver, account *model.Account, src, dst string, clearCache bool) error {
|
||||||
|
log.Debugf("move %s to %s", src, dst)
|
||||||
rename := false
|
rename := false
|
||||||
if utils.Dir(src) == utils.Dir(dst) {
|
if utils.Dir(src) == utils.Dir(dst) {
|
||||||
rename = true
|
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 {
|
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)
|
err := driver.Copy(src, dst, account)
|
||||||
if err == nil && clearCache {
|
if err == nil && clearCache {
|
||||||
_ = base.DeleteCache(utils.Dir(dst), account)
|
_ = 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 {
|
func Delete(driver base.Driver, account *model.Account, path string, clearCache bool) error {
|
||||||
|
log.Debugf("delete %s", path)
|
||||||
err := driver.Delete(path, account)
|
err := driver.Delete(path, account)
|
||||||
if err == nil && clearCache {
|
if err == nil && clearCache {
|
||||||
_ = base.DeleteCache(utils.Dir(path), account)
|
_ = base.DeleteCache(utils.Dir(path), account)
|
||||||
|
|
|
@ -16,9 +16,9 @@ func Folder(c *gin.Context) {
|
||||||
common.ErrorResp(c, err, 400)
|
common.ErrorResp(c, err, 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var files []model.File
|
var files = make([]model.File, 0)
|
||||||
var err error
|
var err error
|
||||||
if model.AccountsCount() > 1 && req.Path == "/" {
|
if model.AccountsCount() > 1 && (req.Path == "/" || req.Path == "") {
|
||||||
files, err = model.GetAccountFiles()
|
files, err = model.GetAccountFiles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
common.ErrorResp(c, err, 500)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package file
|
||||||
import (
|
import (
|
||||||
"github.com/Xhofe/alist/drivers/base"
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
"github.com/Xhofe/alist/drivers/operate"
|
"github.com/Xhofe/alist/drivers/operate"
|
||||||
|
"github.com/Xhofe/alist/model"
|
||||||
"github.com/Xhofe/alist/server/common"
|
"github.com/Xhofe/alist/server/common"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -24,6 +25,10 @@ func Move(c *gin.Context) {
|
||||||
common.ErrorStrResp(c, "Empty file names", 400)
|
common.ErrorStrResp(c, "Empty file names", 400)
|
||||||
return
|
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]))
|
srcAccount, srcPath, srcDriver, err := common.ParsePath(utils.Join(req.SrcDir, req.Names[0]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
common.ErrorResp(c, err, 500)
|
||||||
|
|
|
@ -77,7 +77,7 @@ func Path(c *gin.Context) {
|
||||||
if meta != nil && meta.Upload {
|
if meta != nil && meta.Upload {
|
||||||
upload = true
|
upload = true
|
||||||
}
|
}
|
||||||
if model.AccountsCount() > 1 && req.Path == "/" {
|
if model.AccountsCount() > 1 && (req.Path == "/" || req.Path == "") {
|
||||||
files, err := model.GetAccountFiles()
|
files, err := model.GetAccountFiles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
common.ErrorResp(c, err, 500)
|
||||||
|
|
Loading…
Reference in New Issue