mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +01:00
🎨 Kernel API /api/file/* no longer use HTTP status code https://github.com/siyuan-note/siyuan/issues/8329
This commit is contained in:
parent
8c843f8775
commit
25acbb6929
1 changed files with 24 additions and 14 deletions
|
|
@ -92,24 +92,27 @@ func getFile(c *gin.Context) {
|
|||
filePath = filepath.Join(util.WorkspaceDir, filePath)
|
||||
info, err := os.Stat(filePath)
|
||||
if os.IsNotExist(err) {
|
||||
c.Status(404)
|
||||
ret.Code = 404
|
||||
return
|
||||
}
|
||||
if nil != err {
|
||||
logging.LogErrorf("stat [%s] failed: %s", filePath, err)
|
||||
c.Status(500)
|
||||
ret.Code = 500
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
if info.IsDir() {
|
||||
logging.LogErrorf("file [%s] is a directory", filePath)
|
||||
c.Status(405)
|
||||
ret.Code = 405
|
||||
ret.Msg = "file is a directory"
|
||||
return
|
||||
}
|
||||
|
||||
data, err := filelock.ReadFile(filePath)
|
||||
if nil != err {
|
||||
logging.LogErrorf("read file [%s] failed: %s", filePath, err)
|
||||
c.Status(500)
|
||||
ret.Code = 500
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -139,24 +142,27 @@ func readDir(c *gin.Context) {
|
|||
dirPath = filepath.Join(util.WorkspaceDir, dirPath)
|
||||
info, err := os.Stat(dirPath)
|
||||
if os.IsNotExist(err) {
|
||||
c.Status(404)
|
||||
ret.Code = 404
|
||||
return
|
||||
}
|
||||
if nil != err {
|
||||
logging.LogErrorf("stat [%s] failed: %s", dirPath, err)
|
||||
c.Status(500)
|
||||
ret.Code = 500
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
if !info.IsDir() {
|
||||
logging.LogErrorf("file [%s] is not a directory", dirPath)
|
||||
c.Status(405)
|
||||
ret.Code = 405
|
||||
ret.Msg = "file is not a directory"
|
||||
return
|
||||
}
|
||||
|
||||
entries, err := os.ReadDir(dirPath)
|
||||
if nil != err {
|
||||
logging.LogErrorf("read dir [%s] failed: %s", dirPath, err)
|
||||
c.Status(500)
|
||||
ret.Code = 500
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -220,18 +226,20 @@ func removeFile(c *gin.Context) {
|
|||
filePath = filepath.Join(util.WorkspaceDir, filePath)
|
||||
_, err := os.Stat(filePath)
|
||||
if os.IsNotExist(err) {
|
||||
c.Status(404)
|
||||
ret.Code = 404
|
||||
return
|
||||
}
|
||||
if nil != err {
|
||||
logging.LogErrorf("stat [%s] failed: %s", filePath, err)
|
||||
c.Status(500)
|
||||
ret.Code = 500
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
if err = filelock.Remove(filePath); nil != err {
|
||||
logging.LogErrorf("remove [%s] failed: %s", filePath, err)
|
||||
c.Status(500)
|
||||
ret.Code = 500
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -255,7 +263,8 @@ func putFile(c *gin.Context) {
|
|||
fileHeader, _ := c.FormFile("file")
|
||||
if nil == fileHeader {
|
||||
logging.LogErrorf("form file is nil [path=%s]", filePath)
|
||||
c.Status(400)
|
||||
ret.Code = 400
|
||||
ret.Msg = "form file is nil"
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -300,14 +309,15 @@ func putFile(c *gin.Context) {
|
|||
modTimeInt, parseErr := strconv.ParseInt(modTimeStr, 10, 64)
|
||||
if nil != parseErr {
|
||||
logging.LogErrorf("parse mod time [%s] failed: %s", modTimeStr, parseErr)
|
||||
c.Status(500)
|
||||
ret.Code = 500
|
||||
ret.Msg = parseErr.Error()
|
||||
return
|
||||
}
|
||||
modTime = millisecond2Time(modTimeInt)
|
||||
}
|
||||
if err = os.Chtimes(filePath, modTime, modTime); nil != err {
|
||||
logging.LogErrorf("change time failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Code = 500
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue