mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 21:24:55 +08:00
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
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";
|
|
|
|
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),
|
|
timestamp: getTime(v.pubTimeLong),
|
|
url: `https://www.thepaper.cn/newsDetail_forward_${v.contId}`,
|
|
mobileUrl: `https://m.thepaper.cn/newsDetail_forward_${v.contId}`,
|
|
})),
|
|
};
|
|
};
|