mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 13:14:55 +08:00
✨ feat: 新增一些接口
This commit is contained in:
54
src/routes/51cto.ts
Normal file
54
src/routes/51cto.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import type { RouterData } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { getToken, sign } from "../utils/getToken/51cto.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: "51cto",
|
||||
title: "51CTO",
|
||||
type: "推荐榜",
|
||||
link: "https://www.51cto.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
|
||||
const getList = async (noCache: boolean) => {
|
||||
const url = `https://api-media.51cto.com/index/index/recommend`;
|
||||
const params = {
|
||||
page: 1,
|
||||
page_size: 50,
|
||||
limit_time: 0,
|
||||
name_en: "",
|
||||
};
|
||||
const timestamp = Date.now();
|
||||
const token = (await getToken()) as string;
|
||||
const result = await get({
|
||||
url,
|
||||
params: {
|
||||
...params,
|
||||
timestamp,
|
||||
token,
|
||||
sign: sign("index/index/recommend", params, timestamp, token),
|
||||
},
|
||||
noCache,
|
||||
});
|
||||
const list = result.data.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: list.map((v: RouterType["51cto"]) => ({
|
||||
id: v.source_id,
|
||||
title: v.title,
|
||||
cover: v.cover,
|
||||
desc: v.abstract,
|
||||
url: v.url,
|
||||
mobileUrl: v.url,
|
||||
})),
|
||||
};
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getBiliWbi from "../utils/getBiliWbi.js";
|
||||
import getBiliWbi from "../utils/getToken/bilibili.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "0";
|
||||
|
||||
76
src/routes/earthquake.ts
Normal file
76
src/routes/earthquake.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
|
||||
const mappings = {
|
||||
O_TIME: "发震时刻(UTC+8)",
|
||||
LOCATION_C: "参考位置",
|
||||
M: "震级(M)",
|
||||
EPI_LAT: "纬度(°)",
|
||||
EPI_LON: "经度(°)",
|
||||
EPI_DEPTH: "深度(千米)",
|
||||
SAVE_TIME: "录入时间",
|
||||
};
|
||||
|
||||
const typeMappings = {
|
||||
1: "最近24小时地震信息",
|
||||
2: "最近48小时地震信息",
|
||||
3: "最近7天地震信息",
|
||||
4: "最近30天地震信息",
|
||||
5: "最近一年3.0级以上地震信息",
|
||||
6: "最近一年地震信息",
|
||||
7: "最近一年3.0级以下地震",
|
||||
8: "最近一年4.0级以上地震信息",
|
||||
9: "最近一年5.0级以上地震信息",
|
||||
0: "最近一年6.0级以上地震信息",
|
||||
};
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "5";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "earthquake",
|
||||
title: "中国地震台",
|
||||
type: "地震速报",
|
||||
parameData: {
|
||||
type: {
|
||||
name: "速报分类",
|
||||
type: {
|
||||
...typeMappings,
|
||||
},
|
||||
},
|
||||
},
|
||||
link: "https://news.ceic.ac.cn/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
|
||||
const getList = async (options: Options, noCache: boolean) => {
|
||||
const { type } = options;
|
||||
const url = `http://www.ceic.ac.cn/ajax/speedsearch?num=${type}`;
|
||||
const result = await get({ url, noCache });
|
||||
const data = result.data.replace(/,"page":"(.*?)","num":/, ',"num":');
|
||||
const list = JSON.parse(data.substring(1, data.length - 1)).shuju;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: list.map((v: RouterType["earthquake"]) => {
|
||||
const contentBuilder = [];
|
||||
const { NEW_DID, LOCATION_C, M } = v;
|
||||
for (const mappingsKey in mappings) {
|
||||
contentBuilder.push(`${mappings[mappingsKey]}:${v[mappingsKey]}`);
|
||||
}
|
||||
return {
|
||||
id: NEW_DID,
|
||||
title: `${LOCATION_C}发生${M}级地震`,
|
||||
desc: contentBuilder.join("\n"),
|
||||
url: `https://news.ceic.ac.cn/${NEW_DID}.html`,
|
||||
mobileUrl: `https://news.ceic.ac.cn/${NEW_DID}.html`,
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
@@ -5,7 +5,7 @@ import { get } from "../utils/getData.js";
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "ithome",
|
||||
name: "ithome-xijiayi",
|
||||
title: "IT之家「喜加一」",
|
||||
type: "最新动态",
|
||||
description: "最新最全的「喜加一」游戏动态尽在这里!",
|
||||
|
||||
48
src/routes/v2ex.ts
Normal file
48
src/routes/v2ex.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "hot";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "v2ex",
|
||||
title: "V2EX",
|
||||
type: "主题榜",
|
||||
parameData: {
|
||||
type: {
|
||||
name: "榜单分类",
|
||||
type: {
|
||||
hot: "最热主题",
|
||||
latest: "最新主题",
|
||||
},
|
||||
},
|
||||
},
|
||||
link: "https://www.v2ex.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
|
||||
const getList = async (options: Options, noCache: boolean) => {
|
||||
const { type } = options;
|
||||
const url = `https://www.v2ex.com/api/topics/${type}.json`;
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: list.map((v: RouterType["v2ex"]) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
desc: v.content,
|
||||
author: v.member.username,
|
||||
hot: v.replies,
|
||||
url: v.url,
|
||||
mobileUrl: v.url,
|
||||
})),
|
||||
};
|
||||
};
|
||||
45
src/routes/weatheralarm.ts
Normal file
45
src/routes/weatheralarm.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.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 || "全国气象预警",
|
||||
parameData: {
|
||||
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,
|
||||
url: `http://nmc.cn${v.url}`,
|
||||
mobileUrl: `http://nmc.cn${v.url}`,
|
||||
})),
|
||||
};
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { RouterData } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getWereadID from "../utils/getWereadID.js";
|
||||
import getWereadID from "../utils/getToken/weread.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
|
||||
Reference in New Issue
Block a user