hmjz100/LinkSwift · error · Error

[百度网盘] 获取分享文件 URL 失败

Error message

[百度网盘] 获取分享文件 URL 失败

What it means

Same fallback pattern as error 12 but for the share page: thrown when `this.getShareFilesUrl(files, shareData, token)` rejects with a non-Error value. Resolving download links for files inside a shared folder requires share sign/timestamp plus a logged-in BDNDS token; failure there is re-wrapped as this generic message.

Source

Thrown at (改)网盘直链下载助手.user.js:6118

				$doc.find(".loading-popup .loading-title").html(`链接获取中`);
				$doc.find(".loading-popup .swal2-html-container").html(`<div>正在获取文件对应的下载链接~</div>`);

				files = await this.getFilesUrl(files, token).catch(e => {
					if (e instanceof Error) throw e;
					throw new Error(e?.message || e || "[百度网盘] 获取文件 URL 失败");
				});
			} else if (temp.page === "share") {
				const shareData = await this.getShareData();

				const sign = await base.get(`${config.$baidu.api.getShareSign}&surl=1${shareData.share.url}$bdstoken=${shareData.baidu.token}&logid=${base.encodeBase(shareData.baidu.id)}`);
				if (sign?.data?.sign && sign?.data?.timestamp) {
					shareData.sign = sign.data.sign;
					shareData.timestamp = sign.data.timestamp;
				}

				files = await this.getShareFilesUrl(files, shareData, token).catch(e => {
					if (e instanceof Error) throw e;
					throw new Error(e?.message || e || "[百度网盘] 获取分享文件 URL 失败");
				});
			} else {
				throw new Error("提示:<br/>页面错误~");
			}

			temp.links = [files, {
				isFolder: v => v.isdir === 1,
				getFileName: v => (v.server_filename || v.filename),
				getFileSize: v => v.size,
				getFileLink: v => {
					if (!v.dlink || !v.dlink.startsWith("http")) return v.dlink;
					const url = new URL(v.dlink);
					url.searchParams.set("access_token", token);
					return url.href;
				},
				convert: {
					aria2: `--header "User-Agent:${config.$baidu.api.ua.downloadLink}"`,
					curl: `-A "${config.$baidu.api.ua.downloadLink}"`,

View on GitHub (pinned to 417ea5e28a)

Solutions

  1. Verify the share link is still valid and open it fresh before using the script.
  2. Log into Baidu Netdisk so share downloads can be authorized.
  3. Re-enter the share passcode if the share is protected.
  4. Update the userscript; the getShareSign API signature may have changed.
Defensive patterns

Strategy: try-catch

Validate before calling

if (!shareData || !shareData.sign || !shareData.timestamp) { alert('分享信息获取失败,请重新打开分享页'); return; }

Type guard

function hasShareSign(sd) { return !!(sd && sd.sign && sd.timestamp); }

Try / catch

try { await getShareLinks(); } catch (e) { console.error('share link resolve failed:', e); if (!shareData.sign) reopenSharePage(); }

Prevention

When it happens

Trigger: On a Baidu share page (`temp.page === 'share'`), getShareFilesUrl fails: shareData.sign/timestamp missing (getShareSign returned no data), share link expired or cancelled, or the transfer/download API rejects with a non-Error payload.

Common situations: Share link has expired or been cancelled by the owner; share requires a passcode the script didn't capture; user not logged in so quota-limited share cannot be resolved; Baidu changed the share-sign API parameters.

Related errors


AI-assisted analysis of hmjz100/LinkSwift@417ea5e28a (2026-09-02). Data as JSON: /api/errors/f75188a37a6b603e. Report an issue: GitHub.