mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 05:04:56 +08:00
@@ -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") || "",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user