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] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E5=BE=AE=E5=8D=9A=E7=83=AD=E6=90=9C=E4=B8=AD=E7=9A=84=E5=B9=BF?= =?UTF-8?q?=E5=91=8A=EF=BC=88FILTER=5FWEIBO=5FADVERTISEMENT=3Dtrue?= =?UTF-8?q?=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, + }; + }), }; };