🎨 Add a kernel API /api/system/getWorkspaceInfo https://github.com/siyuan-note/siyuan/issues/13300

This commit is contained in:
Daniel 2024-11-29 10:56:32 +08:00
parent cc629041f9
commit 691290a7be
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 11 additions and 1 deletions

View file

@ -65,6 +65,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/system/getNetwork", model.CheckAuth, model.CheckAdminRole, getNetwork)
ginServer.Handle("POST", "/api/system/exportConf", model.CheckAuth, model.CheckAdminRole, exportConf)
ginServer.Handle("POST", "/api/system/importConf", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, importConf)
ginServer.Handle("POST", "/api/system/getWorkspaceInfo", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, getWorkspaceInfo)
ginServer.Handle("POST", "/api/storage/setLocalStorage", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setLocalStorage)
ginServer.Handle("POST", "/api/storage/getLocalStorage", model.CheckAuth, getLocalStorage)

View file

@ -35,6 +35,15 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func getWorkspaceInfo(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
ret.Data = map[string]any{
"workspaceDir": util.WorkspaceDir,
}
}
func getNetwork(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

View file

@ -232,7 +232,7 @@ func CheckAuth(c *gin.Context) {
c.Next()
return
}
if strings.HasPrefix(c.Request.RequestURI, "/api/system/getNetwork") {
if strings.HasPrefix(c.Request.RequestURI, "/api/system/getNetwork") || strings.HasPrefix(c.Request.RequestURI, "/api/system/getWorkspaceInfo") {
c.Set(RoleContextKey, RoleAdministrator)
c.Next()
return