Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2024-03-18 12:11:24 +08:00
commit 21b64d3710
2 changed files with 40 additions and 0 deletions

View file

@ -17,6 +17,7 @@
package api
import (
"fmt"
"io"
"mime"
"mime/multipart"
@ -35,6 +36,44 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func globalCopyFiles(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
var srcs []string
srcsArg := arg["srcs"].([]interface{})
for _, s := range srcsArg {
srcs = append(srcs, s.(string))
}
for _, src := range srcs {
if !filelock.IsExist(src) {
msg := fmt.Sprintf("file [%s] does not exist", src)
logging.LogErrorf(msg)
ret.Code = -1
ret.Msg = msg
return
}
}
destDir := arg["destDir"].(string) // 相对于工作空间的路径
destDir = filepath.Join(util.WorkspaceDir, destDir)
for _, src := range srcs {
dest := filepath.Join(destDir, filepath.Base(src))
if err := filelock.Copy(src, dest); nil != err {
logging.LogErrorf("copy file [%s] to [%s] failed: %s", src, dest, err)
ret.Code = -1
ret.Msg = err.Error()
return
}
}
}
func copyFile(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

View file

@ -202,6 +202,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/file/getFile", model.CheckAuth, getFile)
ginServer.Handle("POST", "/api/file/putFile", model.CheckAuth, model.CheckReadonly, putFile)
ginServer.Handle("POST", "/api/file/copyFile", model.CheckAuth, model.CheckReadonly, copyFile)
ginServer.Handle("POST", "/api/file/globalCopyFiles", model.CheckAuth, model.CheckReadonly, globalCopyFiles)
ginServer.Handle("POST", "/api/file/removeFile", model.CheckAuth, model.CheckReadonly, removeFile)
ginServer.Handle("POST", "/api/file/renameFile", model.CheckAuth, model.CheckReadonly, renameFile)
ginServer.Handle("POST", "/api/file/readDir", model.CheckAuth, readDir)