mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 13:14:55 +08:00
🦄 refactor: Refactoring using hono
This commit is contained in:
36
src/routes/thepaper.ts
Normal file
36
src/routes/thepaper.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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: "thepaper",
|
||||
title: "澎湃新闻",
|
||||
type: "热榜",
|
||||
link: "https://www.thepaper.cn/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
|
||||
const getList = async (noCache: boolean) => {
|
||||
const url = `https://cache.thepaper.cn/contentapi/wwwIndex/rightSidebar`;
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.hotNews;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: list.map((v: RouterType["thepaper"]) => ({
|
||||
id: v.contId,
|
||||
title: v.name,
|
||||
cover: v.pic,
|
||||
hot: Number(v.praiseTimes),
|
||||
url: `https://www.thepaper.cn/newsDetail_forward_${v.contId}`,
|
||||
mobileUrl: `https://m.thepaper.cn/newsDetail_forward_${v.contId}`,
|
||||
})),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user