An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Add internal kernel API `/api/file/globalCopyFiles` https://github.com/siyuan-note/siyuan/issues/10614
Daniel27c55b96a4cd
diff --git a/kernel/api/file.go b/kernel/api/file.goindex d638d08ce9..a842eb7115 100644--- a/kernel/api/file.go+++ b/kernel/api/file.go@@ -17,6 +17,7 @@package apiimport (+ "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)diff --git a/kernel/api/router.go b/kernel/api/router.goindex f598494803..6af5564d56 100644--- a/kernel/api/router.go+++ b/kernel/api/router.go@@ -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)