From dba22b98b31a776c36ecd597c219455d9ac20dc6 Mon Sep 17 00:00:00 2001 From: mtvpls Date: Mon, 27 Apr 2026 16:01:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E4=BA=91=E7=9B=98=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/netdisk/mobile.client.ts | 85 ++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/src/lib/netdisk/mobile.client.ts b/src/lib/netdisk/mobile.client.ts index 0f1ff17..8add420 100644 --- a/src/lib/netdisk/mobile.client.ts +++ b/src/lib/netdisk/mobile.client.ts @@ -221,48 +221,57 @@ export async function getMobileSharePlayUrl(contentId: string, linkID: string, a }, }; - const authCandidates = authorization ? [undefined, authorization] : [undefined]; let lastErrorMessage = '未获取到移动云盘播放地址'; - for (const auth of authCandidates) { - try { - const raw = await postPlain( - `${BASE_URL}getContentInfoFromOutLink`, - requestPayload, - false, - auth - ); - let parsed: any; - try { - parsed = JSON.parse(raw); - } catch { - lastErrorMessage = '移动云盘播放接口返回异常'; - continue; - } + try { + const response = await fetch(`${BASE_URL}getContentInfoFromOutLink`, { + method: 'POST', + headers: { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36', + Accept: 'application/json, text/plain, */*', + 'Accept-Encoding': 'gzip, deflate, br, zstd', + 'Content-Type': 'application/json', + ...(authorization ? { authorization: ensureHeaderSafeAuthorization(authorization) } : {}), + }, + body: JSON.stringify(requestPayload), + cache: 'no-store', + }); - const contentInfo = parsed?.data?.contentInfo || parsed?.contentInfo; - const playUrl = - contentInfo?.presentURL || - contentInfo?.presentUrl || - contentInfo?.playUrl || - contentInfo?.url || - parsed?.data?.presentURL || - parsed?.data?.url; - - if (playUrl) { - return playUrl; - } - - lastErrorMessage = - parsed?.message || - parsed?.msg || - parsed?.data?.message || - parsed?.data?.msg || - '未获取到移动云盘播放地址'; - } catch (error) { - lastErrorMessage = - error instanceof Error ? error.message : '未获取到移动云盘播放地址'; + const raw = await response.text(); + if (!response.ok) { + throw new Error(`移动云盘播放接口请求失败 (${response.status})`); } + + let parsed: any; + try { + parsed = typeof raw === 'string' ? JSON.parse(raw) : raw; + } catch { + throw new Error('移动云盘播放接口返回异常'); + } + + const playUrl = + parsed?.data?.contentInfo?.presentURL || + parsed?.data?.contentInfo?.presentUrl || + parsed?.data?.contentInfo?.playUrl || + parsed?.data?.contentInfo?.url || + parsed?.contentInfo?.presentURL || + parsed?.contentInfo?.presentUrl || + parsed?.data?.presentURL || + parsed?.data?.url; + + if (playUrl) { + return playUrl; + } + + lastErrorMessage = + parsed?.message || + parsed?.msg || + parsed?.data?.message || + parsed?.data?.msg || + '未获取到移动云盘播放地址'; + } catch (error) { + lastErrorMessage = + error instanceof Error ? error.message : '未获取到移动云盘播放地址'; } throw new Error(lastErrorMessage);