From da1175d40002e78971eed8023ca151685bc78216 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 27 May 2025 20:30:20 +0800 Subject: [PATCH] feat: zhihu check-cookie --- lib/routes/zhihu/check-cookie.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/routes/zhihu/check-cookie.ts diff --git a/lib/routes/zhihu/check-cookie.ts b/lib/routes/zhihu/check-cookie.ts new file mode 100644 index 000000000..20d9f9bad --- /dev/null +++ b/lib/routes/zhihu/check-cookie.ts @@ -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, + }; +}