Просмотр исходного кода

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

Daniel 7 месяцев назад
Родитель
Сommit
691290a7be
3 измененных файлов с 11 добавлено и 1 удалено
  1. 1 0
      kernel/api/router.go
  2. 9 0
      kernel/api/system.go
  3. 1 1
      kernel/model/session.go

+ 1 - 0
kernel/api/router.go

@@ -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/getNetwork", model.CheckAuth, model.CheckAdminRole, getNetwork)
 	ginServer.Handle("POST", "/api/system/exportConf", model.CheckAuth, model.CheckAdminRole, exportConf)
 	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/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/setLocalStorage", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setLocalStorage)
 	ginServer.Handle("POST", "/api/storage/getLocalStorage", model.CheckAuth, getLocalStorage)
 	ginServer.Handle("POST", "/api/storage/getLocalStorage", model.CheckAuth, getLocalStorage)

+ 9 - 0
kernel/api/system.go

@@ -35,6 +35,15 @@ import (
 	"github.com/siyuan-note/siyuan/kernel/util"
 	"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) {
 func getNetwork(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)
 	defer c.JSON(http.StatusOK, ret)

+ 1 - 1
kernel/model/session.go

@@ -232,7 +232,7 @@ func CheckAuth(c *gin.Context) {
 			c.Next()
 			c.Next()
 			return
 			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.Set(RoleContextKey, RoleAdministrator)
 			c.Next()
 			c.Next()
 			return
 			return