hmjz100/LinkSwift · warning · Error
错误:<br/>请先登录网盘后再获取文件呢~
Error message
错误:<br/>请先登录网盘后再获取文件呢~
What it means
Pre-flight guard thrown before any API call when required login state is incomplete: it requires stored credentials (creds), a cached captcha token (cap), a clientId, and a deviceId. If any of these is missing or falsy, the library refuses to proceed and asks the user to log in to the cloud drive first. It is an intentional validation error, not an API failure.
Source
Thrown at (改)网盘直链下载助手.user.js:7719
device_id: deviceId,
meta: {
username: "", phone_number: "", email: "",
package_name: location.host,
client_version: clientVersion,
captcha_sign: this._getCaptchaSign(clientId, clientVersion, location.host, deviceId, timestamp.toString()),
timestamp: timestamp.toString(),
user_id: userId
}
}, { "Content-Type": "application/json" });
if (res?.captcha_token) {
cap = { token: res.captcha_token, expires_at: new Date(timestamp + res.expires_in * 1000).toString() };
base.setStorage(capKey, cap);
} else {
throw new Error(`错误:<br/>令牌刷新失败,${res?.error_description || res?.error || "未知错误"}`);
}
} else if (!creds || !cap || !clientId || !deviceId) {
throw new Error(`错误:<br/>请先登录网盘后再获取文件呢~`);
}
return { credentials: creds, captcha: cap, device_id: deviceId };
});
},
async getFileUrl(item, index, isRetry = false) {
if (item.downloadUrl) return { index, downloadUrl: item.downloadUrl };
// 获取当前内存中的 token
const token = await this.getToken(false, false).catch(e => {
if (e instanceof Error) throw e;
throw new Error(e?.message || e || "[迅雷云盘] 获取令牌失败");
});
const res = await base.get(config.$xunlei.api.getLink + item.id, {
"Authorization": `${token.credentials?.token_type} ${token.credentials?.access_token}`,
"Content-Type": "application/json",
"X-Captcha-Token": token.captcha.token,
View on GitHub (pinned to 417ea5e28a)
Solutions
- Open the cloud drive web page and complete the login flow in the userscript so creds/cap/clientId/deviceId are stored
- Clear and redo the userscript login if storage appears partially populated (e.g. creds present but captcha missing)
- Verify the script runs on the correct domain so storage keys and clientId/deviceId can be initialized
- Reinstall/update the userscript if a version change altered storage key names
Example fix
// caller-side pre-check
const creds = GM_getValue(capKeyPrefix + 'creds');
if (!creds || !GM_getValue(capKey) || !clientId || !deviceId) {
alert('请先在网盘页面登录再获取链接');
return;
} Defensive patterns
Strategy: validation
Validate before calling
const { credentials, captcha, clientId, deviceId } = readAuthState();
if (!credentials || !captcha || !clientId || !deviceId) { openLoginFlow(); return; } Type guard
function isLoggedIn(state) { return Boolean(state && state.credentials && state.captcha && state.clientId && state.deviceId); } Try / catch
try { await getLink(); } catch (e) { if (e.message.includes('请先登录网盘')) { showLoginModal(); } else throw e; } Prevention
- Check login state before showing the download button
- Avoid clearing site data while using the script
- Re-run login after userscript upgrades
- Detect partial storage and force full re-login
When it happens
Trigger: Invoking getFileUrl/getLink (or any flow calling this auth-check function) while !creds || !cap || !clientId || !deviceId — i.e. never logged in, or storage was cleared so cached credentials/captcha are gone.
Common situations: Fresh browser profile or incognito mode with no stored login; user cleared site data/localStorage; first-time use of the script without completing the cloud-drive login step; storage key renamed after a userscript upgrade.
Related errors
- extra 缺少内容。
- 错误:<br/>令牌刷新失败,${res?.error_description || res?.error || "未知
- [迅雷云盘] 获取令牌失败
- 提示:<br/>获取分享令牌失败,${res.msg ? "服务器说:" + res.msg + "。" : "刷新后再
AI-assisted analysis of hmjz100/LinkSwift@417ea5e28a (2026-09-02).
Data as JSON: /api/errors/837ed6356ee28cbf.
Report an issue: GitHub.