🦄 refactor: Refactoring using hono

This commit is contained in:
imsyy
2024-04-08 16:35:58 +08:00
parent 7459858767
commit 34ab73a3f1
95 changed files with 3555 additions and 6345 deletions

36
src/routes/thepaper.ts Normal file
View 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}`,
})),
};
};