From faa6f0225d84fca7a826d339c5343108c3013e8b Mon Sep 17 00:00:00 2001 From: XiaoZhu Date: Wed, 15 Oct 2025 17:12:01 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E9=85=8D?= =?UTF-8?q?=E7=BD=AERedis=E6=95=B0=E6=8D=AE=E5=BA=93=E7=B4=A2=E5=BC=95=20f?= =?UTF-8?q?ix:=20=E4=BF=AE=E5=A4=8D=E5=BE=AE=E5=8D=9A=E7=83=AD=E6=A6=9C?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.ts | 2 ++ src/router.types.d.ts | 3 ++- src/routes/weibo.ts | 2 +- src/utils/cache.ts | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index 1147701..33397b8 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; + REDIS_DB: number; ZHIHU_COOKIE: string; }; @@ -52,5 +53,6 @@ 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") || "", }; diff --git a/src/router.types.d.ts b/src/router.types.d.ts index bed6b6b..b87ebb7 100644 --- a/src/router.types.d.ts +++ b/src/router.types.d.ts @@ -89,7 +89,8 @@ export type RouterType = { word_scheme: string; note: string; flag_desc: string; - num: number; + // num: number; + desc_extr: number; onboard_time: number; }; zhihu: { diff --git a/src/routes/weibo.ts b/src/routes/weibo.ts index ae8f5b1..54214f0 100644 --- a/src/routes/weibo.ts +++ b/src/routes/weibo.ts @@ -44,7 +44,7 @@ const getList = async (noCache: boolean) => { desc: key, // author: v.flag_desc, timestamp: getTime(v.onboard_time), - // hot: v.num, + 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), From 10db165fc41c8fffcbad6401afe70a103cffd0c6 Mon Sep 17 00:00:00 2001 From: XiaoZhu Date: Wed, 15 Oct 2025 17:25:23 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E9=85=8D?= =?UTF-8?q?=E7=BD=AERedis=E6=95=B0=E6=8D=AE=E5=BA=93=E7=B4=A2=E5=BC=95=20f?= =?UTF-8?q?ix:=20=E4=BF=AE=E5=A4=8D=E5=BE=AE=E5=8D=9A=E7=83=AD=E6=A6=9C?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.example b/.env.example index adb5f0e..d6d32ec 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 From 0a3869f1a267b90e36e9547d1383a5e215d851d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8C=AA=E7=8C=AA=E5=85=AC=E4=B8=BBz?= <1293383305@qq.com> Date: Fri, 17 Oct 2025 14:00:48 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E5=BE=AE=E5=8D=9A=E7=83=AD=E6=90=9C=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E5=B9=BF=E5=91=8A=EF=BC=88FILTER=5FWEIBO=5FADVERTISEMENT=3Dtru?= =?UTF-8?q?e=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 5 ++++- src/config.ts | 2 ++ src/router.types.d.ts | 1 + src/routes/weibo.ts | 34 +++++++++++++++++++++------------- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/.env.example b/.env.example index d6d32ec..3f60385 100644 --- a/.env.example +++ b/.env.example @@ -27,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 33397b8..380ab86 100644 --- a/src/config.ts +++ b/src/config.ts @@ -17,6 +17,7 @@ export type Config = { REDIS_PASSWORD: string; REDIS_DB: number; ZHIHU_COOKIE: string; + FILTER_WEIBO_ADVERTISEMENT: boolean; }; // 验证并提取环境变量 @@ -55,4 +56,5 @@ export const config: Config = { 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 b87ebb7..89517b2 100644 --- a/src/router.types.d.ts +++ b/src/router.types.d.ts @@ -92,6 +92,7 @@ export type RouterType = { // 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 54214f0..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.desc_extr, - 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, + }; + }), }; };