hmjz100/LinkSwift · error · Error
提示:<br/>请先登录网盘后再刷新页面呢~
Error message
提示:<br/>请先登录网盘后再刷新页面呢~
What it means
This userscript (网盘直链下载助手, 光鸭云盘 driver) throws this when the RPC/backend request inside getLink() throws a non-Error value in its try/catch. The catch block assumes the most common cause is an unauthenticated session (network disk cookies missing/expired), so it converts any thrown failure into a 'please log in first' hint. It is a user-facing hint rather than a precise diagnostic.
Source
Thrown at (改)网盘直链下载助手.user.js:8093
let res;
if (item.downloadUrl) return { index, downloadUrl: item.downloadUrl };
if (shareToken) {
res = await base.post(config.$guangya.api.getShareLink, { "fileId": item.fileId, "accessToken": shareToken }, { "Authorization": `${token.credentials?.token_type} ${token.credentials?.access_token}`, "Content-Type": "application/json", "X-Captcha-Token": token.captcha.captcha_token, "X-Device-Id": token.deviceid });
} else {
res = await base.post(config.$guangya.api.getLink, { "fileId": item.fileId }, { "Authorization": `${token.credentials?.token_type} ${token.credentials?.access_token}`, "Content-Type": "application/json", "X-Captcha-Token": token.captcha.captcha_token, "X-Device-Id": token.deviceid });
}
if (res.data?.signedURL || res.data?.downloadUrl) {
return { index, downloadUrl: res.data?.signedURL ?? res.data?.downloadUrl };
} else if (res.code) {
if (res.code == 9) return { index, downloadUrl: "获取下载地址失败,服务器说:页面验证过期了,刷新后再获取吧~" };
if (res.code == 103) return { index, downloadUrl: "获取下载地址失败,服务器说:后端 RPC 响应超时。脚本建议:再重新获取一次~" };
if (res.code == 207) return { index, downloadUrl: "获取下载地址失败,服务器说:分享者未打开免登录下载。请登录后下载~" };
} else {
return { index, downloadUrl: `获取下载地址失败,${res.msg ? "服务器说:" + res.msg + "。" : "刷新后再试试吧~"}` };
}
} catch {
throw new Error("提示:<br/>请先登录网盘后再刷新页面呢~");
}
},
async getLink() {
const selects = this.getSelectedList();
if (selects.length === 0) throw new Error("提示:<br/>请勾选要下载的文件哦~");
if (selects.every(item => item.resType == 2)) throw new Error("提示:<br/>请打开文件夹后再勾选文件~");
if (temp.page === "home") {
const token = this.getToken();
const batchSize = 15;
let proc = 0;
$doc.find(".loading-popup .loading-title").html(`链接获取中`);
$doc.find(".loading-popup .swal2-html-container").html(`<div>正在获取文件对应的下载链接~</div>`);
for (let i = 0; i < selects.length; i += batchSize) {
const batch = selects.slice(i, i + batchSize);
const queue = [];
batch.forEach((item, localIndex) => {
const globalIndex = i + localIndex;
queue.push(this.getFileUrl(item, globalIndex, token)
View on GitHub (pinned to 417ea5e28a)
Solutions
- Log in to the cloud-drive website in the same browser, confirm you can browse files, then retry.
- Refresh the page so the script picks up fresh cookies, then re-fetch links.
- If already logged in, check the network/console for the real underlying request failure (timeout, CORS, blocked RPC) before assuming auth.
- Clear stale cookies or re-login if the session is half-expired.
Example fix
// before
catch {
throw new Error("提示:<br/>请先登录网盘后再刷新页面呢~");
}
// after
catch (e) {
if (e instanceof Error && /login|401/i.test(String(e.message))) throw new Error("提示:<br/>请先登录网盘后再刷新页面呢~");
throw new Error("获取失败:" + (e?.message || e));
} Defensive patterns
Strategy: try-catch
Validate before calling
// run before fetching
const loggedOut = !document.cookie || !/^(?:.*;)?\s*(__pus|__puer)=/.test(document.cookie);
if (loggedOut) alert('请先登录网盘'); Type guard
function is thrownValueError(e) { return e instanceof Error; } Try / catch
try { await driver.getLink(); } catch (e) { if (String(e.message).includes('请先登录网盘')) { promptLogin(); } else { throw e; } } Prevention
- Log in to the cloud drive before using the script
- Refresh after login so cookies are picked up
- Watch the console for the real underlying request failure
When it happens
Trigger: The await-ed backend call in the link-fetch flow throws (network failure, invalid JSON, 401/redirect to login page returning non-JSON, GM_xmlhttpRequest error) and the caught value is not an Error with res.code 103/207; the catch{} unconditionally throws this login hint.
Common situations: User's cloud-drive cookie expired or they opened a share page without logging in; backend RPC returned non-JSON (login redirect HTML) causing JSON.parse throw; network blocked the request entirely.
Related errors
AI-assisted analysis of hmjz100/LinkSwift@417ea5e28a (2026-09-02).
Data as JSON: /api/errors/9f426d44e2c9ef63.
Report an issue: GitHub.