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)