mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat: bilibili check cookie api
This commit is contained in:
@@ -7,10 +7,8 @@ import logger from '@/utils/logger';
|
||||
import puppeteer from '@/utils/puppeteer';
|
||||
import { JSDOM } from 'jsdom';
|
||||
|
||||
const disableConfigCookie = false;
|
||||
|
||||
const getCookie = () => {
|
||||
if (!disableConfigCookie && Object.keys(config.bilibili.cookies).length > 0) {
|
||||
if (Object.keys(config.bilibili.cookies).length > 0) {
|
||||
// Update b_lsid in cookies
|
||||
for (const key of Object.keys(config.bilibili.cookies)) {
|
||||
const cookie = config.bilibili.cookies[key];
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { APIRoute } from '@/types';
|
||||
import cacheIn from './cache';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
|
||||
export const apiRoute: APIRoute = {
|
||||
path: '/check-cookie',
|
||||
description: '检查 bilibili cookie 是否有效',
|
||||
maintainers: ['DIYgod'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler() {
|
||||
const cookie = await cacheIn.getCookie();
|
||||
|
||||
if (!cookie) {
|
||||
return {
|
||||
code: -1,
|
||||
};
|
||||
}
|
||||
|
||||
const response = await ofetch(`https://api.bilibili.com/x/web-interface/nav`, {
|
||||
headers: {
|
||||
Referer: `https://space.bilibili.com/1/`,
|
||||
Cookie: cookie as string,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
code: response.code === 0 && !!response.data.mid ? 0 : -1,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user