feat: zhihu check-cookie
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { config } from '@/config';
|
||||
import { APIRoute } from '@/types';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
|
||||
export const apiRoute: APIRoute = {
|
||||
path: '/check-cookie',
|
||||
description: '检查 zhihu cookie 是否有效',
|
||||
maintainers: ['DIYgod'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler() {
|
||||
const cookie = config.zhihu.cookies;
|
||||
|
||||
if (!cookie) {
|
||||
return {
|
||||
code: -1,
|
||||
};
|
||||
}
|
||||
|
||||
const response = await ofetch(`https://www.zhihu.com/api/v4/me?include=is_realname`, {
|
||||
headers: {
|
||||
Referer: `https://www.zhihu.com/`,
|
||||
Cookie: cookie as string,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
code: response.name ? 0 : -1,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user