mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 05:04:56 +08:00
feat: 支持过滤微博热搜中的广告(FILTER_WEIBO_ADVERTISEMENT=true)
This commit is contained in:
@@ -27,4 +27,7 @@ REQUEST_TIMEOUT=6000
|
||||
USE_LOG_FILE=true
|
||||
|
||||
# RSS Mode
|
||||
RSS_MODE=false
|
||||
RSS_MODE=false
|
||||
|
||||
# Weibo
|
||||
FILTER_WEIBO_ADVERTISEMENT=false
|
||||
@@ -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),
|
||||
};
|
||||
|
||||
1
src/router.types.d.ts
vendored
1
src/router.types.d.ts
vendored
@@ -92,6 +92,7 @@ export type RouterType = {
|
||||
// num: number;
|
||||
desc_extr: number;
|
||||
onboard_time: number;
|
||||
pic: string;
|
||||
};
|
||||
zhihu: {
|
||||
target: {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user