fix(bilibili): video reply (#17440)

* fix(bilibili): video reply

* fix

* update
This commit is contained in:
Stephen Zhou
2024-11-05 00:27:55 +08:00
committed by GitHub
parent 01141f94a7
commit 4ffe081eb2
2 changed files with 15 additions and 1 deletions
+2
View File
@@ -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,
},
});
+13 -1
View File
@@ -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;
}