diff --git a/.env.example b/.env.example index adb5f0e..3f60385 100644 --- a/.env.example +++ b/.env.example @@ -15,6 +15,7 @@ DISALLOW_ROBOT=true REDIS_HOST="127.0.0.1" REDIS_PORT=6379 REDIS_PASSWORD="" +REDIS_DB=0 # 缓存时长( 秒 ) CACHE_TTL=3600 @@ -26,4 +27,7 @@ REQUEST_TIMEOUT=6000 USE_LOG_FILE=true # RSS Mode -RSS_MODE=false \ No newline at end of file +RSS_MODE=false + +# Weibo +FILTER_WEIBO_ADVERTISEMENT=false \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index 1147701..380ab86 100644 --- a/src/config.ts +++ b/src/config.ts @@ -15,7 +15,9 @@ export type Config = { REDIS_HOST: string; REDIS_PORT: number; REDIS_PASSWORD: string; + REDIS_DB: number; ZHIHU_COOKIE: string; + FILTER_WEIBO_ADVERTISEMENT: boolean; }; // 验证并提取环境变量 @@ -52,5 +54,7 @@ export const config: Config = { REDIS_HOST: getEnvVariable("REDIS_HOST") || "127.0.0.1", REDIS_PORT: getNumericEnvVariable("REDIS_PORT", 6379), REDIS_PASSWORD: getEnvVariable("REDIS_PASSWORD") || "", + REDIS_DB: getNumericEnvVariable("REDIS_DB", 0), ZHIHU_COOKIE: getEnvVariable("ZHIHU_COOKIE") || "", + FILTER_WEIBO_ADVERTISEMENT: getBooleanEnvVariable("FILTER_WEIBO_ADVERTISEMENT", false), }; diff --git a/src/router.types.d.ts b/src/router.types.d.ts index bed6b6b..89517b2 100644 --- a/src/router.types.d.ts +++ b/src/router.types.d.ts @@ -89,8 +89,10 @@ export type RouterType = { word_scheme: string; note: string; flag_desc: string; - num: number; + // num: number; + desc_extr: number; onboard_time: number; + pic: string; }; zhihu: { target: { diff --git a/src/routes/weibo.ts b/src/routes/weibo.ts index ae8f5b1..bf6ddfe 100644 --- a/src/routes/weibo.ts +++ b/src/routes/weibo.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"; export const handleRoute = async (_: undefined, noCache: boolean) => { const listData = await getList(noCache); @@ -36,18 +37,25 @@ const getList = async (noCache: boolean) => { const list = result.data.data.cards?.[0]?.card_group; return { ...result, - data: list.map((v: RouterType["weibo"]) => { - const key = v.word_scheme ? v.word_scheme : `#${v.desc}`; - return { - id: v.itemid, - title: v.desc, - desc: key, - // author: v.flag_desc, - timestamp: getTime(v.onboard_time), - // hot: v.num, - url: `https://s.weibo.com/weibo?q=${encodeURIComponent(key)}&t=31&band_rank=1&Refer=top`, - mobileUrl: v?.scheme, - }; - }), + data: list + .filter( + (v: RouterType["weibo"]) => + !( + v?.pic === "https://simg.s.weibo.com/20210408_search_point_orange.png" && + config.FILTER_WEIBO_ADVERTISEMENT + ), + ) + .map((v: RouterType["weibo"]) => { + const key = v.word_scheme ?? `#${v.desc}`; + return { + id: v.itemid, + title: v.desc, + desc: key, + timestamp: getTime(v.onboard_time), + hot: v.desc_extr, + url: `https://s.weibo.com/weibo?q=${encodeURIComponent(key)}&t=31&band_rank=1&Refer=top`, + mobileUrl: v?.scheme, + }; + }), }; }; diff --git a/src/utils/cache.ts b/src/utils/cache.ts index 958cc87..8c943f5 100644 --- a/src/utils/cache.ts +++ b/src/utils/cache.ts @@ -26,6 +26,7 @@ const redis = new Redis({ host: config.REDIS_HOST, port: config.REDIS_PORT, password: config.REDIS_PASSWORD, + db: config.REDIS_DB, maxRetriesPerRequest: 5, // 重试策略:最小延迟 50ms,最大延迟 2s retryStrategy: (times) => Math.min(times * 50, 2000),