mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 13:20:22 +08:00
fix: 发布 1.1.28,修更新 http 302 与测试版列表被正式号藏空
- 归档下载改直连 codeload,并手动跟随 301/302,避免 Electron 下 github.com/archive 报 http 302 - 前端 keepListedVersion 与后端一致:beta tip / beta 分支始终可见;tip SHA 失败时 raw/jsDelivr 回退 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3f2051be7e
commit
00b4c6f93d
5 files changed
+62
-20
No files matched your search
+42
-15
@@ -11,7 +11,7 @@ import { cliInvocation } from "./desktop.js";
|
||||
const REPO = "YuJunZhiXue/dsh-purge";
|
||||
const STABLE_REF = "master";
|
||||
const BETA_REF = "beta";
|
||||
export const TARBALL_URL = `https://github.com/${REPO}/archive/refs/heads/${STABLE_REF}.tar.gz`;
|
||||
export const TARBALL_URL = `https://codeload.github.com/${REPO}/tar.gz/refs/heads/${STABLE_REF}`;
|
||||
const PLUGIN_ROOT = path.resolve(fileURLToPath(new URL(".", import.meta.url)), "..");
|
||||
const CHANNELS = {
|
||||
stable: { id: "stable", ref: STABLE_REF, label: "正式版" },
|
||||
@@ -165,18 +165,19 @@ function pushHistory(entry) {
|
||||
fs.writeFileSync(historyPath(), `${JSON.stringify(next, null, 2)}\n`, "utf8");
|
||||
}
|
||||
|
||||
/** 直连 codeload,避免 github.com/archive → 302 在 Electron/部分 Node 下变成 http 302 / fetch failed。 */
|
||||
function archiveZipUrl(ref) {
|
||||
const value = String(ref || STABLE_REF);
|
||||
if (/^[0-9a-f]{40}$/i.test(value)) return `https://github.com/${REPO}/archive/${value}.zip`;
|
||||
if (/^v?\d/.test(value)) return `https://github.com/${REPO}/archive/refs/tags/${encodeURIComponent(value)}.zip`;
|
||||
return `https://github.com/${REPO}/archive/refs/heads/${encodeURIComponent(value)}.zip`;
|
||||
if (/^[0-9a-f]{40}$/i.test(value)) return `https://codeload.github.com/${REPO}/zip/${value}`;
|
||||
if (/^v?\d/.test(value)) return `https://codeload.github.com/${REPO}/zip/refs/tags/${encodeURIComponent(value)}`;
|
||||
return `https://codeload.github.com/${REPO}/zip/refs/heads/${encodeURIComponent(value)}`;
|
||||
}
|
||||
|
||||
function archiveTarballUrl(ref) {
|
||||
const value = String(ref || STABLE_REF);
|
||||
if (/^[0-9a-f]{40}$/i.test(value)) return `https://github.com/${REPO}/archive/${value}.tar.gz`;
|
||||
if (/^v?\d/.test(value)) return `https://github.com/${REPO}/archive/refs/tags/${encodeURIComponent(value)}.tar.gz`;
|
||||
return `https://github.com/${REPO}/archive/refs/heads/${encodeURIComponent(value)}.tar.gz`;
|
||||
if (/^[0-9a-f]{40}$/i.test(value)) return `https://codeload.github.com/${REPO}/tar.gz/${value}`;
|
||||
if (/^v?\d/.test(value)) return `https://codeload.github.com/${REPO}/tar.gz/refs/tags/${encodeURIComponent(value)}`;
|
||||
return `https://codeload.github.com/${REPO}/tar.gz/refs/heads/${encodeURIComponent(value)}`;
|
||||
}
|
||||
|
||||
function readStamp() {
|
||||
@@ -420,14 +421,25 @@ async function fetchRes(url, ms = 20000, headers = {}) {
|
||||
}
|
||||
}, ms);
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
headers: { "user-agent": "dsh-purge-update", accept: "*/*", ...headers },
|
||||
redirect: "follow",
|
||||
cache: "no-store",
|
||||
signal: ctrl.signal,
|
||||
});
|
||||
if (!res.ok) throw new Error(`http ${res.status}`);
|
||||
return res;
|
||||
let current = String(url || "");
|
||||
for (let hop = 0; hop < 6; hop += 1) {
|
||||
const res = await fetch(current, {
|
||||
headers: { "user-agent": "dsh-purge-update", accept: "*/*", ...headers },
|
||||
// 手动跟跳转:部分宿主对 github.com → codeload 跨域 302 不会自动 follow,会直接抛 http 302。
|
||||
redirect: "manual",
|
||||
cache: "no-store",
|
||||
signal: ctrl.signal,
|
||||
});
|
||||
if ([301, 302, 303, 307, 308].includes(res.status)) {
|
||||
const loc = res.headers.get("location");
|
||||
if (!loc) throw new Error(`http ${res.status}`);
|
||||
current = new URL(loc, current).href;
|
||||
continue;
|
||||
}
|
||||
if (!res.ok) throw new Error(`http ${res.status}`);
|
||||
return res;
|
||||
}
|
||||
throw new Error("http redirect loop");
|
||||
} catch (e) {
|
||||
if (isAbortError(e)) throw new Error("GitHub 超时");
|
||||
throw e;
|
||||
@@ -631,6 +643,21 @@ async function listRemoteVersions() {
|
||||
kind: "head",
|
||||
latest: true,
|
||||
});
|
||||
} else {
|
||||
// API/atom 拿不到 tip 时,仍用 raw/jsDelivr 探一下 beta 分支,避免测试通道整栏空白。
|
||||
const version = await remotePackageVersion("", BETA_REF).catch(() => "");
|
||||
if (version) {
|
||||
add({
|
||||
id: BETA_REF,
|
||||
ref: BETA_REF,
|
||||
sha: "",
|
||||
version,
|
||||
channel: "beta",
|
||||
label: `${versionLabel(version, "beta")} · 最新`,
|
||||
kind: "head",
|
||||
latest: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const tag of tags) {
|
||||
if (!withdrawnVersion(tag)) add(tag);
|
||||
|
||||
Reference in new issue
Block a user