From c6a8c137728bce71810d053ebe5738a516d8b0ee Mon Sep 17 00:00:00 2001 From: ZHLH Date: Mon, 12 May 2025 12:08:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9Acoo?= =?UTF-8?q?kie=E8=8E=B7=E5=8F=96=E7=9F=A5=E4=B9=8E=E7=83=AD=E6=A6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.ts | 2 ++ src/routes/zhihu.ts | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index 3e4b630..1147701 100644 --- a/src/config.ts +++ b/src/config.ts @@ -15,6 +15,7 @@ export type Config = { REDIS_HOST: string; REDIS_PORT: number; REDIS_PASSWORD: string; + ZHIHU_COOKIE: string; }; // 验证并提取环境变量 @@ -51,4 +52,5 @@ export const config: Config = { REDIS_HOST: getEnvVariable("REDIS_HOST") || "127.0.0.1", REDIS_PORT: getNumericEnvVariable("REDIS_PORT", 6379), REDIS_PASSWORD: getEnvVariable("REDIS_PASSWORD") || "", + ZHIHU_COOKIE: getEnvVariable("ZHIHU_COOKIE") || "", }; diff --git a/src/routes/zhihu.ts b/src/routes/zhihu.ts index d8302de..00aa902 100644 --- a/src/routes/zhihu.ts +++ b/src/routes/zhihu.ts @@ -2,6 +2,7 @@ import type { RouterData } from "../types.js"; import type { RouterType } from "../router.types.js"; import { get } from "../utils/getData.js"; import { getTime } from "../utils/getTime.js"; +import { config } from "../config.js" export const handleRoute = async (_: undefined, noCache: boolean) => { const listData = await getList(noCache); @@ -18,7 +19,15 @@ export const handleRoute = async (_: undefined, noCache: boolean) => { const getList = async (noCache: boolean) => { const url = `https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=50&desktop=true`; - const result = await get({ url, noCache }); + const result = await get({ + url, + noCache, + ...(config.ZHIHU_COOKIE && { + headers: { + Cookie: config.ZHIHU_COOKIE + } + }) + }); const list = result.data.data; return { ...result,