{"record":{"id":"a7a55c1e35a76246","repo":"hmjz100/LinkSwift","slug":"url-a7a55c","errorCode":null,"errorMessage":"[阿里云盘] 获取文件 URL 失败","messagePattern":"\\[阿里云盘\\] 获取文件 URL 失败","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"（改）网盘直链下载助手.user.js","lineNumber":6593,"sourceCode":"\t\t\t}\r\n\r\n\t\t\t// 获取选择的文件列表\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.type !== \"file\")) throw new Error(\"提示：<br/>请打开文件夹后再勾选文件~\");\r\n\r\n\t\t\t$doc.find(\".loading-popup .loading-title\").html(`链接获取中`);\r\n\t\t\t$doc.find(\".loading-popup .swal2-html-container\").html(`<div>正在获取文件对应的下载链接~</div>`);\r\n\r\n\t\t\tif (temp.page === \"home\") {\r\n\t\t\t\tselects = selects.filter(item => item.type === \"file\");\r\n\t\t\t\tconst token = base.getStorage(\"token\");\r\n\t\t\t\tif (!token || !token.token_type || !token.access_token) {\r\n\t\t\t\t\treturn message.error(\"提示：<br/>请先登录网盘~\");\r\n\t\t\t\t}\r\n\t\t\t\tselects = await this.getFilesUrl(selects, `${token.token_type} ${token.access_token}`).catch(e => {\r\n\t\t\t\t\tif (e instanceof Error) throw e;\r\n\t\t\t\t\tthrow new Error(e?.message || e || \"[阿里云盘] 获取文件 URL 失败\");\r\n\t\t\t\t});\r\n\t\t\t} else {\r\n\t\t\t\tthrow new Error(\"提示：<br/>页面错误~\");\r\n\t\t\t}\r\n\r\n\t\t\ttemp.links = [selects, {\r\n\t\t\t\tisFolder: v => v.type === \"folder\",\r\n\t\t\t\tgetFileName: v => v.name,\r\n\t\t\t\tgetFileSize: v => v.size,\r\n\t\t\t\tgetFileLink: v => (v.downloadUrl || v.url),\r\n\t\t\t\tconvert: {\r\n\t\t\t\t\taria2: `--header \"Referer:https://${location.host}/\"`,\r\n\t\t\t\t\tcurl: `-e \"https://${location.host}/\"`,\r\n\t\t\t\t\tbitcomet: `&refer=${encodeURIComponent(`https://${location.host}/`)}`\r\n\t\t\t\t},\r\n\t\t\t\ttooltip: config.$aliyun.dom\r\n\t\t\t}];\r\n\t\t\tbase.showMainDialog(config.base.dom.button[temp.mode].title, base.generateDOM(temp.links), config.base.dom.button[temp.mode].footer);\r","sourceCodeStart":6575,"sourceCodeEnd":6611,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L6575-L6611","documentation":"Fallback wrapper for Aliyun Drive's `this.getFilesUrl(selects, token)` rejection when the thrown value is not an Error instance. Resolving direct URLs calls Aliyun Drive's API with a Bearer token (`token_type access_token` from storage); API-side failures surface as this generic message unless an Error was already thrown.","triggerScenarios":"getFilesUrl's requests to Aliyun Drive's download-link API reject with a non-Error: expired/revoked access_token, 403/429 from Aliyun risk control, API path change, or network failure yielding a plain-string/object rejection.","commonSituations":"Aliyun Drive access tokens expire (they are short-lived) while stored in script storage; user re-logged in elsewhere invalidating the token; Aliyun tightened API rate limits; userscript outdated after an Aliyun API revision.","solutions":["Re-obtain the token: log out/in to Aliyun Drive (or use the script's token-refresh) so storage holds a fresh access_token.","Update the userscript to the latest version for current API endpoints.","Retry after a cooldown if rate-limited (HTTP 429).","Inspect DevTools Network for the failing request's status/body to identify the real error."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const token = base.getStorage('token');\nif (!token || !token.token_type || !token.access_token) { alert('请先登录网盘并刷新 token'); return; }","typeGuard":"function hasValidToken(t) { return !!(t && t.token_type && t.access_token); }","tryCatchPattern":"try { await getLinks(); } catch (e) { console.error('Aliyun link fetch failed:', e); if (await isTokenExpired()) { await refreshToken(); retry(); } }","preventionTips":["Refresh the Aliyun Drive access_token before it expires (tokens are short-lived)","Re-login when downloads start failing to obtain a fresh token","Keep the userscript updated for Aliyun API revisions","Back off and retry after rate-limit responses (HTTP 429)"],"tags":["userscript","aliyun-drive","api","token","network"],"backgroundTag":"api-request-failed","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}