From ba7f04c483e59d021d335b3860f4a254399d595a Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 1 Jan 2023 14:46:05 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20localStorage=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=9C=A8=E5=A4=9A=E7=95=8C=E9=9D=A2=E5=AE=9E=E4=BE=8B=E9=97=B4?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=20https://github.com/siyuan-note/siyuan/issu?= =?UTF-8?q?es/6965?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/storage.go | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/kernel/api/storage.go b/kernel/api/storage.go index 02d089620..23b323835 100644 --- a/kernel/api/storage.go +++ b/kernel/api/storage.go @@ -136,13 +136,18 @@ func removeLocalStorageVal(c *gin.Context) { } key := arg["key"].(string) - err := model.RemoveLocalStorageVal(key) if nil != err { ret.Code = -1 ret.Msg = err.Error() return } + + app := arg["app"].(string) + evt := util.NewCmdResult("removeLocalStorageVal", 0, util.PushModeBroadcastMainExcludeSelfApp) + evt.AppId = app + evt.Data = map[string]interface{}{"key": key} + util.PushEvent(evt) } func setLocalStorageVal(c *gin.Context) { @@ -156,26 +161,18 @@ func setLocalStorageVal(c *gin.Context) { key := arg["key"].(string) val := arg["val"].(interface{}) - err := model.SetLocalStorageVal(key, val) if nil != err { ret.Code = -1 ret.Msg = err.Error() return } -} -func getLocalStorage(c *gin.Context) { - ret := gulu.Ret.NewResult() - defer c.JSON(http.StatusOK, ret) - - data, err := model.GetLocalStorage() - if nil != err { - ret.Code = -1 - ret.Msg = err.Error() - return - } - ret.Data = data + app := arg["app"].(string) + evt := util.NewCmdResult("setLocalStorageVal", 0, util.PushModeBroadcastMainExcludeSelfApp) + evt.AppId = app + evt.Data = map[string]interface{}{"key": key, "val": val} + util.PushEvent(evt) } func setLocalStorage(c *gin.Context) { @@ -201,3 +198,16 @@ func setLocalStorage(c *gin.Context) { evt.Data = val util.PushEvent(evt) } + +func getLocalStorage(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + data, err := model.GetLocalStorage() + if nil != err { + ret.Code = -1 + ret.Msg = err.Error() + return + } + ret.Data = data +}