mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-02 11:31:41 +08:00
Improve the response status code of kernel API /api/file/getFile
(#9075)
* 🎨 Improve the response status code of API `/api/file/getFile`
* refactor: change status code from `204` to `202`
This commit is contained in:
parent
dc3889b5b3
commit
baa3ef0bb4
19
API.md
19
API.md
@ -992,7 +992,24 @@ View API token in <kbd>Settings - About</kbd>, request header: `Authorization: T
|
|||||||
* `path`: the file path under the workspace path
|
* `path`: the file path under the workspace path
|
||||||
* Return value
|
* Return value
|
||||||
|
|
||||||
File content
|
* Response status code `200`: File content
|
||||||
|
* Response status code `202`: Exception information
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 404,
|
||||||
|
"msg": "",
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* `code`: non-zero for exceptions
|
||||||
|
|
||||||
|
* `-1`: Parameter parsing error
|
||||||
|
* `404`: Not Found (file doesn't exist)
|
||||||
|
* `405`: Method Not Allowed (it's a directory)
|
||||||
|
* `500`: Server Error (stat file failed / read file failed)
|
||||||
|
* `msg`: a piece of text describing the error
|
||||||
|
|
||||||
### Put file
|
### Put file
|
||||||
|
|
||||||
|
19
API_zh_CN.md
19
API_zh_CN.md
@ -984,7 +984,24 @@
|
|||||||
* `path`:工作空间路径下的文件路径
|
* `path`:工作空间路径下的文件路径
|
||||||
* 返回值
|
* 返回值
|
||||||
|
|
||||||
文件内容
|
* 响应状态码 `200`: 文件内容
|
||||||
|
* 响应状态码 `202`: 异常信息
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 404,
|
||||||
|
"msg": "",
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* `code`: 非零的异常值
|
||||||
|
|
||||||
|
* `-1`: 参数解析错误
|
||||||
|
* `404`: 未找到 (文件不存在)
|
||||||
|
* `405`: 方法不被允许 (这是一个目录)
|
||||||
|
* `500`: 服务器错误 (文件查询失败 / 文件读取失败)
|
||||||
|
* `msg`: 一段描述错误的文本
|
||||||
|
|
||||||
### 写入文件
|
### 写入文件
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ func getFile(c *gin.Context) {
|
|||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
arg, ok := util.JsonArg(c, ret)
|
arg, ok := util.JsonArg(c, ret)
|
||||||
if !ok {
|
if !ok {
|
||||||
c.JSON(http.StatusOK, ret)
|
c.JSON(http.StatusAccepted, ret)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,21 +93,21 @@ func getFile(c *gin.Context) {
|
|||||||
info, err := os.Stat(filePath)
|
info, err := os.Stat(filePath)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
ret.Code = 404
|
ret.Code = 404
|
||||||
c.JSON(http.StatusOK, ret)
|
c.JSON(http.StatusAccepted, ret)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("stat [%s] failed: %s", filePath, err)
|
logging.LogErrorf("stat [%s] failed: %s", filePath, err)
|
||||||
ret.Code = 500
|
ret.Code = 500
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
c.JSON(http.StatusOK, ret)
|
c.JSON(http.StatusAccepted, ret)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
logging.LogErrorf("file [%s] is a directory", filePath)
|
logging.LogErrorf("file [%s] is a directory", filePath)
|
||||||
ret.Code = 405
|
ret.Code = 405
|
||||||
ret.Msg = "file is a directory"
|
ret.Msg = "file is a directory"
|
||||||
c.JSON(http.StatusOK, ret)
|
c.JSON(http.StatusAccepted, ret)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ func getFile(c *gin.Context) {
|
|||||||
logging.LogErrorf("read file [%s] failed: %s", filePath, err)
|
logging.LogErrorf("read file [%s] failed: %s", filePath, err)
|
||||||
ret.Code = 500
|
ret.Code = 500
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
c.JSON(http.StatusOK, ret)
|
c.JSON(http.StatusAccepted, ret)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user