feat: bilibili check cookie api

This commit is contained in:
DIYgod
2025-05-27 13:36:48 +08:00
parent 8520db3e13
commit 5cc315f6c2
2 changed files with 32 additions and 3 deletions
+1 -3
View File
@@ -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];
+31
View File
@@ -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,
};
}