diff --git a/CHANGELOG.md b/CHANGELOG.md index b70963a..9870f72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,20 @@ > 3. 核验正式地址版本 → 之后才移动 `stable` / `stable-verified-<日期>` 标签、更新本 CHANGELOG、写 GitHub Release(`gh release create`)。 > 测试发现问题 → 改 → 再 `deploy:test`,正式环境不受影响。回滚点 `git reset --hard stable`。 +## v3.25.15(2026-11-18)彻底转桌面客户端:删除网页版部署面 + +### 变更 +- **删除网页版部署产物**:`_headers`、`functions/`(`api/img.js`、`plugins/[[path]].js`)、`wrangler.toml`, + 以及只测它们的 `tests/iwb-csp-gate.spec.js`、`tests/iwb-functions-headers.spec.js`、`tests/functions-api-test.js`、`tests/iwb-v32-web-test.js`。 +- **`scripts/serve-test.js` 退化为纯静态服务器**:不再解析 `_headers`、不再模拟 Pages Functions。 +- **`app.js` 清除网页代理分支**:图床下载 ③ 兜底、缩略图兜底、预览派生 `viaUrl`、显示缩略图 4 处 `/api/img` 全部删除,桌面端只走原生 HTTP。 +- **更新清单平台解耦**:`tauri.windows.conf.json` 的 updater 指向 `updates/latest-windows.json`; + `publish-windows-update.sh` 改写独立清单,mac 发版不再丢弃 Windows 条目。 +- **README / docs/RELEASES.md** 改为桌面客户端口径。 + +### 说明 +- Windows 客户端 **需要在 3.25.15 手动装一次**(旧版的 updater 仍指向 `latest.json`),之后自动更新走独立清单。 + ## v3.25.14(2026-11-18)桌面 CSP 回归修复(鲜艺抠图)+ 外观 tab ### 修复 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9669665..f4174ef 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ build esbuild 打包到 dist/(单 dist/app.js = src/ 模块按序 node --check app.js 与 dist/app.js 语法 check-dist.js 产物体检 lint ESLint(src/ + app.js,正确性规则) -test:unit 103 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底)) +test:unit 101 个单测文件(jsdom 契约测试;2026-11-07 新增 sync-facts-guard(事实一致性)/ _helpers/source(统一源文本);2026-11-12 新增 provider-ping(测速 no-cors 兜底)) test relay-task-graph-fixture + iwb-v32-web-test test:facts 事实基线守门(见 §5) typecheck 渐进类型检查(tsc --noEmit;范围 = src/*.js,不含 app.js) diff --git a/README.md b/README.md index a5f2375..1075461 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ -# 🎨 生图工作台 Web 版(Cloudflare Pages 免费部署) +# 🎨 生图工作台(桌面客户端) -**在线访问:https://iwb.maqiart.eu.org**(自定义域名,Cloudflare 免费 HTTPS) - - -基于 **OpenAI 兼容生图 API** 的节点式图形化生图工作台,纯前端实现(Cloudflare Pages 免费托管)。 +基于 **OpenAI 兼容生图 API** 的节点式图形化生图工作台。**Tauri v2 桌面客户端**(macOS / Windows),数据全部落在本机资料目录。 - **零后端**:数据保存在浏览器(localStorage + IndexedDB),图片生成直连兼容 API;Tuzi 生图固定使用 generations、要求 URL 响应,参考图允许公网 URL 与本地 Base64,且不自动重试 - 与独立版功能一致:无限画布、节点连线、文生图/图生图、参数设置(比例/分辨率对齐接口)、提示词库、节点组收藏、图库、右键菜单、双击聚焦/适应视图、标注节点等 @@ -13,7 +10,7 @@ - 稳定性边界:保存失败会保留恢复快照并支持重试,离页前执行本地兜底;启动时检查 localStorage/IndexedDB 可用性并显示异常。 - 构建:`npm run build` 用 **esbuild 压缩打包**(单 `dist/app.js` = `src/` 模块按序拼接 + `app.js`,另有压缩 `style.css`;`dist/` 不再有 `src/`),并生成带 Git commit 元数据的 `dist/version.json`。 - 测试:`npm test` 运行 jsdom 契约测试,`npm run test:e2e` 构建后启动本地静态服务器并运行 Playwright Chromium 测试;`npm run verify` 执行完整验证。 -- 发布:`npm run deploy` 仅在完整验证通过后,将 `dist/` 上传到 Cloudflare Pages。 +- 发布:`./scripts/publish-update.sh <版本>` 构建 macOS 双架构并写更新清单;Windows 用 `./scripts/publish-windows-update.sh ` 重签并写独立清单(`latest-windows.json`)。 ## 第三方许可 @@ -29,27 +26,24 @@ **想知道「这个项目还有什么待办」** → [`BACKLOG.md`](BACKLOG.md)(唯一入口:优先级 + 证据链接 + 明确不做的项)。 -## 部署到 Cloudflare Pages(免费) +## 构建与发布(桌面客户端) -### 本地手动发布(本仓库方式) +> 已从网页版迁移为桌面客户端,**不再部署 Cloudflare Pages**(`_headers` / `functions/` / `wrangler.toml` 已删除)。 ```bash npm ci -npm run deploy # 正式站(--branch main) -npm run deploy:test # 测试站(--branch test) +npm run build # 前端产物 dist/(esbuild 压缩) +npx tauri build # 桌面安装包(macOS: .app + dmg / Windows: nsis) ``` -`npm run deploy` 会先跑完整 `verify`,通过后再把 `dist/` 上传到 Cloudflare Pages。 +| 平台 | 命令 | 产物 | +| --- | --- | --- | +| macOS | `./scripts/publish-update.sh <版本>` | `updates/latest.json` + 双架构 dmg / app.tar.gz | +| Windows | `./scripts/publish-windows-update.sh ` | `updates/latest-windows.json`(平台独立) | -### CI(只验证,不部署) +两个平台的更新清单**完全解耦**:mac 发版不影响 Windows 版本号,反之亦然。 -`.github/workflows/verify.yml` 在**推送到 `main` 与向 `main` 开 PR** 时执行验证门禁,分两个 job:`gate`(`npm ci` + `npm run verify:ci` = 构建 + 校验 + lint + 单测 + 事实守卫)与 `e2e`(Playwright + `npm run test:e2e`),**不自动部署**。 - -发布配置位于 `wrangler.toml`,Cloudflare Pages 输出目录固定为 `dist/`。部署前生成的 `version.json` 可用于确认线上版本和 Git commit。 - -### 绑定自定义域名(可选) - -Pages 项目 → **Custom domains** → 添加域名(免费 HTTPS 自动签发)。 +CI:`.github/workflows/verify.yml` 在推送 `main` 与向 `main` 开 PR 时执行 `npm run verify:ci`。 ## 使用前配置 diff --git a/_headers b/_headers deleted file mode 100644 index 23c62d7..0000000 --- a/_headers +++ /dev/null @@ -1,9 +0,0 @@ -/* - X-Content-Type-Options: nosniff - Referrer-Policy: no-referrer - Permissions-Policy: camera=(), microphone=(), geolocation=() - Content-Security-Policy: default-src 'self'; script-src 'self'; worker-src 'self' blob:; style-src 'self' 'unsafe-inline'; img-src 'self' https: data: blob:; connect-src 'self' https: http://127.0.0.1:30092 http://localhost:30092 http://127.0.0.1:3425 http://localhost:3425; object-src 'none'; base-uri 'none'; frame-ancestors 'none' - -/sw.js - Cache-Control: no-cache, no-store, must-revalidate - Service-Worker-Allowed: / diff --git a/app.js b/app.js index 32d2818..61fb89c 100644 --- a/app.js +++ b/app.js @@ -1817,10 +1817,9 @@ if (fkEarly && /^https:/i.test(fkEarly) && !wThumbProxyTried.has(fkEarly)) { wThumbProxyTried.add(fkEarly) try { - // 桌面端没有 /api/img 代理(无服务端)⇒ 用 plugin-http 直取字节(Rust 侧请求,不受 CORS 限制) - const pr = wIsTauri() - ? await wTauri.http.fetch(fkEarly) - : await fetch('/api/img?url=' + encodeURIComponent(fkEarly), { mode: 'cors' }) + // 桌面客户端:用 plugin-http 直取字节(Rust 侧请求,不受 CORS 限制) + if (!wIsTauri()) { if (fkEarly) wThumbFail.add(fkEarly); return null } + const pr = await wTauri.http.fetch(fkEarly) // v3.87.52(丙方案 C5):交给 wRegisterBlobUrl(入参是 Blob,内部创建并登记 objectURL), // 避免此前的"创建了 blob URL 却不登记、不回收"✗ if (pr.ok) return storeOutputThumb(Object.assign({}, item, { url: wRegisterBlobUrl(await pr.blob()) })) @@ -4362,13 +4361,13 @@ } } } catch (e) { /* 继续兜底 */ } - // ③ **本站同源代理**兜底(functions/api/img.js;跨域图床专用。不经任何第三方) + // ③ 原生 HTTP 兜底(Rust 侧请求,不受 CORS 限制) + // 本项目是桌面客户端,没有服务端同源代理(旧的 functions/api/img.js 已随网页版删除) try { - // 桌面端没有同源代理:改用 plugin-http 直连(Rust 侧请求,不受 CORS 限制) - const r2 = wIsTauri() - ? await wTauri.http.fetch(su) - : await fetch('/api/img?url=' + encodeURIComponent(su), { mode: 'cors' }) - if (r2.ok) { downloadBlob(await r2.blob()); wDownloadToast(wIsTauri() ? '已通过原生 HTTP 取图保存' : '该图床不支持直连下载,已通过本站代理保存'); return } + if (wIsTauri()) { + const r2 = await wTauri.http.fetch(su) + if (r2.ok) { downloadBlob(await r2.blob()); wDownloadToast('已通过原生 HTTP 取图保存'); return } + } } catch (e) { /* 继续兜底 */ } // ④ 最后兜底:新标签打开(右键/长按另存)——绝不静默失败 try { @@ -4679,10 +4678,9 @@ const tbCenterSeed = (type, refs) => { const Derive = (typeof window !== 'undefined') ? window.IWBImagePreviewDerive : null if (!Derive || typeof Derive.create !== 'function' || typeof document === 'undefined') return v previewPending.add(key) - // 跨域图必须走同源代理(否则 fetch 必失败 ⇒ 负缓存后等于没做 ✗,见 §8.3 坑 2) - // 桌面端没有 /api/img 代理:不给 viaUrl,让派生器直连(失败即负缓存并回退原图,不影响显示) - const viaUrl = (/^https?:\/\//i.test(v) && (typeof location === 'undefined' || v.indexOf(location.origin + '/') !== 0) && !wIsTauri()) - ? (location.origin + '/api/img?url=' + encodeURIComponent(v)) : undefined + // 桌面客户端没有同源代理(旧的 functions/api/img.js 已随网页版删除)⇒ 派生器直连; + // 跨域失败即负缓存并回退原图,不影响显示。 + const viaUrl = undefined let inst = null try { inst = Derive.create({ maxEdge: PREVIEW_MAX_EDGE, quality: 0.82 }) } catch (e) { inst = null } if (!inst || typeof inst.deriveUrl !== 'function') { previewPending.delete(key); wPreviewPick(key, v); return v } @@ -4763,10 +4761,8 @@ const tbCenterSeed = (type, refs) => { if (displayThumbs.size >= DISPLAY_THUMB_CACHE_MAX) { const first = displayThumbs.keys().next().value; if (first !== undefined) displayThumbs.delete(first) } displayThumbs.set(key, val) } - const isRemoteHttp = /^https?:\/\//i.test(v) && (typeof location === 'undefined' || v.indexOf(location.origin + '/') !== 0) - // 桌面端没有代理:直接给原地址( 不受 CORS 限制,能正常显示;canvas 降采样失败会回退原图) - img.src = (isRemoteHttp && wIsTauri()) ? v - : (isRemoteHttp ? (location.origin + '/api/img?url=' + encodeURIComponent(v)) : v) + // 桌面客户端没有同源代理:直接给原地址( 不受 CORS 限制,能正常显示;canvas 降采样失败会回退原图) + img.src = v img.onload = () => { try { const iw = img.naturalWidth || 0, ih = img.naturalHeight || 0 diff --git a/docs/RELEASES.md b/docs/RELEASES.md index 8bb3b1b..e8b8273 100644 --- a/docs/RELEASES.md +++ b/docs/RELEASES.md @@ -278,7 +278,7 @@ npm run deploy # 部署到正式站 IWB_VERIFY_STRICT=1 node scripts/verify-release.js ``` -> ⚠️ `npm run deploy` = `verify` + `wrangler pages deploy`,**不含 git push**。 +> ⚠️ 本项目已转桌面客户端:**不再用 `wrangler pages deploy`**,发版走 `./scripts/publish-update.sh`(macOS)/ `./scripts/publish-windows-update.sh`(Windows)。 > 回滚时**不要**把旧代码 push 到 main(会污染历史);用 `checkout` 部署即可, > 部署完 `git checkout main` 回到主干。 @@ -408,7 +408,7 @@ git checkout refactor-step-3 git checkout stable-v3.24.5 && npm ci && npm run verify:ci && npm run deploy # 层 4:看部署历史,用 dashboard 或 API 切回旧 deployment -npx wrangler pages deployment list --project-name image-workbench-web +# 桌面端没有「线上部署列表」:版本清单在 NAS 的 /vol8/web/iwb-download/updates/ ``` ### 7.2 铁律 diff --git a/docs/standards/architecture-current-state.md b/docs/standards/architecture-current-state.md index f6460b0..36b1628 100644 --- a/docs/standards/architecture-current-state.md +++ b/docs/standards/architecture-current-state.md @@ -31,7 +31,7 @@ |---|---|---| | 单测基线 | **658 通过 / 0 新增失败 / 2 已知环境差异**(2026-11-12 v3.24.76 实测;660 −2 = 94-5~7 三条钉点换成一条消费方契约) | (A) `npm test` 实测(`tests/iwb-v32-web-test.js`) | | e2e | spec 文件 **59** 个(**55** 个进门禁 + 4 个 dev 探针 `_perf-baseline` / `_plugin-host-probe` / `_probe-drag` / `_probe-tab-switch`) | (A) `tests/` 计数 + `scripts/list-e2e-specs.js` | -| e2e 用例数 | **200 条**(2026-11-16 实测:55 个进门禁 spec 内 `test()` 总数)(历史:115 → v3.24.18 **143** → v3.24.19 **147** → v3.24.21 **151** → F2 改名 1 条 **152** → 抓手工具 2 条 **154** → v3.24.44 输出顺序 2 条 **166** → v3.24.47 同步去重 `iwb-sync-dedupe` 1 条 **167** → v3.24.67 **179** → v3.24.68 **183** → v3.24.69 **184** → v3.24.70 **186** → v3.24.74 **187**(新增「拖入 PDF 给提示 + MIME 空 PNG 仍能导入」)→ v3.24.75 **188**(新增「同一张图连粘两次只建一个节点」)→ v3.24.76 **191**(新增 `iwb-tabs-release` 3 条:回首页不降级 / 关标签先保存再关 / 彻底删除连带关标签)→ v3.24.77 **194**(新增 `iwb-lod` 3 条:fit 大画布必须全 LOD / 放大后必须恢复 / 常规画布不 LOD)→ v3.24.78 **196**(`iwb-lod` 3 → 5 条:新增「lite 档必须画出代表图/首行文字」与「缩到 15% 以下才退成 plain」)→ v3.24.82 **197**(新增 `iwb-inherit-text` 1 条:提示词/文本节点显示上游继承文本、改字接管、恢复跟随)→ v3.24.83 **198**(新增 `iwb-plugin-node-coldstart` 1 条:插件脚本晚到 1.2s,存档里的插件节点必须自动切回插件节点体,且类型不被降级成 `plugin`)→ v3.24.79 **196 不变**(测速修复的守门落在 jsdom 单测 `provider-ping-test.js`,e2e 无新增)→ v3.24.85 **200**(新增 `iwb-multi-tab` 2 条:A 页 flush 落盘后 B 页必须靠 rev 轮询看到改动;B 页持锁期间 A 页图库归档必须挂起);早期 99 → 115 的逐版链条见 `docs/history/coverage-baseline-2026-10-27.md`) | (A) `tests/*.spec.js` 计数 + `scripts/list-e2e-specs.js` | +| e2e 用例数 | **200 条**(2026-11-16 实测:55 个进门禁 spec 内 `test()` 总数;v3.25.15 删除网页版部署面后为 **53** 个进门禁 —— `iwb-csp-gate` / `iwb-functions-headers` 随 `_headers`、`functions/` 一起移除)(历史:115 → v3.24.18 **143** → v3.24.19 **147** → v3.24.21 **151** → F2 改名 1 条 **152** → 抓手工具 2 条 **154** → v3.24.44 输出顺序 2 条 **166** → v3.24.47 同步去重 `iwb-sync-dedupe` 1 条 **167** → v3.24.67 **179** → v3.24.68 **183** → v3.24.69 **184** → v3.24.70 **186** → v3.24.74 **187**(新增「拖入 PDF 给提示 + MIME 空 PNG 仍能导入」)→ v3.24.75 **188**(新增「同一张图连粘两次只建一个节点」)→ v3.24.76 **191**(新增 `iwb-tabs-release` 3 条:回首页不降级 / 关标签先保存再关 / 彻底删除连带关标签)→ v3.24.77 **194**(新增 `iwb-lod` 3 条:fit 大画布必须全 LOD / 放大后必须恢复 / 常规画布不 LOD)→ v3.24.78 **196**(`iwb-lod` 3 → 5 条:新增「lite 档必须画出代表图/首行文字」与「缩到 15% 以下才退成 plain」)→ v3.24.82 **197**(新增 `iwb-inherit-text` 1 条:提示词/文本节点显示上游继承文本、改字接管、恢复跟随)→ v3.24.83 **198**(新增 `iwb-plugin-node-coldstart` 1 条:插件脚本晚到 1.2s,存档里的插件节点必须自动切回插件节点体,且类型不被降级成 `plugin`)→ v3.24.79 **196 不变**(测速修复的守门落在 jsdom 单测 `provider-ping-test.js`,e2e 无新增)→ v3.24.85 **200**(新增 `iwb-multi-tab` 2 条:A 页 flush 落盘后 B 页必须靠 rev 轮询看到改动;B 页持锁期间 A 页图库归档必须挂起);早期 99 → 115 的逐版链条见 `docs/history/coverage-baseline-2026-10-27.md`) | (A) `tests/*.spec.js` 计数 + `scripts/list-e2e-specs.js` | | CI | `.github/workflows/verify.yml`:**push(main) + PR(→main) + 手动** 触发,两个 job(`gate` = `verify:ci`;`e2e` = `test:e2e`),只验证不部署 | (A) | | 部署 | `npm run deploy` = `verify` + `wrangler pages deploy dist --branch main`;**内含全量 verify,不得绕过** | (A) `package.json:16` | | 部署环境 | 本机 wrangler 为 OAuth 登录 → **不能设 `CI=true`**(用 `unset CI` + `WRANGLER_SEND_METRICS=false`) | (A) 本轮发布实测 | diff --git a/functions/api/img.js b/functions/api/img.js deleted file mode 100644 index 2766c1a..0000000 --- a/functions/api/img.js +++ /dev/null @@ -1,108 +0,0 @@ -// Cloudflare Pages Function:**第一方**图片代理(同源 /api/img)。 -// 目的:豆包(火山 TOS)等图床**不返回 CORS 头**,浏览器无法 fetch ⇒ 下载、缩略图归档、 -// 本地原图备份全部拿不到字节。经本站代理转发后由本站给出 CORS 头,前端即可正常读取。 -// 用法:GET /api/img?url= -// -// 安全边界(H2 加固): -// - 仅接受**同源**调用:若请求带 Origin 头,其 host 必须与本站一致。 -// - 仅 https、仅允许常见图片/对象存储域名(避免成为开放代理/SSRF),仅透传 image/* 响应。 -// - **手动跟随重定向**:每一跳都对目标 host 重新做白名单校验(原实现 redirect:'follow' 只校验初始 -// host,可被 302 逃逸到任意主机),并限制跳数。 -// - **响应大小上限**:先看 content-length,超限即拒;无 content-length 时按流裁剪(防超大响应耗尽配额)。 -// - 不再返回 Access-Control-Allow-Origin: *(同源调用本就不需要 CORS)。 -export function onRequest(context) { - return handle(context.request) -} - -const ALLOW_HOSTS = [ - /(^|\.)volces\.com$/i, // 火山引擎 / TOS(豆包 Seedream 图床) - /(^|\.)aliyuncs\.com$/i, // 阿里云 OSS(tuzi 文档示例图床) - /(^|\.)myqcloud\.com$/i, // 腾讯云 COS - /(^|\.)qiniucdn\.com$/i, - /(^|\.)cloudfront\.net$/i, - /(^|\.)googleusercontent\.com$/i, - /(^|\.)openai\.org$/i, - /(^|\.)oaistatic\.com$/i, - /(^|\.)blob\.core\.windows\.net$/i, -] -const MAX_BYTES = 25 * 1024 * 1024 // 单张图片上限 25MB(生成图远小于此;防超大响应) -const MAX_REDIRECTS = 3 - -// 安全头(2026-10-20 加,H1):Cloudflare Pages 的 `_headers` **不作用于 Functions 响应** -// (https://developers.cloudflare.com/pages/configuration/headers/)⇒ 静态资源有 CSP/nosniff, -// 而本函数(及 plugins 函数)原本**一个安全头都没有**。这不是可利用漏洞(每个响应都显式 -// 设了 Content-Type),但属于纵深防御缺口:将来若有端点返回用户影响的内容且漏设 Content-Type, -// 浏览器会自行嗅探类型 ⇒ 可能演变成 XSS。故在**每个** Response 显式补齐 nosniff + Referrer-Policy。 -const SECURITY_HEADERS = { - 'X-Content-Type-Options': 'nosniff', - 'Referrer-Policy': 'no-referrer', -} - -function hdr() { - return Object.assign({ 'Content-Type': 'text/plain; charset=utf-8' }, SECURITY_HEADERS) -} -function plain(msg, status) { - return new Response(msg, { status, headers: hdr() }) -} -function sameOrigin(request) { - const origin = request.headers.get('Origin') - if (!origin || origin === 'null') return true - try { return new URL(origin).host === new URL(request.url).host } catch (e) { return false } -} -function hostAllowed(u) { - return ALLOW_HOSTS.some((re) => re.test(u.hostname)) -} -function capStream(stream, max) { - let seen = 0 - return stream.pipeThrough(new TransformStream({ - transform(chunk, controller) { - seen += chunk && chunk.byteLength ? chunk.byteLength : 0 - if (seen > max) { controller.error(new Error('response too large')); return } - controller.enqueue(chunk) - }, - })) -} - -async function handle(request) { - if (request.method === 'OPTIONS') return new Response(null, { status: 204, headers: hdr() }) - if (request.method !== 'GET') return plain('仅支持 GET', 405) - if (!sameOrigin(request)) return plain('仅允许同源调用', 403) - let target - try { - const raw = String(new URL(request.url).searchParams.get('url') || '') - target = new URL(raw) - } catch (e) { return plain('缺少或非法的 url 参数', 400) } - if (target.protocol !== 'https:') return plain('仅支持 https 图片地址', 400) - if (!hostAllowed(target)) return plain('该图床未在允许列表中:' + target.hostname, 403) - try { - // 手动跟随重定向:每一跳都对 host 重新校验,逃逸即拒。 - let upstream = null - for (let hop = 0; hop <= MAX_REDIRECTS; hop++) { - upstream = await fetch(target.toString(), { headers: { Accept: 'image/*' }, redirect: 'manual' }) - const status = upstream.status - const isRedirect = status >= 300 && status < 400 - if (!isRedirect) break - const location = upstream.headers.get('Location') - if (!location) return plain('上游重定向缺少 Location', 502) - if (hop === MAX_REDIRECTS) return plain('重定向次数过多', 508) - let next - try { next = new URL(location, target) } catch (e) { return plain('上游重定向地址非法', 502) } - if (next.protocol !== 'https:') return plain('重定向目标非 https', 403) - if (!hostAllowed(next)) return plain('重定向目标未在允许列表中:' + next.hostname, 403) - target = next - } - if (!upstream || !upstream.ok) return plain('上游返回 ' + (upstream ? upstream.status : '0'), 502) - const ct = String(upstream.headers.get('content-type') || '') - if (ct && ct.toLowerCase().indexOf('image/') !== 0) return plain('上游不是图片(' + ct + ')', 415) - const len = Number(upstream.headers.get('content-length')) - if (Number.isFinite(len) && len > MAX_BYTES) return plain('图片过大(超过 ' + MAX_BYTES + ' 字节)', 413) - const headers = new Headers() - headers.set('Content-Type', ct || 'image/png') - headers.set('Cache-Control', 'private, max-age=600') - for (const [k, v] of Object.entries(SECURITY_HEADERS)) headers.set(k, v) - const body = upstream.body && !(Number.isFinite(len) && len <= MAX_BYTES) ? capStream(upstream.body, MAX_BYTES) : upstream.body - return new Response(body, { status: 200, headers }) - } catch (e) { - return plain('代理失败:' + ((e && e.message) || 'unknown'), 502) - } -} diff --git a/functions/plugins/[[path]].js b/functions/plugins/[[path]].js deleted file mode 100644 index e8403c7..0000000 --- a/functions/plugins/[[path]].js +++ /dev/null @@ -1,74 +0,0 @@ -// /plugins/* → 从 KV(binding: PLUGINS)以**同源**方式提供插件文件。 -// 同源脚本本就被页面 CSP(script-src 'self')允许 ⇒ 无需放宽 CSP、无需 unsafe-eval、无需重新部署 app.js。 -// KV 键约定:plugins/index.json(清单)+ plugins/(每个插件一个文件)。 -// -// 缓存策略(按 basename 分流): -// - plugin-..js(内容寻址,发布脚本生成)→ public, max-age=31536000, immutable(字节永不变 ⇒ 可永久缓存) -// - 其他 .js(历史遗留未哈希文件)→ no-cache + ETag(安全网:绝不许被永久缓存) -// - .json(清单)→ no-cache + ETag;if-none-match 命中 → 304 空 body -// - 其他扩展名 / 404 / 500 → no-store -// ETag 为 (value, basename) 的确定性纯函数:FNV-1a 32bit(同步、廉价),hex 后加双引号。 - -const JS_CT = 'application/javascript; charset=utf-8' -const JSON_CT = 'application/json; charset=utf-8' - -// 安全头(2026-10-20 加,H1):Cloudflare Pages 的 `_headers` **不作用于 Functions 响应** -// (https://developers.cloudflare.com/pages/configuration/headers/)⇒ 静态资源有 CSP/nosniff, -// 而本函数原本**一个安全头都没有**。插件字节虽同源且有 SRI 校验,但缺 nosniff 意味着 -// 万一将来 KV 里的内容类型异常,浏览器可能自行嗅探 ⇒ 补齐纵深防御。 -const SECURITY_HEADERS = { 'x-content-type-options': 'nosniff', 'referrer-policy': 'no-referrer' } - -const ERROR_HEADERS = Object.assign({ 'content-type': JSON_CT, 'cache-control': 'no-store' }, SECURITY_HEADERS) -const NO_STORE_HEADERS = Object.assign({ 'content-type': JS_CT, 'cache-control': 'no-store' }, SECURITY_HEADERS) - -const IMMUTABLE_JS_RE = /^plugin-[a-z0-9-]+\.[0-9a-f]{12}\.js$/ - -// FNV-1a 32-bit(对 UTF-16 code unit 序列):同步、确定、够用于 ETag 指纹 -const fnv1a32 = (s) => { - let h = 0x811c9dc5 - for (let i = 0; i < s.length; i++) { - h ^= s.charCodeAt(i) - h = Math.imul(h, 0x01000193) - } - return (h >>> 0).toString(16).padStart(8, '0') -} - -const etagOf = (value, base) => '"' + fnv1a32(base + '\n' + value) + '"' - -export async function onRequestGet(context) { - const { params, env } = context - const parts = Array.isArray(params.path) ? params.path : [params.path].filter(Boolean) - const tail = parts.join('/') || 'index.json' - const key = 'plugins/' + tail - const base = tail.slice(tail.lastIndexOf('/') + 1) - - if (!env || !env.PLUGINS) { - return new Response(JSON.stringify({ error: 'PLUGINS KV 未绑定' }), { status: 500, headers: ERROR_HEADERS }) - } - - const value = await env.PLUGINS.get(key) - if (value === null) return new Response('not found', { status: 404, headers: Object.assign({ 'cache-control': 'no-store' }, SECURITY_HEADERS) }) - - // A) 内容寻址的插件 JS:内容变 ⇒ 文件名变 ⇒ 可 immutable 永久缓存 - if (IMMUTABLE_JS_RE.test(base)) { - return new Response(value, { - headers: Object.assign({ 'content-type': JS_CT, 'cache-control': 'public, max-age=31536000, immutable' }, SECURITY_HEADERS), - }) - } - - // B) 未哈希 .js 与 .json(清单):no-cache + ETag,每次回源校验,命中即 304 - if (base.endsWith('.js') || base.endsWith('.json')) { - const etag = etagOf(value, base) - const headers = Object.assign({ - 'content-type': base.endsWith('.json') ? JSON_CT : JS_CT, - 'cache-control': 'no-cache', - etag, - }, SECURITY_HEADERS) - const inm = context.request && context.request.headers && context.request.headers.get('if-none-match') - if (inm === etag) return new Response(null, { status: 304, headers }) - return new Response(value, { headers }) - } - - // 其他扩展名:保持 no-store - return new Response(value, { headers: NO_STORE_HEADERS }) -} diff --git a/package.json b/package.json index c51ab79..a76b48a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "image-workbench-web", "private": true, - "version": "3.25.14", + "version": "3.25.15", "description": "Browser-based node canvas image workbench", "scripts": { "build": "node scripts/build.js && node scripts/copy-plugins.js", @@ -9,8 +9,8 @@ "app:dev": "tauri dev", "app:build": "tauri build", "lint": "eslint src app.js", - "test": "node tests/relay-task-graph-fixture-test.js && node tests/plugin-style-node-test.js && node tests/inherit-text-test.js && node tests/iwb-v32-web-test.js", - "test:unit": "node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/storage-config-shape-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/image-blob-store-test.js && node tests/image-preview-derive-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/ui-groups-sidebar-test.js && node tests/ui-lib-sidebar-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/functions-api-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/ui-workbench-hooks-test.js", + "test": "node tests/relay-task-graph-fixture-test.js && node tests/plugin-style-node-test.js && node tests/inherit-text-test.js", + "test:unit": "node tests/unit-test.js && node tests/canvas-actions-test.js && node tests/canvas-performance-test.js && node tests/canvas-drag-performance-test.js && node tests/resize-observer-performance-test.js && node tests/node-drag-jank-test.js && node tests/edge-graph-performance-test.js && node tests/persistence-export-images-test.js && node tests/settings-hotkeys-size-presets-test.js && node tests/custom-size-validation-test.js && node tests/image-node-performance-test.js && node tests/drag-frame-performance-test.js && node tests/canvas-edge-memo-test.js && node tests/canvas-node-transform-test.js && node tests/canvas-dot-zoom-test.js && node tests/duplicate-ws-fresh-source-test.js && node tests/single-canvas-shell-test.js && node tests/navigation-layout-test.js && node tests/home-canvas-library-test.js && node tests/left-resource-layout-test.js && node tests/interface-hierarchy-test.js && node tests/three-page-layout-test.js && node tests/page-chrome-regression-test.js && node tests/task-cache-test.js && node tests/storage-config-shape-test.js && node tests/storage-zip-test.js && node tests/canvas-node-factory-test.js && node tests/runtime-error-test.js && node tests/runtime-lifecycle-test.js && node tests/runtime-fetch-test.js && node tests/runtime-channel-test.js && node tests/runtime-boundary-test.js && node tests/runtime-record-test.js && node tests/runtime-recovery-test.js && node tests/runtime-diagnostic-record-test.js && node tests/runtime-metrics-test.js && node tests/runtime-run-context-test.js && node tests/runtime-execution-context-test.js && node tests/storage-gc-canvas-refs-test.js && node tests/storage-health-test.js && node tests/generation-state-test.js && node tests/canvas-store-test.js && node tests/storage-result-test.js && node tests/storage-local-test.js && node tests/storage-domain-test.js && node tests/storage-runtime-test.js && node tests/storage-indexeddb-test.js && node tests/generation-scheduler-test.js && node tests/gallery-query-test.js && node tests/gallery-hydration-test.js && node tests/image-blob-store-test.js && node tests/image-preview-derive-test.js && node tests/image-format-test.js && node tests/clipboard-graph-test.js && node tests/clipboard-graph-fallback-test.js && node tests/image-admit-test.js && node tests/image-dedupe-test.js && node tests/clipboard-kind-test.js && node tests/clipboard-paste-test.js && node tests/clipboard-copy-test.js && node tests/paste-once-test.js && node tests/list-e2e-specs-test.js && node tests/desktop-csp-loopback-test.js && node tests/architecture-boundary-guard-test.js && node tests/plugin-host-test.js && node tests/image-compress-test.js && node tests/storage-fallback-indexeddb-test.js && node tests/canvas-normalize-test.js && node tests/canvas-geometry-test.js && node tests/canvas-history-test.js && node tests/canvas-ops-test.js && node tests/canvas-text-test.js && node tests/history-store-test.js && node tests/plugin-integrity-test.js && node tests/workspace-sessions-store-test.js && node tests/workspace-list-test.js && node tests/workspace-purge-test.js && node tests/provider-ping-test.js && node tests/ui-groups-sidebar-test.js && node tests/ui-lib-sidebar-test.js && node tests/runtime-diagnostics-hotpath-test.js && node tests/storage-log-failure-test.js && node tests/storage-convergence-test.js && node tests/swallow-wiring-test.js && node tests/workbench-logic-test.js && node tests/storage-autobackup-test.js && node tests/storage-outputs-mutate-test.js && node tests/sync-facts-guard-test.js && node tests/e2e-fixed-waits-ratchet-test.js && node tests/shell-render-behavior-test.js && node tests/canvas-meta-notice-behavior-test.js && node tests/source-text-ratchet-test.js && node tests/prompt-md-roundtrip-test.js && node tests/generation-results-store-test.js && node tests/out-groups-order-test.js && node tests/ui-workbench-hooks-test.js", "test:diagnostics": "node tests/runtime-diagnostics-hotpath-test.js", "test:facts": "node tests/architecture-facts-guard-test.js && node tests/release-records-test.js", "plugins:gc": "node scripts/plugins-publish.mjs --gc", @@ -20,8 +20,6 @@ "test:e2e:local": "node scripts/serve-test.js", "verify:ci": "npm run build && node --check app.js && node --check dist/app.js && node scripts/check-dist.js && npm run lint && npm run typecheck && npm run test:unit && npm test && npm run test:facts", "verify": "npm run verify:ci && npm run test:e2e", - "deploy": "npm run verify && npx --yes wrangler@4 pages deploy dist --project-name image-workbench-web --branch main", - "deploy:test": "npm run verify && npx --yes wrangler@4 pages deploy dist --project-name image-workbench-web --branch test", "verify:release": "node scripts/verify-release.js", "coverage:e2e": "node scripts/coverage-e2e.js", "sync:facts": "node scripts/sync-facts.js", diff --git a/scripts/build.js b/scripts/build.js index 7a745a1..5512626 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -170,7 +170,6 @@ const minifiedCss = transformSync(fs.readFileSync(path.join(root, 'style.css'), fs.writeFileSync(path.join(dist, 'style.css'), minifiedCss) fs.copyFileSync(path.join(root, 'favicon.svg'), path.join(dist, 'favicon.svg')) -fs.copyFileSync(path.join(root, '_headers'), path.join(dist, '_headers')) // PWA(2026-11-07):可安装 —— manifest + 图标(iOS 额外要 apple-touch-icon 的 PNG) for (const f of ['manifest.webmanifest', 'icon-192.png', 'icon-512.png', 'apple-touch-icon.png']) { fs.copyFileSync(path.join(root, f), path.join(dist, f)) diff --git a/scripts/publish-windows-update.sh b/scripts/publish-windows-update.sh index 2847435..15f6b0f 100755 --- a/scripts/publish-windows-update.sh +++ b/scripts/publish-windows-update.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash # 发布 Windows 更新:对 Windows 侧构建好的 *-setup.exe 重新签名(用本机正式私钥), -# 上传到 NAS,并把 windows-x86_64 条目合并进 updates/latest.json。 +# 上传到 NAS,并写入 **独立** 的 updates/latest-windows.json(v3.25.15 起平台解耦: +# mac 的 latest.json 与 Windows 的 latest-windows.json 互不影响)。 # # 用法:./scripts/publish-windows-update.sh "/path/to/image-workbench_3.25.3_x64-setup.exe" # @@ -38,27 +39,25 @@ echo "== 3/4 上传到 NAS" ssh -i "$SSH_KEY" -o BatchMode=yes "$NAS_HOST" "mkdir -p $NAS_DIR/updates/windows-x86_64" $SCP "$OUT" "$SIG_FILE" "$NAS_HOST:$NAS_DIR/updates/windows-x86_64/" -echo "== 4/4 合并 latest.json" +echo "== 4/4 写 latest-windows.json(平台独立)" SIG=$(cat "$SIG_FILE") URL="https://download.maqiart.eu.org/updates/windows-x86_64/image-workbench_${V}_x64-setup.exe" export SIG URL APP_VERSION="$V" -curl -s -m 20 https://download.maqiart.eu.org/updates/latest.json -o "$WORK/latest.json" || echo '{}' > "$WORK/latest.json" node -e ' const fs = require("fs") const p = process.argv[1] -let cur = {} -try { cur = JSON.parse(fs.readFileSync(p, "utf8")) } catch (e) { cur = {} } -cur.version = process.env.APP_VERSION -cur.notes = cur.notes || "在线更新" -cur.pub_date = new Date().toISOString() -cur.platforms = cur.platforms || {} -cur.platforms["windows-x86_64"] = { signature: process.env.SIG, url: process.env.URL } -fs.writeFileSync(p, JSON.stringify(cur, null, 2)) -console.log(" platforms:", Object.keys(cur.platforms).join(", ")) -' "$WORK/latest.json" -$SCP "$WORK/latest.json" "$NAS_HOST:$NAS_DIR/updates/latest.json" +const doc = { + version: process.env.APP_VERSION, + notes: process.env.NOTES || "在线更新", + pub_date: new Date().toISOString(), + platforms: { "windows-x86_64": { signature: process.env.SIG, url: process.env.URL } }, +} +fs.writeFileSync(p, JSON.stringify(doc, null, 2)) +console.log(" version", doc.version) +' "$WORK/latest-windows.json" +$SCP "$WORK/latest-windows.json" "$NAS_HOST:$NAS_DIR/updates/latest-windows.json" ssh -i "$SSH_KEY" -o BatchMode=yes "$NAS_HOST" "chmod -R a+rX $NAS_DIR" echo "== 完成" -curl -s -m 20 https://download.maqiart.eu.org/updates/latest.json | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const j=JSON.parse(s);console.log("version",j.version);for(const k of Object.keys(j.platforms))console.log(" -",k,"sig",(j.platforms[k].signature||"").length,"bytes")})' +curl -s -m 20 https://download.maqiart.eu.org/updates/latest-windows.json | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const j=JSON.parse(s);console.log("version",j.version);for(const k of Object.keys(j.platforms))console.log(" -",k,"sig",(j.platforms[k].signature||"").length,"bytes")})' curl -s -o /dev/null -m 60 -w "exe:%{http_code} size:%{size_download}\n" "$URL" diff --git a/scripts/serve-test.js b/scripts/serve-test.js index 1f1b4cb..d65f1d0 100644 --- a/scripts/serve-test.js +++ b/scripts/serve-test.js @@ -1,238 +1,65 @@ +/* serve-test.js —— e2e 用的本地静态服务器(v3.25.15 起脱离网页部署) + * + * 历史:本项目早期同时发布网页版(Cloudflare Pages),这个脚本会解析 `_headers` 下发 CSP、 + * 并模拟 Pages Functions(/api/img、/plugins/*)。**现在是桌面客户端项目**,那些部署面已删除, + * 因此这里只保留「能跑 e2e」的最小职责:把 dist/ 当静态目录伺服。 + * + * 桌面端的 CSP 由 src-tauri/tauri.conf.json 决定,e2e 不模拟 webview 的 CSP(要验就装真包)。 + * 用法:node scripts/serve-test.js(IWB_LOCAL_PORT 可改端口,默认 8787) + */ 'use strict' -const http = require('http') -const fs = require('fs') -const path = require('path') -const cp = require('child_process') +const http = require('node:http') +const fs = require('node:fs') +const path = require('node:path') const root = path.resolve(__dirname, '..') const dist = path.join(root, 'dist') const port = Number(process.env.IWB_LOCAL_PORT || 8787) -const mime = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8', '.json': 'application/json; charset=utf-8', '.png': 'image/png', '.svg': 'image/svg+xml' } -// ---------- _headers → 响应头(本地 e2e 与 Cloudflare Pages 保持一致) ---------- -// 动机:线上 CSP 是 connect-src 'self' https:,会拦掉 fetch(data:...) / CDN