From 1b053e557744b02cc21814d5a21908e817cfa288 Mon Sep 17 00:00:00 2001 From: wangheng Date: Wed, 2 Dec 2026 17:30:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(update):=20=E6=9B=B4=E6=96=B0=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=94=B9=E8=B5=B0=E5=AE=BF=E4=B8=BB=E4=B8=AD=E8=BD=AC?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=20Gitea=20=E6=97=A0=20CORS=20?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E8=AF=B7=E6=B1=82=E8=A2=AB=E6=8B=A6=20(v0.5.?= =?UTF-8?q?3-local.8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 0.5.3-local.6 把更新检查从上游 GitHub 改到自建 Gitea API,但仍不通: 页面来源是 http://127.0.0.1:<随机端口>,请求 https://gitea.ququclean.com/api/... 属跨源,而 Gitea 不返回 Access-Control-Allow-Origin,浏览器直接拦截 fetch。 表现为「立即检查」无反应、长期显示「上次检查未成功」。 改为宿主中转: - src/index.ts 新增 /api/worktable/update-check 路由,服务端(Node 无 CORS 约束)代取 Gitea releases/latest,客户端只请求同源路径 - updateCheck.ts / index.tsx 的 fetch 改指向该同源路由 - 该路由沿既有约定需要鉴权(request-auth.test.mjs 要求除 health/preview-static 外所有路由都必须拒绝未鉴权请求),未传 publicAsset 测试:sidebar-popup.test.mjs 的 releaseUrl 改为 /api/worktable/update-check。 验证:npm run pack 全绿,双资产同源 sha256 225e8568…。 --- 01_content/dsh.plugin.json | 2 +- 01_content/lib/client.js | 14 +++++------- 01_content/lib/index.js | 31 +++++++++++++++++++++++++- 01_content/package.json | 2 +- 01_content/src/client/hostTransport.ts | 2 +- 01_content/src/client/index.tsx | 6 ++--- 01_content/src/client/updateCheck.ts | 7 +++--- 01_content/src/index.ts | 30 +++++++++++++++++++++++++ 02_process/LOCAL-CHANGES.md | 16 ++++++++++--- 04_test/sidebar-popup.test.mjs | 2 +- README.md | 12 +++++----- 11 files changed, 96 insertions(+), 28 deletions(-) diff --git a/01_content/dsh.plugin.json b/01_content/dsh.plugin.json index 2e444a7..e8f4317 100644 --- a/01_content/dsh.plugin.json +++ b/01_content/dsh.plugin.json @@ -1,7 +1,7 @@ { "name": "dsh-worktable", "description": "工作台:DSH 侧边栏的 agent 级项目容器,收纳如 TravelAtlas 等自装项目", - "version": "0.5.3-local.7", + "version": "0.5.3-local.8", "entry": { "name": "dsh-worktable", "inject": [] diff --git a/01_content/lib/client.js b/01_content/lib/client.js index 96de9a4..3af6808 100644 --- a/01_content/lib/client.js +++ b/01_content/lib/client.js @@ -8967,7 +8967,7 @@ function hostPreviewUrl(path, surface = { if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error("Unsupported Host preview protocol"); return url.href; } -var UPDATE_TGZ = "https://gitea.ququclean.com/xiaoqu/dsh-worktable/releases/download/v0.5.3-local.7/dsh-worktable.tgz"; +var UPDATE_TGZ = "https://gitea.ququclean.com/xiaoqu/dsh-worktable/releases/download/v0.5.3-local.8/dsh-worktable.tgz"; function worktableUpgrade(protocol = typeof location === "undefined" ? "http:" : location.protocol) { const desktop = protocol === "dsh-app:"; const command = "dsh plugin --profile " + (desktop ? "desktop" : "web") + ' add "' + UPDATE_TGZ + '"'; @@ -9200,9 +9200,8 @@ var CHANGELOG_V030 = `\u66F4\u65B0\u516C\u544A \xB7 v0.5.1 \u30103.1 \u6587\u5B57\u4E0E\u7EC6\u8282\u6253\u78E8\u3011\u5168\u5C40\u5B57\u4F53\u4E0E\u5B57\u53F7\u7EDF\u4E00\u4F18\u5316\u3001\u4E0B\u62C9\u9762\u677F\u73BB\u7483\u5316\u4E0E\u5BF9\u9F50\u3001\u83DC\u5355\u70B9\u9009\u540E\u4FDD\u6301\u6253\u5F00\u4FBF\u4E8E\u8FDE\u7EED\u9884\u89C8\u3001\u6309\u94AE\u63CF\u8FB9\u4E0E\u60AC\u505C\u53CD\u9988\u7B49\u4EA4\u4E92\u7EC6\u8282\uFF1B\u540C\u65F6\u4FEE\u590D\u4E86\u591A\u9879\u4F53\u9A8C\u95EE\u9898\uFF08\u7167\u7247\u4E0A\u4F20\u6E05\u6670\u5EA6\u3001\u80CC\u666F\u7F51\u683C\u7EBF\u5728\u7167\u7247\u6A21\u5F0F\u4E0B\u4E0D\u751F\u6548\u3001\u6D45\u8272\u4E3B\u9898\u4E0B\u5DE5\u4F5C\u72B6\u6001\u5149\u6548\u4E0D\u53EF\u89C1\u7B49\uFF09\u3002`; // src/client/updateCheck.ts -var LOCAL_VERSION = false ? "dev" : "0.5.3-local.7"; -var UPDATE_HOST = "https://gitea.ququclean.com"; -var UPDATE_REPO = "xiaoqu/dsh-worktable"; +var LOCAL_VERSION = false ? "dev" : "0.5.3-local.8"; +var UPDATE_API = "/api/worktable/update-check"; var K_UPDATE_CHECK = "dsh.worktable.updateCheck.v1"; var K_LAST_CHECK = "dsh.worktable.lastUpdateCheck.v1"; var K_SKIP = "dsh.worktable.skipVersion.v1"; @@ -9306,7 +9305,7 @@ async function checkUpdate(force = false) { const ctrl = new AbortController(); const timer2 = setTimeout(() => ctrl.abort(), 8e3); try { - const r = await fetch(UPDATE_HOST + "/api/v1/repos/" + UPDATE_REPO + "/releases/latest", { headers: { Accept: "application/json" }, cache: "no-store", signal: ctrl.signal }); + const r = await fetch(UPDATE_API, { headers: { Accept: "application/json" }, cache: "no-store", signal: ctrl.signal }); if (r.ok) d = await r.json(); else if (r.status === 403 || r.status === 404) break; } catch { @@ -20871,8 +20870,7 @@ function flushHostSave() { // src/client/index.tsx var import_jsx_runtime3 = require("react/jsx-runtime"); -var UPDATE_HOST2 = "https://gitea.ququclean.com"; -var UPDATE_REPO2 = "xiaoqu/dsh-worktable"; +var UPDATE_API2 = "/api/worktable/update-check"; var { command: UPGRADE_CMD, prompt: UPGRADE_AI2, desktop: DESKTOP_HOST } = worktableUpgrade(); var ICON_SYNC = /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { viewBox: "0 0 16 16", "aria-hidden": true, children: [ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", d: "M1.5 8a6.5 6.5 0 0 1 11.1-4.6L14.5 5" }), @@ -21796,7 +21794,7 @@ function WorktableSection(props) { const ctrl = new AbortController(); const timer2 = setTimeout(() => ctrl.abort(), 8e3); try { - const r = await fetch(UPDATE_HOST2 + "/api/v1/repos/" + UPDATE_REPO2 + "/releases/latest", { headers: { Accept: "application/json" }, cache: "no-store", signal: ctrl.signal }); + const r = await fetch(UPDATE_API2, { headers: { Accept: "application/json" }, cache: "no-store", signal: ctrl.signal }); if (r.ok) d = await r.json(); else if (r.status === 403 || r.status === 404) break; } catch { diff --git a/01_content/lib/index.js b/01_content/lib/index.js index 9489af5..e6da56b 100644 --- a/01_content/lib/index.js +++ b/01_content/lib/index.js @@ -382,7 +382,7 @@ function resolveDshHomeSafe() { cachedDshHome = baseDshHome(); return cachedDshHome; } -var PLUGIN_VERSION = false ? "dev" : "0.5.3-local.7"; +var PLUGIN_VERSION = false ? "dev" : "0.5.3-local.8"; var name = "dsh-worktable"; var inject = ["webServer", "sessions"]; var HEALTH_PATH = "/api/worktable/health"; @@ -743,6 +743,35 @@ function apply(ctx) { json(res, 200, { plugin: "dsh-worktable", version: PLUGIN_VERSION, ok: true }); } }); + register({ + kind: "exact", + path: "/api/worktable/update-check", + handler: async (_req, res) => { + const upstream = "https://gitea.ququclean.com/api/v1/repos/xiaoqu/dsh-worktable/releases/latest"; + const ctrl = new AbortController(); + const timer = setTimeout(() => ctrl.abort(), 8e3); + try { + const r = await fetch(upstream, { + headers: { Accept: "application/json", "user-agent": "dsh-worktable/" + PLUGIN_VERSION }, + signal: ctrl.signal + }); + if (!r.ok) { + json(res, 502, { error: "upstream status " + r.status }); + return; + } + const d = await r.json(); + json(res, 200, { + tag_name: typeof d?.tag_name === "string" ? d.tag_name : "", + body: typeof d?.body === "string" ? d.body : "", + html_url: typeof d?.html_url === "string" ? d.html_url : "" + }); + } catch (err) { + json(res, 502, { error: "upstream unreachable: " + String(err?.message ?? err) }); + } finally { + clearTimeout(timer); + } + } + }); register({ kind: "exact", path: "/api/worktable/file", diff --git a/01_content/package.json b/01_content/package.json index 1f2aa96..3631105 100644 --- a/01_content/package.json +++ b/01_content/package.json @@ -1,7 +1,7 @@ { "name": "dsh-worktable", "description": "工作台 Worktable:DeepSeek Harness 侧边栏的 agent 级项目容器(应用抽屉)", - "version": "0.5.3-local.7", + "version": "0.5.3-local.8", "repository": { "type": "git", "url": "https://github.com/Aisland-SJL/dsh-worktable.git", diff --git a/01_content/src/client/hostTransport.ts b/01_content/src/client/hostTransport.ts index 3eefe74..e0dbe0f 100644 --- a/01_content/src/client/hostTransport.ts +++ b/01_content/src/client/hostTransport.ts @@ -38,7 +38,7 @@ export function hostPreviewUrl( /** Keep update instructions on the active profile; Desktop must use its bundled CLI. */ // 本仓发布在自建 Gitea:它不支持 GitHub 的 /releases/latest/download 简写, // 安装命令必须带具体 tag。这里给固定 tag(随发布更新),避免给出 404 的命令。 -const UPDATE_TGZ = 'https://gitea.ququclean.com/xiaoqu/dsh-worktable/releases/download/v0.5.3-local.7/dsh-worktable.tgz' +const UPDATE_TGZ = 'https://gitea.ququclean.com/xiaoqu/dsh-worktable/releases/download/v0.5.3-local.8/dsh-worktable.tgz' export function worktableUpgrade(protocol = typeof location === 'undefined' ? 'http:' : location.protocol) { const desktop = protocol === 'dsh-app:' diff --git a/01_content/src/client/index.tsx b/01_content/src/client/index.tsx index 5406774..b9b4dc4 100644 --- a/01_content/src/client/index.tsx +++ b/01_content/src/client/index.tsx @@ -33,8 +33,8 @@ type DockMode = 'footer' | 'float' // ── 更新检查(客户端直连本仓 Gitea Releases API,只读 GET;失败静默)── // 本仓是内部补丁分发仓:上游只发官方版(无本地补丁), // 查上游既看不到本仓版本,国内网络也常失败。 -const UPDATE_HOST = 'https://gitea.ququclean.com' -const UPDATE_REPO = 'xiaoqu/dsh-worktable' +// 走宿主中转:页面来源是随机端口 127.0.0.1,直连 Gitea 跨源且无 CORS 头会被拦截 +const UPDATE_API = '/api/worktable/update-check' const { command: UPGRADE_CMD, prompt: UPGRADE_AI, desktop: DESKTOP_HOST } = worktableUpgrade() // 更新提示图标(手绘 SVG,避免 emoji 跨平台渲染差异) const ICON_SYNC = ( @@ -1097,7 +1097,7 @@ function WorktableSection(props: any) { const ctrl = new AbortController() const timer = setTimeout(() => ctrl.abort(), 8000) // 单次 8s 超时,计入下一轮重试 try { - const r = await fetch(UPDATE_HOST + '/api/v1/repos/' + UPDATE_REPO + '/releases/latest', { headers: { Accept: 'application/json' }, cache: 'no-store', signal: ctrl.signal }) + const r = await fetch(UPDATE_API, { headers: { Accept: 'application/json' }, cache: 'no-store', signal: ctrl.signal }) if (r.ok) d = await r.json() as { tag_name?: string; body?: string; html_url?: string } else if (r.status === 403 || r.status === 404) break // 限流/不存在:不再重试 } catch { /* 网络抖动/超时:下一轮重试 */ } diff --git a/01_content/src/client/updateCheck.ts b/01_content/src/client/updateCheck.ts index 5fc9b19..66d8e5e 100644 --- a/01_content/src/client/updateCheck.ts +++ b/01_content/src/client/updateCheck.ts @@ -3,8 +3,9 @@ declare const __WT_VERSION__: string export const LOCAL_VERSION = typeof __WT_VERSION__ === 'undefined' ? 'dev' : __WT_VERSION__ // 本仓是内部补丁分发仓,更新源必须是自己的 Gitea,而不是上游 GitHub: // 上游只发布官方版(无本地补丁),查它既看不到本仓版本,国内网络也常失败。 -const UPDATE_HOST = 'https://gitea.ququclean.com' -const UPDATE_REPO = 'xiaoqu/dsh-worktable' +// 走宿主中转(/api/worktable/update-check):页面来源是随机端口的 127.0.0.1, +// 直连 Gitea 属跨源且 Gitea 无 CORS 头,浏览器会拦截请求。 +const UPDATE_API = '/api/worktable/update-check' export type UpdateStatus = 'idle' | 'checking' | 'uptodate' | 'failed' export type UpdateInfo = { latest: string; notes: string; url: string } @@ -95,7 +96,7 @@ export async function checkUpdate(force = false): Promise<{ status: UpdateStatus const ctrl = new AbortController() const timer = setTimeout(() => ctrl.abort(), 8000) try { - const r = await fetch(UPDATE_HOST + '/api/v1/repos/' + UPDATE_REPO + '/releases/latest', { headers: { Accept: 'application/json' }, cache: 'no-store', signal: ctrl.signal }) + const r = await fetch(UPDATE_API, { headers: { Accept: 'application/json' }, cache: 'no-store', signal: ctrl.signal }) if (r.ok) d = (await r.json()) as { tag_name?: string; body?: string; html_url?: string } else if (r.status === 403 || r.status === 404) break } catch { /* 网络抖动/超时:下一轮重试 */ } diff --git a/01_content/src/index.ts b/01_content/src/index.ts index 00b818d..74fc4e8 100644 --- a/01_content/src/index.ts +++ b/01_content/src/index.ts @@ -368,6 +368,36 @@ export function apply(ctx: Context) { }, }) + // 更新检查中转:客户端页面来源是 http://127.0.0.1:<随机端口>,直接 fetch + // 自建 Gitea 属跨源请求;Gitea 不返回 Access-Control-Allow-Origin,浏览器会拦截 + // (表现为「立即检查」无反应 / 「上次检查未成功」)。改由宿主服务端代取,同源无 CORS。 + register({ + kind: 'exact', + path: '/api/worktable/update-check', + handler: async (_req: any, res: any) => { + const upstream = 'https://gitea.ququclean.com/api/v1/repos/xiaoqu/dsh-worktable/releases/latest' + const ctrl = new AbortController() + const timer = setTimeout(() => ctrl.abort(), 8000) + try { + const r = await fetch(upstream, { + headers: { Accept: 'application/json', 'user-agent': 'dsh-worktable/' + PLUGIN_VERSION }, + signal: ctrl.signal, + }) + if (!r.ok) { json(res, 502, { error: 'upstream status ' + r.status }); return } + const d: any = await r.json() + json(res, 200, { + tag_name: typeof d?.tag_name === 'string' ? d.tag_name : '', + body: typeof d?.body === 'string' ? d.body : '', + html_url: typeof d?.html_url === 'string' ? d.html_url : '', + }) + } catch (err: any) { + json(res, 502, { error: 'upstream unreachable: ' + String(err?.message ?? err) }) + } finally { + clearTimeout(timer) + } + }, + }) + // 本地文件读取(资源管理器点击 .html 后浏览器标签内打开) register({ kind: 'exact', diff --git a/02_process/LOCAL-CHANGES.md b/02_process/LOCAL-CHANGES.md index 57e8381..af3f51c 100644 --- a/02_process/LOCAL-CHANGES.md +++ b/02_process/LOCAL-CHANGES.md @@ -4,9 +4,9 @@ > 每条标注日期、动机、落点与验证方式。改动在 `01_content/src/`,经 `npm run build` > 产出 `lib/`;发布物由 `npm run pack`(`01_content/release-prep.mjs`)生成。 -当前版本:**0.5.3-local.7**(2026-12-02) -产物:`01_content/dist/v0.5.3-local.7/dsh-worktable.tgz`,485166 字节, -sha256 `8c30d35f7b01a2242a311f36d5474c2764fef903049fbbbc3f2c14dfad126bec` +当前版本:**0.5.3-local.8**(2026-12-02) +产物:`01_content/dist/v0.5.3-local.8/dsh-worktable.tgz`,485317 字节, +sha256 `225e85683ab8848917cb09dbb80a49090b50210cc7b93245a676cc8e6e966cd4` --- @@ -156,6 +156,16 @@ fetch('https://api.github.com/repos/Aisland-SJL/dsh-worktable/releases/latest') **测试**:`04_test/sidebar-popup.test.mjs` 的 `releaseUrl` 断言同步改为新 API 地址。 +**0.5.3-local.8 修正(2026-12-02)**:直连 Gitea API 仍不通 —— 页面来源是 +`http://127.0.0.1:<随机端口>`,请求 `https://gitea.ququclean.com/api/...` 属跨源, +而 **Gitea 不返回 `Access-Control-Allow-Origin`**,浏览器直接拦截 fetch +(表现为「立即检查」无反应、长期显示「上次检查未成功」)。 + +改为**宿主中转**:`src/index.ts` 新增 `/api/worktable/update-check` 路由, +由服务端(Node,无 CORS 约束)代取 Gitea 的 `releases/latest`,客户端只请求同源路径。 +该路由沿既有约定**需要鉴权**(`request-auth.test.mjs` 要求除 health/preview-static 外 +所有路由都必须拒绝未鉴权请求)。 + **版本比较无需改动**:`cmpVer('v0.5.2-local.6', '0.5.3-local.5') = -1`, core 段 0.5.2 < 0.5.3 已能正确判定「有新版」。 diff --git a/04_test/sidebar-popup.test.mjs b/04_test/sidebar-popup.test.mjs index b7de4b6..988129d 100644 --- a/04_test/sidebar-popup.test.mjs +++ b/04_test/sidebar-popup.test.mjs @@ -305,7 +305,7 @@ function testConsolePresentation() { async function testUpdatePresentation() { // 更新源是本仓 Gitea(内部补丁分发仓),不是上游 GitHub - const releaseUrl = 'https://gitea.ququclean.com/api/v1/repos/xiaoqu/dsh-worktable/releases/latest' + const releaseUrl = '/api/worktable/update-check' for (const outcome of ['older', 'same', 'forbidden', 'invalid', 'invalid-prefix', 'skip']) { let response = { status: 200, tag: 'v9.0.0' } let requests = 0 diff --git a/README.md b/README.md index d8b87c5..71d9c5d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ > ## 📦 本仓库是内部补丁分发仓,不是上游源码仓 > -> 上游: | 本仓 = 上游 **v0.5.1** + 桌面端状态持久化补丁 + 本项目自用的若干增强(`0.5.3-local.7`)。 +> 上游: | 本仓 = 上游 **v0.5.1** + 桌面端状态持久化补丁 + 本项目自用的若干增强(`0.5.3-local.8`)。 > 下面从「Screenshots」开始的全部内容是上游 README 原文;本地改动逐条记录见 [LOCAL-CHANGES.md](02_process/LOCAL-CHANGES.md)。 ### 要不要装 @@ -16,16 +16,16 @@ ### 安装 -当前版本 **v0.5.3-local.7**: +当前版本 **v0.5.3-local.8**: ```bash -dsh plugin --profile web add "https://gitea.ququclean.com/xiaoqu/dsh-worktable/releases/download/v0.5.3-local.7/dsh-worktable.tgz" +dsh plugin --profile web add "https://gitea.ququclean.com/xiaoqu/dsh-worktable/releases/download/v0.5.3-local.8/dsh-worktable.tgz" ``` - **桌面端:先完全退出 Slark,再执行命令**,装完手动重开;不要在宿主运行时安装。 - `--profile web` 按你自己的 profile 名字改。 -- 资产 `dsh-worktable.tgz`,485166 字节,sha256: - `8c30d35f7b01a2242a311f36d5474c2764fef903049fbbbc3f2c14dfad126bec` +- 资产 `dsh-worktable.tgz`,485317 字节,sha256: + `225e85683ab8848917cb09dbb80a49090b50210cc7b93245a676cc8e6e966cd4` (下载后可 `Get-FileHash dsh-worktable.tgz -Algorithm SHA256` 核对) - 声明兼容的 DSH 版本:`0.2.0-rc.2` / `0.2.1-rc.3` / `0.2.1-rc.5` / `0.2.2-alpha.2`。 宿主不在这个列表里时,安装会被兼容性检查直接拒绝并回滚。 @@ -50,7 +50,7 @@ dsh plugin --profile web add "https://gitea.ququclean.com/xiaoqu/dsh-worktable/r ### 升级与回退 -- 装上 `0.5.3-local.7` 后,插件不会提示升级到 0.5.1。 +- 装上 `0.5.3-local.8` 后,插件不会提示升级到 0.5.1。 - 上游发布 0.5.2 及以上时插件会提示升级;**一旦升级就回到没有补丁的状态**,重启又会丢数据。新版本需要把补丁重新合并(改动清单见 [LOCAL-CHANGES.md](02_process/LOCAL-CHANGES.md))。 - 回退官方版: ```bash -- 2.54.0