hmjz100/LinkSwift · error · Error
提示:<br/>请先登录网盘~<br/>代码:${res.code}
Error message
提示:<br/>请先登录网盘~<br/>代码:${res.code} What it means
Thrown when Quark's getLink API (config.$quark.api.getLink, POSTed with fids and the user's cookies) responds with code 31001, which Quark defines as 'not logged in'. The script maps it to a friendly login prompt including the server code.
Source
Thrown at (改)网盘直链下载助手.user.js:8492
},
async getLink() {
let selects = this.getSelectedList();
if (selects.length === 0) throw new Error("提示:<br/>请勾选要下载的文件哦~");
if (selects.every(item => !item.file)) throw new Error("提示:<br/>请打开文件夹后再勾选文件~");
if (temp.page === "home") {
const data = [];
const batchSize = 15;
let proc = 0;
selects = selects.filter(item => item.file === true)
for (let i = 0; i < selects.length; i += batchSize) {
// 获取当前批次文件
const batch = selects.slice(i, i + batchSize);
const fids = batch.map(item => item.fid);
// 发起请求获取链接
const res = await base.post(config.$quark.api.getLink, { "fids": fids }, { "Content-Type": "application/json", "Cookie": String(document.cookie), "User-Agent": config.$quark.api.ua.downloadLink });
if (!res || res.code !== 0 || !res.data) {
if (res.code == 31001) throw new Error("提示:<br/>请先登录网盘~<br/>代码:" + res.code);
if (res.code == 23018) {
const fid = res.message?.match(/\[([a-f0-9]{32})\]/)?.[1];
const item = batch.find(item => item.fid === fid);
throw new Error(`提示:<br/>超出游客可获取大小限制<br/>请登录后获取哦~${item?.file_name ? `<br/>文件:${item.file_name}` : ""}`);
}
if (res.code || res.message) {
throw new Error(`提示:<br/>获取链接失败了~<br/>${res.code ? res.code : ""} ${res.message ? res.message : ""}`);
} else {
throw new Error("提示:<br/>获取下载链接失败,刷新网页后再试试吧~");
}
}
// 合并响应数据
if (res.data) {
data.push(...res.data);
}
// 更新处理进度
View on GitHub (pinned to 417ea5e28a)
Solutions
- Log in to pan.quark.cn in the browser, confirm the file list loads, then retry.
- Check cookies are not blocked for pan.quark.cn (privacy settings / extensions).
- Clear Quark cookies and re-login to fix a half-expired session.
- Ensure the browser sends cookies with the request (same-site, not incognito without login).
Example fix
// before
if (!res || res.code !== 0 || !res.data) {
if (res.code == 31001) throw new Error("提示:<br/>请先登录网盘~<br/>代码:" + res.code);
// after (guard against res being falsy first)
if (!res || res.code !== 0 || !res.data) {
if (res?.code == 31001) throw new Error("提示:<br/>请先登录网盘~<br/>代码:31001");
if (!res) throw new Error("获取下载地址失败:无响应,请重试"); Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check login state before calling getLink
const loggedIn = /(?:^|;\s*)(__pus|__puer)=/.test(document.cookie);
if (!loggedIn) { alert('请先登录夸克网盘'); return; } Type guard
const isQuarkNotLoggedIn = res => res && res.code === 31001;
Try / catch
try { await driver.getLink(); } catch (e) { if (String(e.message).includes('31001')) { redirectToQuarkLogin(); } else { throw e; } } Prevention
- Log in to pan.quark.cn before fetching links
- Don't block cookies for pan.quark.cn in browser settings/extensions
- Re-login after clearing cookies or switching accounts
- Refresh the page after login so document.cookie is current
When it happens
Trigger: POST to Quark's batch get-link endpoint returns { code: 31001 } — the session cookie (document.cookie sent explicitly) is absent, expired, or invalid for the account.
Common situations: User operates Quark as a guest after session expiry; cookies blocked/cleared by browser privacy settings or extensions; logged into a different account than expected; anti-bot UA mismatch invalidating the session.
Related errors
- 提示:<br/>请先登录网盘后再刷新页面呢~
- AccessTokenInvalid
- [天翼云盘] 获取令牌失败
- 提示:<br/>请先登录网盘~
- GreaseMonkey 兼容 XMLHttpRequest 不可用。
AI-assisted analysis of hmjz100/LinkSwift@417ea5e28a (2026-09-02).
Data as JSON: /api/errors/c650a47039f24239.
Report an issue: GitHub.