diff --git a/lib/routes/bilibili/reply.ts b/lib/routes/bilibili/reply.ts index cb63d4cc6..25a69415c 100644 --- a/lib/routes/bilibili/reply.ts +++ b/lib/routes/bilibili/reply.ts @@ -33,11 +33,13 @@ async function handler(ctx) { } const link = `https://www.bilibili.com/video/${bvid || `av${aid}`}`; + const cookie = await cache.getCookie(); const response = await got({ method: 'get', url: `https://api.bilibili.com/x/v2/reply?type=1&oid=${aid}&sort=0`, headers: { Referer: link, + Cookie: cookie, }, }); diff --git a/lib/utils/got.ts b/lib/utils/got.ts index 1f623d9d6..cf03e74b2 100644 --- a/lib/utils/got.ts +++ b/lib/utils/got.ts @@ -1,6 +1,10 @@ import { destr } from 'destr'; import ofetch from '@/utils/ofetch'; +function isObject(o) { + return o !== null && typeof o === 'object' && Array.isArray(o) === false; +} + const getFakeGot = (defaultOptions?: any) => { const fakeGot = (request, options?: any) => { if (!(typeof request === 'string' || request instanceof Request) && request.url) { @@ -35,7 +39,15 @@ const getFakeGot = (defaultOptions?: any) => { delete options.form; } if (options?.searchParams) { - request += '?' + new URLSearchParams(options.searchParams).toString(); + request += + '?' + + new URLSearchParams( + isObject(options.searchParams) + ? Object.entries(options.searchParams) + .filter(([, value]) => value !== undefined) + .map(([key, value]) => [key, String(value)]) + : options.searchParams + ).toString(); delete options.searchParams; }