feat: 本地清理旧用户遗留的localstorage
This commit is contained in:
parent
c5847d3222
commit
fc979b6841
@ -32,32 +32,16 @@ export interface LocalSettings {
|
||||
};
|
||||
}
|
||||
|
||||
function clearLocalSettingsStorage() {
|
||||
localStorage.removeItem(LOCAL_SETTINGS_KEY);
|
||||
}
|
||||
|
||||
export function getLocalSettings(): LocalSettings {
|
||||
if (typeof window === "undefined") {
|
||||
return DEFAULT_LOCAL_SETTINGS;
|
||||
}
|
||||
const json = localStorage.getItem(LOCAL_SETTINGS_KEY);
|
||||
try {
|
||||
if (json) {
|
||||
const settings = JSON.parse(json);
|
||||
const mergedSettings = {
|
||||
...DEFAULT_LOCAL_SETTINGS,
|
||||
context: {
|
||||
...DEFAULT_LOCAL_SETTINGS.context,
|
||||
...settings.context,
|
||||
},
|
||||
layout: {
|
||||
...DEFAULT_LOCAL_SETTINGS.layout,
|
||||
...settings.layout,
|
||||
},
|
||||
notification: {
|
||||
...DEFAULT_LOCAL_SETTINGS.notification,
|
||||
...settings.notification,
|
||||
},
|
||||
};
|
||||
return mergedSettings;
|
||||
}
|
||||
} catch {}
|
||||
|
||||
clearLocalSettingsStorage();
|
||||
return DEFAULT_LOCAL_SETTINGS;
|
||||
}
|
||||
|
||||
@ -65,6 +49,6 @@ export function saveLocalSettings(settings: LocalSettings) {
|
||||
void settings;
|
||||
// 注释了,因为本地存储会污染模型配置
|
||||
console.log("localStorage设置,已经注释");
|
||||
localStorage.removeItem(LOCAL_SETTINGS_KEY);
|
||||
clearLocalSettingsStorage();
|
||||
// localStorage.setItem(LOCAL_SETTINGS_KEY, JSON.stringify(settings));
|
||||
}
|
||||
|
||||
43
frontend/tests/e2e/local-settings.spec.ts
Normal file
43
frontend/tests/e2e/local-settings.spec.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
import { invalidNewChatUrl } from "./support/chat-helpers";
|
||||
|
||||
const LOCAL_SETTINGS_KEY = "deerflow.local-settings";
|
||||
|
||||
test.describe("本地设置清理", () => {
|
||||
test("禁用持久化后会在进入工作台时清除历史 localStorage 设置", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.addInitScript(
|
||||
({ key, value }: { key: string; value: string }) => {
|
||||
window.localStorage.setItem(key, value);
|
||||
},
|
||||
{
|
||||
key: LOCAL_SETTINGS_KEY,
|
||||
value: JSON.stringify({
|
||||
context: {
|
||||
model_name: "gpt-5",
|
||||
mode: "pro",
|
||||
reasoning_effort: "high",
|
||||
},
|
||||
layout: {
|
||||
sidebar_collapsed: true,
|
||||
},
|
||||
notification: {
|
||||
enabled: false,
|
||||
},
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
await page.goto(invalidNewChatUrl());
|
||||
await expect(page.locator("textarea[name='message']")).toBeVisible();
|
||||
|
||||
await expect
|
||||
.poll(
|
||||
() => page.evaluate((key) => window.localStorage.getItem(key), LOCAL_SETTINGS_KEY),
|
||||
{ message: "expected deprecated local settings storage to be cleared" },
|
||||
)
|
||||
.toBeNull();
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user