From b46cc6c436666f36f9b27c19b0cb400522b004f2 Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:27:39 +0800 Subject: [PATCH] fix: update value stored in tabStore after modified and saved --- backend/services/browser_service.go | 13 +++++++------ frontend/src/stores/browser.js | 8 +++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/services/browser_service.go b/backend/services/browser_service.go index 80b59e0..ccfd41a 100644 --- a/backend/services/browser_service.go +++ b/backend/services/browser_service.go @@ -1156,18 +1156,18 @@ func (b *browserService) SetKeyValue(param types.SetKeyParam) (resp types.JSResp if len(param.Format) <= 0 { param.Format = types.FORMAT_RAW } + var savedValue any switch strings.ToLower(param.KeyType) { case "string": if str, ok := param.Value.(string); !ok { resp.Msg = "invalid string value" return } else { - var saveStr string - if saveStr, err = convutil.SaveAs(str, param.Format, param.Decode, Preferences().GetDecoder()); err != nil { + if savedValue, err = convutil.SaveAs(str, param.Format, param.Decode, Preferences().GetDecoder()); err != nil { resp.Msg = fmt.Sprintf(`save to type "%s" fail: %s`, param.Format, err.Error()) return } - _, err = client.Set(ctx, key, saveStr, 0).Result() + _, err = client.Set(ctx, key, savedValue, 0).Result() // set expiration lonely, not "keepttl" if err == nil && expiration > 0 { client.Expire(ctx, key, expiration) @@ -1254,6 +1254,7 @@ func (b *browserService) SetKeyValue(param types.SetKeyParam) (resp types.JSResp if err == nil && expiration > 0 { client.Expire(ctx, key, expiration) } + savedValue = param.Value } if err != nil { @@ -1261,9 +1262,9 @@ func (b *browserService) SetKeyValue(param types.SetKeyParam) (resp types.JSResp return } resp.Success = true - //resp.Data = map[string]any{ - // "value": param.Value, - //} + resp.Data = map[string]any{ + "value": savedValue, + } return } diff --git a/frontend/src/stores/browser.js b/frontend/src/stores/browser.js index 69b0616..3bcbff9 100644 --- a/frontend/src/stores/browser.js +++ b/frontend/src/stores/browser.js @@ -769,9 +769,11 @@ const useBrowserStore = defineStore('browser', { serverInst.updateDBKeyCount(db, newKey) } } - // const tab = useTabStore() - // tab.updateValue({ server, db, key, value }) - + const { value: updatedValue } = data + if (updatedValue != null) { + const tab = useTabStore() + tab.updateValue({ server, db, key, value: updatedValue }) + } // this.loadKeySummary({ server, db, key }) return { success,