mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +01:00
🎨 Add kernel API /api/file/renameFile https://github.com/siyuan-note/siyuan/issues/8328
This commit is contained in:
parent
68a674b11e
commit
e4229f2bad
6 changed files with 82 additions and 1 deletions
|
|
@ -171,6 +171,36 @@ func readDir(c *gin.Context) {
|
|||
ret.Data = files
|
||||
}
|
||||
|
||||
func renameFile(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
c.JSON(http.StatusOK, ret)
|
||||
return
|
||||
}
|
||||
|
||||
filePath := arg["path"].(string)
|
||||
newPath := arg["newPath"].(string)
|
||||
filePath = filepath.Join(util.WorkspaceDir, filePath)
|
||||
_, err := os.Stat(filePath)
|
||||
if os.IsNotExist(err) {
|
||||
c.Status(404)
|
||||
return
|
||||
}
|
||||
if nil != err {
|
||||
logging.LogErrorf("stat [%s] failed: %s", filePath, err)
|
||||
c.Status(500)
|
||||
return
|
||||
}
|
||||
|
||||
if err = filelock.Rename(filePath, newPath); nil != err {
|
||||
c.Status(500)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func removeFile(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue