feat: 支持指定cookie获取知乎热榜

This commit is contained in:
ZHLH
2025-05-12 12:08:51 +08:00
committed by lh
parent 46cb5ccec2
commit c6a8c13772
2 changed files with 12 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ export type Config = {
REDIS_HOST: string; REDIS_HOST: string;
REDIS_PORT: number; REDIS_PORT: number;
REDIS_PASSWORD: string; REDIS_PASSWORD: string;
ZHIHU_COOKIE: string;
}; };
// 验证并提取环境变量 // 验证并提取环境变量
@@ -51,4 +52,5 @@ export const config: Config = {
REDIS_HOST: getEnvVariable("REDIS_HOST") || "127.0.0.1", REDIS_HOST: getEnvVariable("REDIS_HOST") || "127.0.0.1",
REDIS_PORT: getNumericEnvVariable("REDIS_PORT", 6379), REDIS_PORT: getNumericEnvVariable("REDIS_PORT", 6379),
REDIS_PASSWORD: getEnvVariable("REDIS_PASSWORD") || "", REDIS_PASSWORD: getEnvVariable("REDIS_PASSWORD") || "",
ZHIHU_COOKIE: getEnvVariable("ZHIHU_COOKIE") || "",
}; };

View File

@@ -2,6 +2,7 @@ import type { RouterData } from "../types.js";
import type { RouterType } from "../router.types.js"; import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js"; import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
import { config } from "../config.js"
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const listData = await getList(noCache); const listData = await getList(noCache);
@@ -18,7 +19,15 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
const getList = async (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 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; const list = result.data.data;
return { return {
...result, ...result,