This commit is contained in:
Daniel 2023-05-23 09:01:37 +08:00
parent 68a674b11e
commit e4229f2bad
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
6 changed files with 82 additions and 1 deletions

View file

@ -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)

View file

@ -179,6 +179,7 @@ func ServeAPI(ginServer *gin.Engine) {
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/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, model.CheckReadonly, readDir)
ginServer.Handle("POST", "/api/ref/refreshBacklink", model.CheckAuth, refreshBacklink)

View file

@ -47,7 +47,7 @@ require (
github.com/siyuan-note/dejavu v0.0.0-20230501032540-9d7760329f9d
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75
github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b
github.com/siyuan-note/filelock v0.0.0-20230501032014-b981a05568ef
github.com/siyuan-note/filelock v0.0.0-20230523004741-d9121740f638
github.com/siyuan-note/httpclient v0.0.0-20230501032226-9e9018416f53
github.com/siyuan-note/logging v0.0.0-20230327073243-ebe83aec1493
github.com/siyuan-note/riff v0.0.0-20230516073320-b440b8feaabd

View file

@ -291,6 +291,8 @@ github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b h1:828lTUW2C0
github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b/go.mod h1:Sqo4FYX5lAXu7gWkbEdJF0e6P57tNNVV4WDKYDctokI=
github.com/siyuan-note/filelock v0.0.0-20230501032014-b981a05568ef h1:ZNJKZ+inFBk2k4PnMT8XZLIyfhzTRd29oOVOe+dg0kE=
github.com/siyuan-note/filelock v0.0.0-20230501032014-b981a05568ef/go.mod h1:lZ/T8iztsw7BIR4MJxLhsC1tnb81o8r8b8JstcpUkr0=
github.com/siyuan-note/filelock v0.0.0-20230523004741-d9121740f638 h1:0dvT+1FvuUf6/GFkFRQML0Q3DLulbswj1GJJ0j7BlD8=
github.com/siyuan-note/filelock v0.0.0-20230523004741-d9121740f638/go.mod h1:v2bpUtjvsvt1TRHgly1mIXQjAEo/t50dOM9YiC813qQ=
github.com/siyuan-note/httpclient v0.0.0-20230501032226-9e9018416f53 h1:CXYTR4QhuibnTYkvDuLQsTnAQiq0Vd8J7ukRXyqrJPs=
github.com/siyuan-note/httpclient v0.0.0-20230501032226-9e9018416f53/go.mod h1:S/pXlPZYCJTOZjmdmQyVga//24x3XEM+MG8vIYO26gw=
github.com/siyuan-note/logging v0.0.0-20230327073243-ebe83aec1493 h1:oaN5b0WDFkjdBgGxmmBnMrtZxaJ76LZLwhQSZnznJMI=