Files
DailyHotApi/src/routes/weatheralarm.ts
imsyy 098b80865b 🐞 fix: 部分类型错误
- 新增 米游社 综合接口
2024-12-03 18:09:32 +08:00

49 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { RouterData, ListContext, Options } 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 (c: ListContext, noCache: boolean) => {
const province = c.req.query("province") || "";
const { fromCache, data, type, updateTime } = await getList({ province }, noCache);
const routeData: RouterData = {
name: "weatheralarm",
title: "中央气象台",
type: type || "全国气象预警",
params: {
province: {
name: "预警区域",
value: "省份名称( 例如:广东省 ",
},
},
link: "http://nmc.cn/publish/alarm.html",
total: data?.length || 0,
updateTime,
fromCache,
data,
};
return routeData;
};
const getList = async (options: Options, noCache: boolean) => {
const { province } = options;
const url = `http://www.nmc.cn/rest/findAlarm?pageNo=1&pageSize=20&signaltype=&signallevel=&province=${encodeURIComponent(province || "")}`;
const result = await get({ url, noCache });
const list = result.data.data.page.list;
return {
fromCache: result.fromCache,
updateTime: result.updateTime,
type: province + "气象预警",
data: list.map((v: RouterType["weatheralarm"]) => ({
id: v.alertid,
title: v.title,
desc: v.issuetime + " " + v.title,
cover: v.pic,
timestamp: getTime(v.issuetime),
hot: null,
url: `http://nmc.cn${v.url}`,
mobileUrl: `http://nmc.cn${v.url}`,
})),
};
};