mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 01:22:02 +08:00
🎨 When local.json is corrupted, clear the file to avoid being unable to enter the main interface Fix https://github.com/siyuan-note/siyuan/issues/7911
This commit is contained in:
parent
95ac0e828b
commit
ae4717710d
@ -177,11 +177,6 @@ func getLocalStorage(c *gin.Context) {
|
|||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
data, err := model.GetLocalStorage()
|
data := model.GetLocalStorage()
|
||||||
if nil != err {
|
|
||||||
ret.Code = -1
|
|
||||||
ret.Msg = err.Error()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ret.Data = data
|
ret.Data = data
|
||||||
}
|
}
|
||||||
|
@ -293,11 +293,7 @@ func RemoveLocalStorageVals(keys []string) (err error) {
|
|||||||
localStorageLock.Lock()
|
localStorageLock.Lock()
|
||||||
defer localStorageLock.Unlock()
|
defer localStorageLock.Unlock()
|
||||||
|
|
||||||
localStorage, err := getLocalStorage()
|
localStorage := getLocalStorage()
|
||||||
if nil != err {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
delete(localStorage, key)
|
delete(localStorage, key)
|
||||||
}
|
}
|
||||||
@ -308,11 +304,7 @@ func SetLocalStorageVal(key string, val interface{}) (err error) {
|
|||||||
localStorageLock.Lock()
|
localStorageLock.Lock()
|
||||||
defer localStorageLock.Unlock()
|
defer localStorageLock.Unlock()
|
||||||
|
|
||||||
localStorage, err := getLocalStorage()
|
localStorage := getLocalStorage()
|
||||||
if nil != err {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
localStorage[key] = val
|
localStorage[key] = val
|
||||||
return setLocalStorage(localStorage)
|
return setLocalStorage(localStorage)
|
||||||
}
|
}
|
||||||
@ -323,7 +315,7 @@ func SetLocalStorage(val interface{}) (err error) {
|
|||||||
return setLocalStorage(val)
|
return setLocalStorage(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetLocalStorage() (ret map[string]interface{}, err error) {
|
func GetLocalStorage() (ret map[string]interface{}) {
|
||||||
localStorageLock.Lock()
|
localStorageLock.Lock()
|
||||||
defer localStorageLock.Unlock()
|
defer localStorageLock.Unlock()
|
||||||
return getLocalStorage()
|
return getLocalStorage()
|
||||||
@ -355,7 +347,8 @@ func setLocalStorage(val interface{}) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLocalStorage() (ret map[string]interface{}, err error) {
|
func getLocalStorage() (ret map[string]interface{}) {
|
||||||
|
// When local.json is corrupted, clear the file to avoid being unable to enter the main interface https://github.com/siyuan-note/siyuan/issues/7911
|
||||||
ret = map[string]interface{}{}
|
ret = map[string]interface{}{}
|
||||||
lsPath := filepath.Join(util.DataDir, "storage/local.json")
|
lsPath := filepath.Join(util.DataDir, "storage/local.json")
|
||||||
if !gulu.File.IsExist(lsPath) {
|
if !gulu.File.IsExist(lsPath) {
|
||||||
|
Loading…
Reference in New Issue
Block a user