{"record":{"id":"c650a47039f24239","repo":"hmjz100/LinkSwift","slug":"br-br-res-code","errorCode":null,"errorMessage":"提示：<br/>请先登录网盘~<br/>代码：${res.code}","messagePattern":"提示：<br/>请先登录网盘~<br/>代码：(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"（改）网盘直链下载助手.user.js","lineNumber":8492,"sourceCode":"\t\t},\r\n\t\tasync getLink() {\r\n\t\t\tlet selects = this.getSelectedList();\r\n\t\t\tif (selects.length === 0) throw new Error(\"提示：<br/>请勾选要下载的文件哦~\");\r\n\t\t\tif (selects.every(item => !item.file)) throw new Error(\"提示：<br/>请打开文件夹后再勾选文件~\");\r\n\t\t\tif (temp.page === \"home\") {\r\n\t\t\t\tconst data = [];\r\n\t\t\t\tconst batchSize = 15;\r\n\t\t\t\tlet proc = 0;\r\n\t\t\t\tselects = selects.filter(item => item.file === true)\r\n\t\t\t\tfor (let i = 0; i < selects.length; i += batchSize) {\r\n\t\t\t\t\t// 获取当前批次文件\r\n\t\t\t\t\tconst batch = selects.slice(i, i + batchSize);\r\n\t\t\t\t\tconst fids = batch.map(item => item.fid);\r\n\t\t\t\t\t// 发起请求获取链接\r\n\t\t\t\t\tconst 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 });\r\n\r\n\t\t\t\t\tif (!res || res.code !== 0 || !res.data) {\r\n\t\t\t\t\t\tif (res.code == 31001) throw new Error(\"提示：<br/>请先登录网盘~<br/>代码：\" + res.code);\r\n\t\t\t\t\t\tif (res.code == 23018) {\r\n\t\t\t\t\t\t\tconst fid = res.message?.match(/\\[([a-f0-9]{32})\\]/)?.[1];\r\n\t\t\t\t\t\t\tconst item = batch.find(item => item.fid === fid);\r\n\t\t\t\t\t\t\tthrow new Error(`提示：<br/>超出游客可获取大小限制<br/>请登录后获取哦~${item?.file_name ? `<br/>文件：${item.file_name}` : \"\"}`);\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (res.code || res.message) {\r\n\t\t\t\t\t\t\tthrow new Error(`提示：<br/>获取链接失败了~<br/>${res.code ? res.code : \"\"} ${res.message ? res.message : \"\"}`);\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tthrow new Error(\"提示：<br/>获取下载链接失败，刷新网页后再试试吧~\");\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// 合并响应数据\r\n\t\t\t\t\tif (res.data) {\r\n\t\t\t\t\t\tdata.push(...res.data);\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// 更新处理进度\r","sourceCodeStart":8474,"sourceCodeEnd":8510,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L8474-L8510","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nif (!res || res.code !== 0 || !res.data) {\n  if (res.code == 31001) throw new Error(\"提示：<br/>请先登录网盘~<br/>代码：\" + res.code);\n// after (guard against res being falsy first)\nif (!res || res.code !== 0 || !res.data) {\n  if (res?.code == 31001) throw new Error(\"提示：<br/>请先登录网盘~<br/>代码：31001\");\n  if (!res) throw new Error(\"获取下载地址失败：无响应，请重试\");","handlingStrategy":"try-catch","validationCode":"// pre-check login state before calling getLink\nconst loggedIn = /(?:^|;\\s*)(__pus|__puer)=/.test(document.cookie);\nif (!loggedIn) { alert('请先登录夸克网盘'); return; }","typeGuard":"const isQuarkNotLoggedIn = res => res && res.code === 31001;","tryCatchPattern":"try { await driver.getLink(); } catch (e) { if (String(e.message).includes('31001')) { redirectToQuarkLogin(); } else { throw e; } }","preventionTips":["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"],"tags":["userscript","quark","auth","session-expired","api-error-code"],"backgroundTag":"not-logged-in-cloud-drive","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}