fix(update): 更新检查改走宿主中转,修复 Gitea 无 CORS 导致请求被拦 (v0.5.3-local.8)
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…。
This commit is contained in:
@@ -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 {
|
||||
|
||||
+30
-1
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user