Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
♻️ 所有调用方恢复使用 ScriptCodeDAO(内部已支持 OPFS)
  • Loading branch information
CodFrm committed Mar 29, 2026
commit bed286b48cb6cb7981f95e97dab0a4d07b1a7773
3 changes: 0 additions & 3 deletions src/app/repo/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,3 @@ export class ScriptCodeDAO extends Repo<ScriptCode> {
return super.deletes(keys);
}
}

// 过渡期间保留别名,供其他文件引用(Task 4 将统一替换为 ScriptCodeDAO)
export { ScriptCodeDAO as ScriptCodeDAONew };
4 changes: 2 additions & 2 deletions src/app/service/service_worker/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { EmitEventRequest, ScriptLoadInfo, ScriptMatchInfo, ScriptMenu } fr
import type { IMessageQueue } from "@Packages/message/message_queue";
import type { Group, IGetSender } from "@Packages/message/server";
import type { ExtMessageSender, MessageSend } from "@Packages/message/types";
import { ScriptCodeDAONew, type TClientPageLoadInfo } from "@App/app/repo/scripts";
import { ScriptCodeDAO, type TClientPageLoadInfo } from "@App/app/repo/scripts";
import type { Script, ScriptDAO, ScriptRunResource, ScriptSite, TScriptInfo } from "@App/app/repo/scripts";
import { SCRIPT_STATUS_DISABLE, SCRIPT_STATUS_ENABLE, SCRIPT_TYPE_NORMAL } from "@App/app/repo/scripts";
import { type ValueService } from "./value";
Expand Down Expand Up @@ -128,7 +128,7 @@ export class RuntimeService {
initialCompiledResourcePromise: Promise<any> | undefined;

compiledResourceDAO: CompiledResourceDAO = new CompiledResourceDAO();
private readonly scriptCodeDAO: ScriptCodeDAONew = new ScriptCodeDAONew();
private readonly scriptCodeDAO: ScriptCodeDAO = new ScriptCodeDAO();

constructor(
private systemConfig: SystemConfig,
Expand Down
4 changes: 2 additions & 2 deletions src/app/service/service_worker/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {
ScriptRunResource,
ScriptSite,
} from "@App/app/repo/scripts";
import { SCRIPT_STATUS_DISABLE, SCRIPT_STATUS_ENABLE, ScriptCodeDAONew } from "@App/app/repo/scripts";
import { SCRIPT_STATUS_DISABLE, SCRIPT_STATUS_ENABLE, ScriptCodeDAO } from "@App/app/repo/scripts";
import { type IMessageQueue } from "@Packages/message/message_queue";
import { createScriptInfo, type ScriptInfo, type InstallSource } from "@App/pkg/utils/scriptInstall";
import { type ResourceService } from "./resource";
Expand Down Expand Up @@ -69,7 +69,7 @@ export type TScriptInstallReturn = {

export class ScriptService {
logger: Logger;
scriptCodeDAO: ScriptCodeDAONew = new ScriptCodeDAONew();
scriptCodeDAO: ScriptCodeDAO = new ScriptCodeDAO();
localStorageDAO: LocalStorageDAO = new LocalStorageDAO();
compiledResourceDAO: CompiledResourceDAO = new CompiledResourceDAO();
private readonly scriptUpdateCheck;
Expand Down
4 changes: 2 additions & 2 deletions src/app/service/service_worker/synchronize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type Script,
SCRIPT_STATUS_DISABLE,
SCRIPT_STATUS_ENABLE,
ScriptCodeDAONew,
ScriptCodeDAO,
type ScriptDAO,
} from "@App/app/repo/scripts";
import BackupExport from "@App/pkg/backup/export";
Expand Down Expand Up @@ -69,7 +69,7 @@ type PushScriptParam = TInstallScriptParams;
export class SynchronizeService {
logger: Logger;

readonly scriptCodeDAO: ScriptCodeDAONew = new ScriptCodeDAONew();
readonly scriptCodeDAO: ScriptCodeDAO = new ScriptCodeDAO();

storage: ChromeStorage = new ChromeStorage("sync", false);

Expand Down
4 changes: 2 additions & 2 deletions src/pages/components/CloudScriptPlan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { Export, ExportTarget } from "@App/app/repo/export";
import { ExportDAO } from "@App/app/repo/export";
import type { Script } from "@App/app/repo/scripts";
import { ScriptCodeDAONew } from "@App/app/repo/scripts";
import { ScriptCodeDAO } from "@App/app/repo/scripts";
import { localePath } from "@App/locales/locales";
import { makeBlobURL } from "@App/pkg/utils/utils";
import { Button, Checkbox, Form, Input, Message, Modal, Select } from "@arco-design/web-react";
Expand Down Expand Up @@ -57,7 +57,7 @@
}
});
}
}, [script]);

Check warning on line 60 in src/pages/components/CloudScriptPlan/index.tsx

View workflow job for this annotation

GitHub Actions / Run tests

React Hook useEffect has a missing dependency: 'form'. Either include it or remove the dependency array
return (
<Modal
title={
Expand Down Expand Up @@ -123,7 +123,7 @@
zip: zipFile,
...params,
});
const code = await new ScriptCodeDAONew().get(script.uuid);
const code = await new ScriptCodeDAO().get(script.uuid);
if (!code) {
Message.error(t("invalid_script_code"));
return;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/options/routes/script/ScriptEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Script } from "@App/app/repo/scripts";
import { SCRIPT_TYPE_NORMAL, ScriptCodeDAONew, ScriptDAO } from "@App/app/repo/scripts";
import { SCRIPT_TYPE_NORMAL, ScriptCodeDAO, ScriptDAO } from "@App/app/repo/scripts";
import CodeEditor from "@App/pages/components/CodeEditor";
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
Expand Down Expand Up @@ -201,7 +201,7 @@ type EditorState = {
};

const scriptDAO = new ScriptDAO();
const scriptCodeDAO = new ScriptCodeDAONew();
const scriptCodeDAO = new ScriptCodeDAO();

function ScriptEditor() {
const [visible, setVisible] = useState<{ [key: string]: boolean }>({});
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/utils/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SCRIPT_TYPE_BACKGROUND,
SCRIPT_TYPE_CRONTAB,
SCRIPT_TYPE_NORMAL,
ScriptCodeDAONew,
ScriptCodeDAO,
ScriptDAO,
} from "@App/app/repo/scripts";
import type { Subscribe } from "@App/app/repo/subscribe";
Expand Down Expand Up @@ -190,7 +190,7 @@ export async function prepareScriptByCode(
) {
throw new Error(i18n_t("error_script_type_mismatch"));
}
const scriptCode = await new ScriptCodeDAONew().get(old.uuid);
const scriptCode = await new ScriptCodeDAO().get(old.uuid);
if (!scriptCode) {

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prepareScriptByCode 这里仍用 if (!scriptCode) 判断旧脚本 code 是否存在,但 ScriptCodeDAONew.get() 当前不会返回 undefined(缺文件时返回空字符串对象),会导致缺失 code 的情况不再抛 error_old_script_code_missing,而是继续用空 code 走后续逻辑。建议配合调整 ScriptCodeDAONew.get() 的返回语义,或在这里改为检查 code.code 是否为空。

Suggested change
if (!scriptCode) {
// ScriptCodeDAONew.get() 在缺文件时可能返回空字符串对象,此处需同时检查 code 字段
if (!scriptCode || !scriptCode.code) {

Copilot uses AI. Check for mistakes.
throw new Error(i18n_t("error_old_script_code_missing"));
}
Expand Down
Loading