Ver código fonte

:art: 改进内核只读模式 https://github.com/siyuan-note/siyuan/issues/7615

Liang Ding 2 anos atrás
pai
commit
883898f053
3 arquivos alterados com 11 adições e 3 exclusões
  1. 3 3
      kernel/api/router.go
  2. 4 0
      kernel/api/system.go
  3. 4 0
      kernel/model/storage.go

+ 3 - 3
kernel/api/router.go

@@ -52,14 +52,14 @@ func ServeAPI(ginServer *gin.Engine) {
 	ginServer.Handle("POST", "/api/system/setAppearanceMode", model.CheckAuth, setAppearanceMode)
 	ginServer.Handle("POST", "/api/system/setAppearanceMode", model.CheckAuth, setAppearanceMode)
 	ginServer.Handle("POST", "/api/system/getSysFonts", model.CheckAuth, getSysFonts)
 	ginServer.Handle("POST", "/api/system/getSysFonts", model.CheckAuth, getSysFonts)
 	ginServer.Handle("POST", "/api/system/exit", model.CheckAuth, exit)
 	ginServer.Handle("POST", "/api/system/exit", model.CheckAuth, exit)
-	ginServer.Handle("POST", "/api/system/setUILayout", model.CheckAuth, model.CheckReadonly, setUILayout)
+	ginServer.Handle("POST", "/api/system/setUILayout", model.CheckAuth, setUILayout)
 	ginServer.Handle("POST", "/api/system/getConf", model.CheckAuth, getConf)
 	ginServer.Handle("POST", "/api/system/getConf", model.CheckAuth, getConf)
 	ginServer.Handle("POST", "/api/system/checkUpdate", model.CheckAuth, checkUpdate)
 	ginServer.Handle("POST", "/api/system/checkUpdate", model.CheckAuth, checkUpdate)
 	ginServer.Handle("POST", "/api/system/exportLog", model.CheckAuth, exportLog)
 	ginServer.Handle("POST", "/api/system/exportLog", model.CheckAuth, exportLog)
 
 
-	ginServer.Handle("POST", "/api/storage/setLocalStorage", model.CheckAuth, model.CheckReadonly, setLocalStorage)
+	ginServer.Handle("POST", "/api/storage/setLocalStorage", model.CheckAuth, setLocalStorage)
 	ginServer.Handle("POST", "/api/storage/getLocalStorage", model.CheckAuth, getLocalStorage)
 	ginServer.Handle("POST", "/api/storage/getLocalStorage", model.CheckAuth, getLocalStorage)
-	ginServer.Handle("POST", "/api/storage/setLocalStorageVal", model.CheckAuth, model.CheckReadonly, setLocalStorageVal)
+	ginServer.Handle("POST", "/api/storage/setLocalStorageVal", model.CheckAuth, setLocalStorageVal)
 	ginServer.Handle("POST", "/api/storage/removeLocalStorageVal", model.CheckAuth, model.CheckReadonly, removeLocalStorageVal)
 	ginServer.Handle("POST", "/api/storage/removeLocalStorageVal", model.CheckAuth, model.CheckReadonly, removeLocalStorageVal)
 	ginServer.Handle("POST", "/api/storage/setCriterion", model.CheckAuth, model.CheckReadonly, setCriterion)
 	ginServer.Handle("POST", "/api/storage/setCriterion", model.CheckAuth, model.CheckReadonly, setCriterion)
 	ginServer.Handle("POST", "/api/storage/getCriteria", model.CheckAuth, getCriteria)
 	ginServer.Handle("POST", "/api/storage/getCriteria", model.CheckAuth, getCriteria)

+ 4 - 0
kernel/api/system.go

@@ -171,6 +171,10 @@ func setUILayout(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)
 	defer c.JSON(http.StatusOK, ret)
 
 
+	if util.ReadOnly {
+		return
+	}
+
 	arg, ok := util.JsonArg(c, ret)
 	arg, ok := util.JsonArg(c, ret)
 	if !ok {
 	if !ok {
 		return
 		return

+ 4 - 0
kernel/model/storage.go

@@ -325,6 +325,10 @@ func GetLocalStorage() (ret map[string]interface{}, err error) {
 }
 }
 
 
 func setLocalStorage(val interface{}) (err error) {
 func setLocalStorage(val interface{}) (err error) {
+	if util.ReadOnly {
+		return
+	}
+
 	dirPath := filepath.Join(util.DataDir, "storage")
 	dirPath := filepath.Join(util.DataDir, "storage")
 	if err = os.MkdirAll(dirPath, 0755); nil != err {
 	if err = os.MkdirAll(dirPath, 0755); nil != err {
 		logging.LogErrorf("create storage [local] dir failed: %s", err)
 		logging.LogErrorf("create storage [local] dir failed: %s", err)