fix: 修正自定义镜像优先级并发布 v2.1.6
构建与发布 / 单测与集成测试 (push) Has been cancelled
构建与发布 / 发布 GitHub Release (push) Has been cancelled
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, linux, ubuntu-24.04-arm) (push) Has been cancelled
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, macos, macos-15) (push) Has been cancelled
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, linux, ubuntu-24.04) (push) Has been cancelled
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, windows, windows-2025) (push) Has been cancelled

用户配置自定义 Z-Library 镜像后,旧会话记录的内置镜像仍被排在前面,
与界面“自定义优先”的约定不一致。调整请求顺序,让自定义镜像严格优先;
全部镜像失败时保留首个自定义镜像的错误,避免被后续兜底错误覆盖。

版本更新到 2.1.6,并补充优先级与错误归因回归测试。
This commit is contained in:
lofyer
2026-08-09 15:48:52 +08:00
parent 488de94289
commit 26c7aaff66
4 changed files with 67 additions and 7 deletions
+17 -4
View File
@@ -215,12 +215,17 @@ async function callOn(mirror, path, params, session, method) {
}
async function attempt(session, path, params, method) {
const custom = auth.getCustomMirrors();
const mirrors = getMirrors();
const ordered = session.mirror
// 用户显式配置镜像后必须严格优先于旧会话镜像,否则界面写着“自定义优先”,
// 实际却仍先等待上次成功但现在已失效的默认域名。
const ordered = custom.length
? mirrors
: session.mirror
? [session.mirror, ...mirrors.filter((m) => m !== session.mirror)]
: mirrors;
let lastErr;
const errors = [];
for (const m of ordered) {
try {
const j = await callOn(m, path, params, session, method);
@@ -228,10 +233,18 @@ async function attempt(session, path, params, method) {
return { ok: true, data: j };
} catch (e) {
if (e.code === 'AUTH_STALE') return { ok: false, stale: true, error: e };
lastErr = e;
errors.push(e);
}
}
return { ok: false, stale: false, error: lastErr };
if (errors.length <= 1) {
return { ok: false, stale: false, error: errors[0] };
}
const first = errors[0];
const label = custom.length ? '自定义镜像失败' : '首选镜像失败';
const summary = new Error(
`${label}${(first && first.message) || String(first)};其余 ${errors.length - 1} 个镜像也未成功`
);
return { ok: false, stale: false, error: summary };
}
async function apiCall(path, params = {}, method = 'GET') {