mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
🎨 Add internal kernel API /api/file/globalCopyFiles https://github.com/siyuan-note/siyuan/issues/10614
This commit is contained in:
parent
8287631078
commit
27c55b96a4
2 changed files with 40 additions and 0 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
|
|
@ -35,6 +36,44 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"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) {
|
func copyFile(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||||
ginServer.Handle("POST", "/api/file/getFile", model.CheckAuth, getFile)
|
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/putFile", model.CheckAuth, model.CheckReadonly, putFile)
|
||||||
ginServer.Handle("POST", "/api/file/copyFile", model.CheckAuth, model.CheckReadonly, copyFile)
|
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/removeFile", model.CheckAuth, model.CheckReadonly, removeFile)
|
||||||
ginServer.Handle("POST", "/api/file/renameFile", model.CheckAuth, model.CheckReadonly, renameFile)
|
ginServer.Handle("POST", "/api/file/renameFile", model.CheckAuth, model.CheckReadonly, renameFile)
|
||||||
ginServer.Handle("POST", "/api/file/readDir", model.CheckAuth, readDir)
|
ginServer.Handle("POST", "/api/file/readDir", model.CheckAuth, readDir)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue