diff --git a/README.md b/README.md index 4cdc5b7..2d62a1f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

dsh-purge

-

Version 1.1.3

+

Version 1.1.4

DeepSeek Harness jailbreak (破甲): every model can jailbreak; swap prompts per model. Default prompt for Chinese models — 小码酱. Please star ⭐ @@ -537,6 +537,10 @@ If nothing is found, set `DSH_BASE`. No files are changed. ## Changelog +### 1.1.4 + +- Update check reads `package.json` at the GitHub commit SHA, instead of the stale jsDelivr `@master` cache or falling back to the local version. + ### 1.1.3 - Prompt inject once on the first turn; later turns pin the committed system prompt instead of appending a second copy. diff --git a/README.zh-CN.md b/README.zh-CN.md index 071ef35..18d13cb 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -4,7 +4,7 @@

dsh-purge

-

Version 1.1.3

+

Version 1.1.4

DeepSeek Harness 破甲:让所有模型都能破甲,不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐ @@ -541,6 +541,10 @@ npm 嵌套布局下,审批在 `dsh-user-approval/lib/index.js`,升级逻辑 ## 更新记录 +### 1.1.4 + +- 检测更新按 GitHub 提交号读 `package.json`,不再误用 jsDelivr `@master` 缓存,也不会在读不到远端版本时显示成「有新版本 1.1.2,当前 1.1.2」。 + ### 1.1.3 - 系统提示词只在每个会话第一轮注入一份;后续轮次钉住已提交的系统提示词,不再追加第二份。 diff --git a/lib/update.js b/lib/update.js index 8316806..91fcc4e 100644 --- a/lib/update.js +++ b/lib/update.js @@ -251,7 +251,7 @@ function isAbortError(e) { return (e && (e.name === "AbortError" || e.name === "TimeoutError")) || /aborted|abort/i.test(msg); } -async function fetchRes(url, ms = 20000) { +async function fetchRes(url, ms = 20000, headers = {}) { const ctrl = new AbortController(); const timer = setTimeout(() => { try { @@ -262,8 +262,9 @@ async function fetchRes(url, ms = 20000) { }, ms); try { const res = await fetch(url, { - headers: { "user-agent": "dsh-purge-update", accept: "*/*" }, + 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}`); @@ -276,23 +277,40 @@ async function fetchRes(url, ms = 20000) { } } -async function fetchText(url, ms = 20000) { - return (await fetchRes(url, ms)).text(); +async function fetchText(url, ms = 20000, headers = {}) { + return (await fetchRes(url, ms, headers)).text(); } -async function fetchJson(url) { - return JSON.parse(await fetchText(url)); +async function fetchJson(url, ms = 20000, headers = {}) { + return JSON.parse(await fetchText(url, ms, headers)); } -async function remotePackageVersion() { +function versionFromPackageText(text) { + const pkg = JSON.parse(text); + return pkg && pkg.version ? String(pkg.version) : ""; +} + +async function remotePackageVersion(sha = "") { + const ref = sha || BRANCH; const urls = [ - `https://raw.githubusercontent.com/${REPO}/${BRANCH}/package.json`, - `https://cdn.jsdelivr.net/gh/${REPO}@${BRANCH}/package.json`, - ]; + sha ? `https://cdn.jsdelivr.net/gh/${REPO}@${sha}/package.json` : "", + `https://raw.githubusercontent.com/${REPO}/${ref}/package.json`, + `https://cdn.jsdelivr.net/gh/${REPO}@${ref}/package.json`, + `https://api.github.com/repos/${REPO}/contents/package.json?ref=${encodeURIComponent(ref)}`, + ].filter(Boolean); for (const url of urls) { try { - const pkg = await fetchJson(url); - if (pkg && pkg.version) return String(pkg.version); + if (url.includes("api.github.com/repos/")) { + const data = await fetchJson(url, 20000, { accept: "application/vnd.github.raw" }); + if (typeof data === "string") return versionFromPackageText(data); + if (data && data.version) return String(data.version); + if (data && data.content && data.encoding === "base64") { + return versionFromPackageText(Buffer.from(data.content.replace(/\s/g, ""), "base64").toString("utf8")); + } + continue; + } + const ver = versionFromPackageText(await fetchText(url)); + if (ver) return ver; } catch { // 换下一个源。 } @@ -316,7 +334,8 @@ async function remoteHeadSha() { export async function checkUpdate() { const localVer = localVersion(); - const [remoteSha, remoteVer] = await Promise.all([remoteHeadSha(), remotePackageVersion()]); + const remoteSha = await remoteHeadSha(); + const remoteVer = await remotePackageVersion(remoteSha); if (!remoteSha && !remoteVer) throw new Error("无法读取 GitHub master"); const gitSha = gitOk() ? gitHead(PLUGIN_ROOT) : ""; const stamp = readStamp(); @@ -334,7 +353,7 @@ export async function checkUpdate() { ok: true, hasUpdate, localVersion: localVer, - remoteVersion: remoteVer || localVer, + remoteVersion: remoteVer || (remoteSha ? remoteSha.slice(0, 7) : ""), localSha: localRev ? localRev.slice(0, 7) : "", remoteSha: remoteSha ? remoteSha.slice(0, 7) : "", via: detectVia(), diff --git a/package.json b/package.json index aaff5ba..9fd2678 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsh-purge", - "version": "1.1.3", + "version": "1.1.4", "description": "DeepSeek Harness 破甲:所有模型都可破甲,不同模型可换不同提示词;默认提示词面向国模「小码酱」。Jailbreak for every model. 求 Star ⭐", "type": "module", "main": "lib/index.js",