mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 每个工作空间单独持久化 localStorage https://github.com/siyuan-note/siyuan/issues/6404
This commit is contained in:
parent
174eb89910
commit
de4d40c0f6
4 changed files with 212 additions and 63 deletions
|
|
@ -26,7 +26,6 @@ import (
|
|||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/conf"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
|
|
@ -164,66 +163,6 @@ func getConf(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func getLocalStorage(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
lsPath := filepath.Join(util.DataDir, "storage/local.json")
|
||||
if !gulu.File.IsExist(lsPath) {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := filelock.ReadFile(lsPath)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
ls := map[string]interface{}{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ls); nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
ret.Data = ls
|
||||
}
|
||||
|
||||
func setLocalStorage(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
val := arg["val"].(interface{})
|
||||
|
||||
dirPath := filepath.Join(util.DataDir, "storage")
|
||||
if err := os.MkdirAll(dirPath, 0755); nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
data, err := gulu.JSON.MarshalJSON(val)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
lsPath := filepath.Join(dirPath, "local.json")
|
||||
err = filelock.WriteFile(lsPath, data)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func setUILayout(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue