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,