{"record":{"id":"345200ebb3e6c132","repo":"hmjz100/LinkSwift","slug":"br-345200","errorCode":null,"errorMessage":"提示：<br/>请先登录网盘~","messagePattern":"提示：<br/>请先登录网盘~","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"（改）网盘直链下载助手.user.js","lineNumber":7372,"sourceCode":"\t\t\t} else if (res.res_code == \"ShareNotFoundFlatDir\") {\r\n\t\t\t\treturn { index, downloadUrl: \"提示：<br/>请[转存]文件，之后再👉前往[我的网盘]中下载哦~\" };\r\n\t\t\t} else {\r\n\t\t\t\treturn { index, downloadUrl: \"获取下载地址失败，刷新后再试试吧~\" + (res.res_code ? res.res_code : \"\") };\r\n\t\t\t}\r\n\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.isFolder)) throw new Error(\"提示：<br/>请打开文件夹后再勾选文件~\");\r\n\t\t\tselects = selects.filter(item => !item.isFolder)\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\t\t\tconst token = base.getStorage(\"accessToken\") || await this.getToken().catch(e => {\r\n\t\t\t\tif (e instanceof Error) throw e;\r\n\t\t\t\tthrow new Error(e?.message || e || \"[天翼云盘] 获取令牌失败\");\r\n\t\t\t});\r\n\t\t\tif (!token) {\r\n\t\t\t\tthrow new Error(\"提示：<br/>请先登录网盘~\");\r\n\t\t\t}\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\t\t\tconst batchSize = 15;\r\n\t\t\tlet proc = 0;\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\t\t\tfor (let i = 0; i < selects.length; i += batchSize) {\r\n\t\t\t\tconst batch = selects.slice(i, i + batchSize);\r\n\t\t\t\tconst queue = [];\r\n\t\t\t\tbatch.forEach((item, localIndex) => {\r\n\t\t\t\t\tconst globalIndex = i + localIndex;\r\n\t\t\t\t\tqueue.push(this.getFileUrl(item, globalIndex, token)\r\n\t\t\t\t\t\t.then(val => {\r\n\t\t\t\t\t\t\tproc++;\r\n\t\t\t\t\t\t\t$doc.find(\".loading-popup .swal2-html-container\").html(`<div>已获取 ${proc} / ${selects.length} 个链接~</div>`);\r\n\t\t\t\t\t\t\treturn val;\r\n\t\t\t\t\t\t}));\r","sourceCodeStart":7354,"sourceCodeEnd":7390,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L7354-L7390","documentation":"Thrown after token retrieval in 天翼云盘 getLink() when the resulting token is falsy — i.e. neither the cached accessToken nor getToken() produced a usable token, but no exception was raised either. The script requires authentication to call the link API, so it tells the user to log into the netdisk first.","triggerScenarios":"const token = base.getStorage(\"accessToken\") || await this.getToken(); evaluates to null/undefined/empty string, then the `if (!token)` check at line 7372 fires.","commonSituations":"User never logged into 天翼云盘 in this browser; the login session expired and getToken() resolved with an empty token instead of failing; the script's storage was cleared (private browsing, cookie cleanup) removing the cached accessToken.","solutions":["Log into 天翼云盘 (cloud.189.cn) in the same browser profile, refresh the page, and retry.","Verify getToken() — if it can resolve with an empty value on unauthenticated sessions, make it throw instead so the real cause is shown.","Avoid clearing cookies/storage for the cloud site while using the script; don't use the script in private/incognito mode where sessions don't persist."],"exampleFix":"// before: getToken() may silently resolve empty\nconst token = await getToken();\n\n// after: fail loudly so users see the login problem\nconst token = await getToken();\nif (!token) throw new Error('请先登录天翼云盘再使用下载功能~');","handlingStrategy":"validation","validationCode":"const token = base.getStorage('accessToken');\nif (!token) {\n  alert('请先登录天翼云盘~');\n  return;\n}","typeGuard":"function hasToken(t) {\n  return typeof t === 'string' && t.trim().length > 0;\n}","tryCatchPattern":"try {\n  await getLink();\n} catch (e) {\n  if (e.message.includes('请先登录网盘')) {\n    window.open('https://cloud.189.cn/', '_blank');\n  } else throw e;\n}","preventionTips":["Log in to cloud.189.cn in the same browser profile before using the script.","Avoid private/incognito mode where sessions and storage don't persist.","Don't clear cookies for the cloud site mid-session.","Make getToken() throw on empty results so the root cause isn't masked."],"tags":["userscript","tianyi-cloud","auth","not-logged-in"],"backgroundTag":"not-authenticated","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}