feat: retry bilibili dynami with different cookie
This commit is contained in:
parent
4cd3cabc2d
commit
314f8a6a87
|
|
@ -7,8 +7,8 @@ import logger from '@/utils/logger';
|
|||
import { getPuppeteerPage } from '@/utils/puppeteer';
|
||||
import { JSDOM } from 'jsdom';
|
||||
|
||||
const getCookie = () => {
|
||||
if (Object.keys(config.bilibili.cookies).length > 0) {
|
||||
const getCookie = (disableConfig = false) => {
|
||||
if (Object.keys(config.bilibili.cookies).length > 0 && !disableConfig) {
|
||||
// Update b_lsid in cookies
|
||||
for (const key of Object.keys(config.bilibili.cookies)) {
|
||||
const cookie = config.bilibili.cookies[key];
|
||||
|
|
|
|||
|
|
@ -243,18 +243,30 @@ async function handler(ctx) {
|
|||
const directLink = fallback(undefined, queryToBoolean(routeParams.directLink), false);
|
||||
const hideGoods = fallback(undefined, queryToBoolean(routeParams.hideGoods), false);
|
||||
|
||||
const cookie = await cacheIn.getCookie();
|
||||
const getDynamic = async (cookie: string) => {
|
||||
const params = utils.addDmVerifyInfo(`offset=${offset}&host_mid=${uid}&platform=web&features=itemOpusStyle,listOnlyfans,opusBigCover,onlyfansVote`, utils.getDmImgList());
|
||||
const response = await got(`https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?${params}`, {
|
||||
headers: {
|
||||
Referer: `https://space.bilibili.com/${uid}/`,
|
||||
Cookie: cookie,
|
||||
},
|
||||
});
|
||||
const body = JSONbig.parse(response.body);
|
||||
return body;
|
||||
};
|
||||
|
||||
let body: BilibiliWebDynamicResponse;
|
||||
|
||||
const cookie = (await cacheIn.getCookie()) as string;
|
||||
body = await getDynamic(cookie);
|
||||
|
||||
const params = utils.addDmVerifyInfo(`offset=${offset}&host_mid=${uid}&platform=web&features=itemOpusStyle,listOnlyfans,opusBigCover,onlyfansVote`, utils.getDmImgList());
|
||||
const response = await got(`https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?${params}`, {
|
||||
headers: {
|
||||
Referer: `https://space.bilibili.com/${uid}/`,
|
||||
Cookie: cookie,
|
||||
},
|
||||
});
|
||||
const body = JSONbig.parse(response.body);
|
||||
if (body?.code === -352) {
|
||||
throw new Error('Request failed, please try again.');
|
||||
const cookie = (await cacheIn.getCookie(true)) as string;
|
||||
body = await getDynamic(cookie);
|
||||
|
||||
if (body?.code === -352) {
|
||||
throw new Error('遇到源站风控校验,请稍后再试');
|
||||
}
|
||||
}
|
||||
const items = (body as BilibiliWebDynamicResponse)?.data?.items;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue