mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 13:14:55 +08:00
✨ feat: 新增 虎嗅 & 爱范儿
This commit is contained in:
@@ -46,6 +46,8 @@
|
||||
| 稀土掘金 | 热榜 | juejin | 🟢 |
|
||||
| 腾讯新闻 | 热点榜 | qq-news | 🟢 |
|
||||
| 网易新闻 | 热点榜 | netease-news | 🟢 |
|
||||
| 虎嗅 | 24小时 | huxiu | 🟢 |
|
||||
| 爱范儿 | 快讯 | ifanr | 🟢 |
|
||||
| 英雄联盟 | 更新公告 | lol | 🟢 |
|
||||
| 原神 | 最新消息 | genshin | 🟢 |
|
||||
| 崩坏3 | 最新动态 | honkai | 🟢 |
|
||||
|
||||
@@ -3,13 +3,13 @@ import { config } from "./config.js";
|
||||
import logger from "./utils/logger.js";
|
||||
import app from "./app.js";
|
||||
|
||||
logger.info(`🔥 DailyHot API 成功在端口 ${config.PORT} 上运行`);
|
||||
logger.info(`🔗 Local: 👉 http://localhost:${config.PORT}`);
|
||||
|
||||
// 启动服务器
|
||||
const server = serve({
|
||||
fetch: app.fetch,
|
||||
port: config.PORT,
|
||||
});
|
||||
|
||||
logger.info(`🔥 DailyHot API 成功在端口 ${config.PORT} 上运行`);
|
||||
logger.info(`🔗 Local: 👉 http://localhost:${config.PORT}`);
|
||||
|
||||
export default server;
|
||||
|
||||
@@ -214,4 +214,21 @@ export type RouterType = {
|
||||
url: string;
|
||||
pic: string;
|
||||
};
|
||||
huxiu: {
|
||||
object_id: number;
|
||||
content: string;
|
||||
url: string;
|
||||
user_info: {
|
||||
username: string;
|
||||
};
|
||||
};
|
||||
ifanr: {
|
||||
buzz_original_url: string;
|
||||
id: number;
|
||||
post_content: string;
|
||||
post_id: number;
|
||||
post_title: string;
|
||||
like_count: number;
|
||||
comment_count: number;
|
||||
};
|
||||
};
|
||||
|
||||
51
src/routes/huxiu.ts
Normal file
51
src/routes/huxiu.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import type { RouterData } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "huxiu",
|
||||
title: "虎嗅",
|
||||
type: "24小时",
|
||||
link: "https://www.huxiu.com/moment/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
|
||||
// 标题处理
|
||||
const titleProcessing = (text: string) => {
|
||||
const paragraphs = text.split("<br><br>");
|
||||
const title = paragraphs.shift().replace(/。$/, "");
|
||||
const intro = paragraphs.join("<br><br>");
|
||||
return { title, intro };
|
||||
};
|
||||
|
||||
const getList = async (noCache: boolean) => {
|
||||
const url = `https://www.huxiu.com/moment/`;
|
||||
const result = await get({
|
||||
url,
|
||||
noCache,
|
||||
});
|
||||
// 正则查找
|
||||
const pattern =
|
||||
/<script>[\s\S]*?window\.__INITIAL_STATE__\s*=\s*(\{[\s\S]*?\});[\s\S]*?<\/script>/;
|
||||
const matchResult = result.data.match(pattern);
|
||||
const jsonObject = JSON.parse(matchResult[1]).moment.momentList.moment_list.datalist;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: jsonObject.map((v: RouterType["huxiu"]) => ({
|
||||
id: v.object_id,
|
||||
title: titleProcessing(v.content).title,
|
||||
desc: titleProcessing(v.content).intro,
|
||||
author: v.user_info.username,
|
||||
url: v.url || "https://www.huxiu.com/moment/",
|
||||
mobileUrl: v.url || "https://m.huxiu.com/moment/",
|
||||
})),
|
||||
};
|
||||
};
|
||||
37
src/routes/ifanr.ts
Normal file
37
src/routes/ifanr.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { RouterData } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "ifanr",
|
||||
title: "爱范儿",
|
||||
type: "快讯",
|
||||
description: "15秒了解全球新鲜事",
|
||||
link: "https://www.ifanr.com/digest/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
|
||||
const getList = async (noCache: boolean) => {
|
||||
const url = "https://sso.ifanr.com/api/v5/wp/buzz/?limit=20&offset=0";
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.objects;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: list.map((v: RouterType["ifanr"]) => ({
|
||||
id: v.id,
|
||||
title: v.post_title,
|
||||
desc: v.post_content,
|
||||
hot: v.like_count || v.comment_count,
|
||||
url: `https://www.ifanr.com/${v.id}` || v.buzz_original_url,
|
||||
mobileUrl: `https://www.ifanr.com/digest/${v.id}` || v.buzz_original_url,
|
||||
})),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user