Skip to content

Spot it. Save it. Free, local-first Chrome extension for images, videos and prompts. Explore 2,000+ curated cases and connect your library to AI Agents via MCP. 提示词导演

Fix large curated package downloads in 1.24.1 (#30)

wchao6891ef5f45d27781
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3b21d57..fd3a886 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
了解每个版本带来的功能变化与使用改善。下载请前往 [GitHub Releases](https://github.com/wchao6891/PromptDirector/releases/latest)。
+## 1.24.1
+
+- 修复大于 128 MiB 的精选案例整包下载到 100% 后被拒绝的问题;保留大小与内容摘要校验。
+
## 1.24.0
- 项目按文件夹组织案例:拖动移动,显式复制保留独立副本;改善项目树、案例定位与删除恢复。
diff --git a/extension/curated-catalog.js b/extension/curated-catalog.js
index bdd0a62..cea5d8a 100644
--- a/extension/curated-catalog.js
+++ b/extension/curated-catalog.js
@@ -1,5 +1,4 @@
-import { sha256Hex } from "./sync-crypto.js";
-import { PORTABLE_LIBRARY_LIMITS } from "./resource-limits.js";
+import { sha256Blob } from "./blob-digest.js";
import { selectLibraryPackage } from "./library-package.js";
export const CURATED_CATALOG_FORMAT = "prompt-director-curated";
@@ -261,12 +260,14 @@ export function prepareCuratedEntriesPackage(libraryValue = {}, entryIdValues =
return selected;
}
-export async function verifyCuratedPackageBlob(blob, expectedSha256) {
+export async function verifyCuratedPackageBlob(blob, expectedSha256, expectedBytes) {
if (!(blob instanceof Blob) || blob.size < 22) throw new Error("精选案例包为空或无效");
- if (blob.size > PORTABLE_LIBRARY_LIMITS.maxArchiveBytes) throw new Error("精选案例包超过安全大小上限");
+ if (!Number.isSafeInteger(expectedBytes) || expectedBytes < 22 || blob.size !== expectedBytes) {
+ throw new Error("精选案例包下载大小与目录不一致");
+ }
const expected = String(expectedSha256 ?? "").toLocaleLowerCase("en-US");
if (!/^[a-f0-9]{64}$/.test(expected)) throw new Error("精选案例包缺少有效校验值");
- const actual = await sha256Hex(blob);
+ const actual = await sha256Blob(blob);
if (actual !== expected) throw new Error("精选案例包校验失败,文件可能损坏或被替换");
return true;
}
diff --git a/extension/curated-download.js b/extension/curated-download.js
index f43b2b8..b4f2fa9 100644
--- a/extension/curated-download.js
+++ b/extension/curated-download.js
@@ -18,31 +18,26 @@ export async function readResponseBlobWithProgress(response, { onProgress = () =
const contentType = response.headers.get("content-type") || "application/octet-stream";
const declaredSize = Number(response.headers.get("content-length"));
const total = Number.isSafeInteger(declaredSize) && declaredSize > 0 ? declaredSize : 0;
- if (!response.body?.getReader) {
+ if (!response.body?.pipeThrough) {
const blob = await response.blob();
onProgress({ loaded: blob.size, total, ratio: total ? Math.min(1, blob.size / total) : null });
return blob;
}
- const chunks = total ? null : [];
- const bytes = total ? new Uint8Array(total) : null;
- const reader = response.body.getReader();
let loaded = 0;
- while (true) {
- const { done, value } = await reader.read();
- if (done) break;
- if (!value?.byteLength) continue;
- if (total) {
- if (loaded + value.byteLength > total) throw new Error("精选案例包下载大小与响应不一致");
- bytes.set(value, loaded);
- } else {
- chunks.push(value);
+ const stream = response.body.pipeThrough(new TransformStream({
+ transform(value, controller) {
+ if (!value?.byteLength) return;
+ loaded += value.byteLength;
+ if (total && loaded > total) throw new Error("精选案例包下载大小与响应不一致");
+ controller.enqueue(value);
+ onProgress({ loaded, total, ratio: total ? Math.min(1, loaded / total) : null });
+ },
+ flush() {
+ if (total && loaded !== total) throw new Error("精选案例包下载不完整");
}
- loaded += value.byteLength;
- onProgress({ loaded, total, ratio: total ? Math.min(1, loaded / total) : null });
- }
- if (total && loaded !== total) throw new Error("精选案例包下载不完整");
- return new Blob(total ? [bytes] : chunks, { type: contentType });
+ }));
+ return new Response(stream, { headers: { "content-type": contentType } }).blob();
}
function isTransientStatus(status) {
diff --git a/extension/curated-page.js b/extension/curated-page.js
index dd270a3..bd4f7bd 100644
--- a/extension/curated-page.js
+++ b/extension/curated-page.js
@@ -565,9 +565,8 @@ async function loadVerifiedArchive(item, onProgress = () => undefined) {
const archive = await readResponseBlobWithProgress(response, {
onProgress: (progress) => emitProgress(item.id, { stage: "downloading", ...progress })
});
- if (archive.size !== item.archiveBytes) throw new Error("精选案例包下载大小与目录不一致");
emitProgress(item.id, { stage: "verifying" });
- await verifyCuratedPackageBlob(archive, item.sha256);
+ await verifyCuratedPackageBlob(archive, item.sha256, item.archiveBytes);
return archive;
})().catch((error) => {
archivePromises.delete(item.id);
diff --git a/extension/manifest.json b/extension/manifest.json
index febb52d..190949d 100644
--- a/extension/manifest.json
+++ b/extension/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "__MSG_extensionName__",
- "version": "1.24.0",
+ "version": "1.24.1",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAq2m8W9ACXJTkJqPAd36sPrtzonmHhOYU34uS7c+D7DXX6ggWNMwB4xZapGFJ4ScBQJv71PeG9KfsEnhcXFZ9RoX/X3wY+57evL19hf6woNX1xxhKOe1rtx5QmzWCEYIr99TzW50k/N9U6tS9Ri+2DHKYA85ssXTC8B2yRQ5zUXhsAWZe/HDU18UFuvUKXYt3ZdIUi31c2vIlgFFBfsyKbIUMny9LlxL/smb4vJzU/+A3LwJDjjvOtS/lmQ2vHoQGjHJItO18bYI6h67fIEvmWk+HJKtO08Ca+5RLS8TYhI+K7l7S0RyDVNujyVWtvhAULot1H0BvteYL87fKu3SNywIDAQAB",
"homepage_url": "https://github.com/wchao6891/PromptDirector",
"default_locale": "zh_CN",
diff --git a/package-lock.json b/package-lock.json
index c9c5620..147e5de 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "prompt-case-collector",
- "version": "1.24.0",
+ "version": "1.24.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "prompt-case-collector",
- "version": "1.24.0",
+ "version": "1.24.1",
"license": "Apache-2.0",
"dependencies": {
"@jonahschulte/rtf-toolkit": "0.5.0",
diff --git a/package.json b/package.json
index b00b528..0ab2247 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "prompt-case-collector",
- "version": "1.24.0",
+ "version": "1.24.1",
"private": false,
"license": "Apache-2.0",
"repository": "https://github.com/wchao6891/PromptDirector",
diff --git a/store/DISTRIBUTION.md b/store/DISTRIBUTION.md
index 2c7606a..01b806c 100644
--- a/store/DISTRIBUTION.md
+++ b/store/DISTRIBUTION.md
@@ -6,7 +6,7 @@ Public distribution formats and the permissions used by PromptDirector.
- Chrome Web Store item public key: stored in the source `manifest.json` for local identity verification only; `package:release` removes `key` from the upload manifest.
- Expected extension ID: `iahakaahijddcjjldidbclicedibgpjm`.
-- Current upload artifact: `dist/store/PromptDirector-1.24.0-Chrome-Web-Store.zip`. Keep this artifact local for Web Store submission. The sole GitHub extension installation package is `PromptDirector-1.24.0.zip`, with stable identity and the local updater.
+- Current upload artifact: `dist/store/PromptDirector-1.24.1-Chrome-Web-Store.zip`. Keep this artifact local for Web Store submission. The sole GitHub extension installation package is `PromptDirector-1.24.1.zip`, with stable identity and the local updater.
- Generate a candidate only with `npm run package:release`; the command verifies the source public key against the expected identity, then removes `key` from the Web Store upload manifest and excludes the local program installer.
## Store listing
diff --git a/test/curated-catalog.test.js b/test/curated-catalog.test.js
index 11769d5..cd35e1e 100644
--- a/test/curated-catalog.test.js
+++ b/test/curated-catalog.test.js
@@ -1,5 +1,6 @@
import test from "node:test";
import assert from "node:assert/strict";
+import { createHash } from "node:crypto";
import {
applyCuratedOrigin,
@@ -11,9 +12,24 @@ import {
prepareCuratedEntryPackage,
prepareCuratedPackageVersion,
validateCuratedPackageContents,
- validateCuratedPackageIndex
+ validateCuratedPackageIndex,
+ verifyCuratedPackageBlob
} from "../extension/curated-catalog.js";
+test("a curated archive above 128 MiB still requires its catalog size and SHA-256", async () => {
+ const chunk = new Uint8Array(1024 * 1024);
+ const parts = Array(128).fill(chunk);
+ parts.push(new Uint8Array([1]));
+ const archive = new Blob(parts);
+ const hash = createHash("sha256");
+ for (const part of parts) hash.update(part);
+ const digest = hash.digest("hex");
+
+ assert.equal(await verifyCuratedPackageBlob(archive, digest, archive.size), true);
+ await assert.rejects(verifyCuratedPackageBlob(archive, digest, archive.size - 1), /大小与目录不一致/);
+ await assert.rejects(verifyCuratedPackageBlob(new Blob([new Uint8Array(22)]), digest, 22), /校验失败/);
+});
+
function catalogItem(overrides = {}) {
return {
id: "feature:cinematic",
diff --git a/test/curated-navigation.test.js b/test/curated-navigation.test.js
index 78bbbb5..0f17a10 100644
--- a/test/curated-navigation.test.js
+++ b/test/curated-navigation.test.js
@@ -95,7 +95,7 @@ test("preview prompts stay inert and package bytes are verified before curated i
assert.match(page, /copyCasePrompt\(entry, copy\)/);
assert.doesNotMatch(page, /innerHTML|insertAdjacentHTML|eval\(|new Function/);
const verifiedArchive = page.slice(page.indexOf("async function loadVerifiedArchive"), page.indexOf("async function loadPackageIndex"));
- assert.match(verifiedArchive, /verifyCuratedPackageBlob\(archive, item\.sha256\)/);
+ assert.match(verifiedArchive, /verifyCuratedPackageBlob\(archive, item\.sha256, item\.archiveBytes\)/);
const save = page.slice(page.indexOf("async function savePreviewCase"), page.indexOf("function openSavedCase"));
assert.match(save, /saveCuratedSelection\(item, \[previewEntry\.id\]/);
assert.match(save, /prepareCuratedEntriesPackage/);
diff --git a/test/local_upgrade_native_e2e.py b/test/local_upgrade_native_e2e.py
index 1d2a10b..b7cdc9c 100644
--- a/test/local_upgrade_native_e2e.py
+++ b/test/local_upgrade_native_e2e.py
@@ -101,8 +101,10 @@ def main():
button = page.get_by_role("button", name="选择安装文件夹并升级", exact=True)
expect(button).to_be_visible(timeout=60_000)
button.click()
- deadline = time.monotonic() + 240
+ started = time.monotonic()
+ deadline = started + 240
last_progress = ""
+ progress_updates = 0
while not page.is_closed() and time.monotonic() < deadline:
try:
status = page.locator(".app-dialog-status")
@@ -110,6 +112,12 @@ def main():
progress = status.inner_text()
if progress != last_progress and ("error" in (status.get_attribute("class") or "")):
raise AssertionError(progress)
+ if progress != last_progress:
+ # Hundreds of verified disk writes can be slower on
+ # hosted Windows. Fail on stalled work, while still
+ # requiring the actual reload and data proof below.
+ deadline = time.monotonic() + 240
+ progress_updates += 1
last_progress = progress
page.wait_for_timeout(200)
except Exception:
@@ -117,7 +125,7 @@ def main():
# established below from a new page and the reloaded extension.
if not page.is_closed():
raise
- assert page.is_closed(), f"Updater did not reload: {last_progress}"
+ assert page.is_closed(), f"Updater stopped progressing before reload: {last_progress} ({progress_updates} progress updates)"
check = context.new_page()
check.goto("chrome://extensions")
check.wait_for_function("""async ({id,version}) =>
@@ -164,7 +172,8 @@ def main():
assert directory_proof["reused"] and directory_proof["name"] == installed.name, directory_proof
print(json.dumps({"native_in_place_upgrade": "passed", "previous": previous["version"], "current": target["version"],
"case_media_identity_retained": True, "installation_directory_reused": True,
- "permission": "preauthorized isolated profile"}), flush=True)
+ "permission": "preauthorized isolated profile", "progress_updates": progress_updates,
+ "upgrade_seconds": round(time.monotonic() - started, 1)}), flush=True)
except Exception:
for candidate in context.pages:
if candidate.url.startswith(f"chrome-extension://{extension_id}/"):
diff --git a/test/projects_and_categories_e2e.py b/test/projects_and_categories_e2e.py
index 2601f58..3af2cf8 100644
--- a/test/projects_and_categories_e2e.py
+++ b/test/projects_and_categories_e2e.py
@@ -97,7 +97,13 @@ def main() -> None:
library.locator(".project-row", has_text="项目与分类验收").focus()
dialog = move_dialog(library, project_id, "辅助项目", "辅助项目")
dialog.get_by_role("button", name="移动", exact=True).click()
- library.locator('.project-row[data-collection-id="collection:e2e-extra"] .project-disclosure').click()
+ parent_row = library.locator('.project-row[data-collection-id="collection:e2e-extra"]')
+ # The move response adds the child asynchronously. Wait for that tree
+ # state before expanding it; a placeholder click can race the render.
+ expect(parent_row).to_have_attribute("aria-expanded", re.compile(r"^(true|false)$"))
+ if parent_row.get_attribute("aria-expanded") == "false":
+ parent_row.locator(".project-disclosure").click()
+ expect(parent_row).to_have_attribute("aria-expanded", "true")
expect(library.locator(".project-row", has_text="项目与分类验收")).to_have_attribute("aria-level", "2")
expect(library.locator(".project-row.project-draggable")).to_have_count(2)
expect(library.locator(".project-row > .project-menu:visible")).to_have_count(2)