feat(subtitles): 字幕站(SubHD、字幕库)在线搜索与下载;rar / 7z 解压;验证码与页面解析在沙箱里

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-10-03 02:28:29 +08:00
1 parent 92d456d123
commit 59b3680f35
32 files changed
+1704 -166

No files matched your search

+33 -1
View File
@@ -1,4 +1,4 @@
import { buildFakeTorrent } from "@umt/testkit";
import { buildFakeTorrent, RAR5_SAMPLE_BASE64, SEVENZIP_SUBTITLE_BASE64, ZIMUKU_CAPTCHA } from "@umt/testkit";
import { zipSync } from "fflate";
import { describe, expect, it } from "vitest";
import { runSandbox, SandboxError } from "../../src/sandbox/client.ts";
@@ -48,4 +48,36 @@ describe("沙箱子进程", () => {
expect(f.files.map((x) => x.path)).toEqual(["Show.S01E01.mkv"]);
expect(f.hash).toBe(t.infoHash);
});
it("rar / 7z 在沙箱里解压(撤销权限后 WASM 仍可用);非字幕条目跳过", async () => {
const r = await runSandbox("subtitle.parse", {
files: [
{ name: "pack.7z", base64: SEVENZIP_SUBTITLE_BASE64 },
{ name: "texts.rar", base64: RAR5_SAMPLE_BASE64 },
],
});
expect(r.items).toEqual([
expect.objectContaining({ name: "s7/a.chs.srt", archive: "pack.7z", language: "zh-Hans" }),
]);
expect(r.skipped).toEqual([{ name: "texts.rar", reason: "压缩包里没有字幕文件" }]);
});
it("字幕库验证码:真实样本识别正确", async () => {
expect(await runSandbox("captcha.solve", { kind: "zimuku", bmpBase64: ZIMUKU_CAPTCHA.bmpBase64 })).toEqual({
code: ZIMUKU_CAPTCHA.code,
});
});
});
describe("压缩包解压(进程内,直接测解压模块)", () => {
it("rar 列出全部条目", async () => {
const { extractArchive } = await import("../../src/sandbox/archives.ts");
const out = await extractArchive(
"rar",
Uint8Array.from(atob(RAR5_SAMPLE_BASE64), (c) => c.charCodeAt(0)),
() => true,
);
expect(Object.keys(out).sort()).toEqual(["stest1.txt", "stest2.txt"]);
await expect(extractArchive("rar", new Uint8Array([1, 2, 3]), () => true)).rejects.toThrow();
});
});