fixed # 修复部分样式BUG

This commit is contained in:
2026-11-24 12:08:04 +08:00
parent 2d7bd0fbdc
commit 98116bef7b
17 changed files with 605 additions and 73 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ const { game } = await import(new URL("noname.js", document.baseURI).href);
game.saveConfig("shuYing_mengsan_zip_trial", true);
```
每包按 5 MiB 的展开数据量分组,压缩包最大 6 MiB。大于展开上限的单文件继续逐个下载。客户端顺序处理同源同标签的附件,已校验并暂存的文件可供本次安装复用。附件缺失或无法使用时,剩余文件从当前标签的 raw 路径补齐。
每包按 10 MiB 的展开数据量分组,压缩包最大 11 MiB。大于展开上限的单文件继续逐个下载。客户端顺序处理同源同标签的附件,已校验并暂存的文件可供本次安装复用。附件缺失或无法使用时,剩余文件从当前标签的 raw 路径补齐。
Electron 走原生 HTTPS,Cordova 使用 `FileTransfer` 下载一包到当前操作的临时目录,读取前核对大小,处理结束后清理。网页端走 Fetch,附件域不可读时回退。ZIP 解压需要支持 `DecompressionStream("deflate-raw")`,不支持的客户端继续逐文件下载。
+2 -2
View File
@@ -9,8 +9,8 @@ from pathlib import Path
from generate_manifest import validate_relative_paths
MAX_UNCOMPRESSED_BYTES = 5 * 1024**2
MAX_ARCHIVE_BYTES = 6 * 1024**2
MAX_UNCOMPRESSED_BYTES = 10 * 1024**2
MAX_ARCHIVE_BYTES = MAX_UNCOMPRESSED_BYTES + 1024**2
def write_part(root: Path, part: Path, files: list[str], manifest: dict) -> None:
+3 -3
View File
@@ -30,11 +30,11 @@ class MengsanArchivesTest(unittest.TestCase):
}), encoding="utf-8")
def test_parts_cover_packable_files_once(self):
first = b"a" * (3 * 1024**2)
second = b"b" * (3 * 1024**2)
first = b"a" * (10 * 1024**2)
second = b"b"
self.write_snapshot({
"mengsan/b": second,
"mengsan/oversized": b"c" * (5 * 1024**2 + 1),
"mengsan/oversized": b"c" * (10 * 1024**2 + 1),
"mengsan/a": first,
})
parts = build_archives(self.root, self.output, "v2.0.2.3-rc.8")
+22 -8
View File
@@ -25,13 +25,13 @@ function info(text) {
return { size: Buffer.byteLength(text), sha256: createHash("sha256").update(text).digest("hex") };
}
function zip(files) {
function zip(files, compression = "DEFLATE") {
const archive = new JSZip();
for (const [name, data] of Object.entries(files)) archive.file(name, data);
return archive.generate({ type: "uint8array", compression: "DEFLATE" });
return archive.generate({ type: "uint8array", compression });
}
async function setup({ source = "github", parts = [zip(assets)], releaseTag = tag,
async function setup({ source = "github", contents = assets, parts = [zip(contents)], releaseTag = tag,
draft = false, failWrite = false, record, trial = true, transport = "browser",
blocksBrowserAssets = false, canInflate = true, localVersion = version } = {}) {
const github = source == "github";
@@ -74,7 +74,7 @@ async function setup({ source = "github", parts = [zip(assets)], releaseTag = ta
files: { "extension.js": info("main") },
modules: { mengsan: { entry: moduleEntry, manifest: modulePath } } };
const moduleManifest = { algorithm: "sha256", module_id: "mengsan", version,
files: Object.fromEntries(Object.entries(assets).map(([file, content]) => [file, info(content)])) };
files: Object.fromEntries(Object.entries(contents).map(([file, content]) => [file, info(content)])) };
const attachments = parts?.map((part, index) => {
const name = `mengsan-${tag}-part-${String(index + 1).padStart(3, "0")}.zip`;
const url = `${repository}/releases/download/${tag}/${name}`;
@@ -159,7 +159,7 @@ async function setup({ source = "github", parts = [zip(assets)], releaseTag = ta
}
return new Response(part.bytes || part);
}
for (const [file, content] of Object.entries({ ...assets, "extension.js": "main" })) {
for (const [file, content] of Object.entries({ ...contents, "extension.js": "main" })) {
if (url == raw(file)) return new Response(content);
}
return new Response(null, { status: 404 });
@@ -186,7 +186,7 @@ async function setup({ source = "github", parts = [zip(assets)], releaseTag = ta
await module.link(() => engine);
await module.evaluate();
const shuYing = { text: { style: {}, showPopover() {}, setAttribute() {}, matches: () => false } };
return { updater: module.namespace.default, shuYing, requests, releaseUrl, raw, attachments, nativeRequests,
return { updater: module.namespace.default, shuYing, requests, releaseUrl, raw, attachments, nativeRequests, contents,
writes, config, files, alerts, errors };
}
@@ -199,7 +199,7 @@ async function install(options) {
function assertInstalled(result) {
assert.deepEqual(result.errors, []);
assert.equal(result.config[recordKey]?.status, "installed", result.alerts.join("\n"));
for (const [file, content] of Object.entries(assets)) {
for (const [file, content] of Object.entries(result.contents)) {
assert.equal(new TextDecoder().decode(result.files.get(extensionRoot + file)), content);
}
}
@@ -240,7 +240,6 @@ for (const [description, options] of Object.entries({
"draft release": { draft: true },
"invalid ZIP": { parts: [new Uint8Array([1, 2, 3])] },
"ZIP contains unlisted entries": { parts: [zip({ ...assets, "../unexpected.js": "x" })] },
"ZIP above the download budget": { parts: [new Uint8Array(6 * 1024**2 + 1)] },
"response larger than its attachment metadata": { parts: [{ size: 1, bytes: zip(assets) }] },
})) {
test(`uses same-tag raw after ${description}`, async () => {
@@ -253,6 +252,21 @@ for (const [description, options] of Object.entries({
});
}
test("stages a ZIP with exactly 10 MiB of content", async () => {
const contents = { ...assets, [asset]: "x".repeat(10 * 1024**2 - Buffer.byteLength(assets[moduleEntry])) };
const result = await install({ contents, parts: [zip(contents, "STORE")] });
assertInstalled(result);
assert.ok(result.requests.includes(result.attachments[0].browser_download_url));
assert.ok(!result.requests.includes(result.raw(asset)));
});
test("skips a ZIP above the 11 MiB download limit", async () => {
const result = await install({ parts: [new Uint8Array(11 * 1024**2 + 1)] });
assertInstalled(result);
assert.ok(!result.requests.includes(result.attachments[0].browser_download_url));
assert.ok(result.requests.includes(result.raw(asset)));
});
test("a staging storage failure stops the ZIP install without raw retries", async () => {
const result = await install({ failWrite: true });
assert.equal(result.config[recordKey]?.status, "disabled");