-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
343 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
})), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`, | ||
}; | ||
}), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
})), | ||
}; | ||
}; |
Oops, something went wrong.