From 0833ed83461c9c0e35d549e931418b817d657784 Mon Sep 17 00:00:00 2001 From: cyfung1031 <44498510+cyfung1031@users.noreply.github.com> Date: Sat, 28 Mar 2026 19:10:06 +0900 Subject: [PATCH 1/8] =?UTF-8?q?Breaking:=20=E4=BB=A5=20OPFS=20=E5=82=A8?= =?UTF-8?q?=E5=AD=98=20Code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/migrate.ts | 15 ++- src/app/repo/scripts.ts | 91 +++++++++++++++---- src/app/service/service_worker/runtime.ts | 7 +- src/app/service/service_worker/script.ts | 6 +- src/app/service/service_worker/subscribe.ts | 2 +- src/app/service/service_worker/synchronize.ts | 5 +- .../components/CloudScriptPlan/index.tsx | 4 +- .../options/routes/script/ScriptEditor.tsx | 6 +- src/pkg/utils/script.ts | 4 +- 9 files changed, 102 insertions(+), 38 deletions(-) diff --git a/src/app/migrate.ts b/src/app/migrate.ts index 63244e79e..ff9d25b2f 100644 --- a/src/app/migrate.ts +++ b/src/app/migrate.ts @@ -1,7 +1,7 @@ import { getStorageName } from "@App/pkg/utils/utils"; import { db } from "./repo/dao"; import type { Script, ScriptAndCode } from "./repo/scripts"; -import { ScriptCodeDAO, ScriptDAO } from "./repo/scripts"; +import { ScriptCodeDAO, ScriptCodeDAONew, ScriptDAO } from "./repo/scripts"; import type { Subscribe } from "./repo/subscribe"; import { SubscribeDAO } from "./repo/subscribe"; import type { Value } from "./repo/value"; @@ -19,7 +19,7 @@ export function migrateToChromeStorage() { // 迁移脚本 const scripts = await db.table("scripts").toArray(); const scriptDAO = new ScriptDAO(); - const scriptCodeDAO = new ScriptCodeDAO(); + const scriptCodeDAO = new ScriptCodeDAONew(); console.log("开始迁移脚本数据", scripts.length); await Promise.all( // 不处理 Promise.reject ? @@ -267,6 +267,17 @@ export function migrateChromeStorage() { ); }, }, + { + version: 2, + upgrade: async () => { + // 修复之前originDomain字段错误的数据 + const scriptCodeDAO = new ScriptCodeDAO(); + const scriptCodeDAONew = new ScriptCodeDAONew(); + const scriptCodes = await scriptCodeDAO.all(); + await Promise.all(scriptCodes.map(async (scriptCode) => scriptCodeDAONew.save(scriptCode))); + await scriptCodeDAO.deletes(scriptCodes.map((e) => e.uuid)); + }, + }, ]; const localstorageDAO = new LocalStorageDAO(); localstorageDAO.get("migrations").then(async (item) => { diff --git a/src/app/repo/scripts.ts b/src/app/repo/scripts.ts index 6fcc2b86f..11489ea38 100644 --- a/src/app/repo/scripts.ts +++ b/src/app/repo/scripts.ts @@ -147,33 +147,18 @@ export type TClientPageLoadInfo = | { ok: false }; export class ScriptDAO extends Repo