mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-13 05:34:55 +08:00
Compare commits
3 Commits
v2.0.0-rc.
...
v2.0.0-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cdf2479044 | ||
|
|
067190b5a2 | ||
|
|
abadb692e4 |
87
README.md
87
README.md
@@ -1,17 +1,17 @@
|
||||
<div align="center">
|
||||
<img alt="logo" height="120" src="./public/favicon.png" width="120"/>
|
||||
<p size="20">今日热榜</p>
|
||||
<h2>今日热榜</h2>
|
||||
<p>一个聚合热门数据的 API 接口</p>
|
||||
</div>
|
||||
|
||||
## 特性
|
||||
## 🚩 特性
|
||||
|
||||
- 极快响应,便于开发
|
||||
- 支持 RSS 模式和 JSON 模式
|
||||
- 支持多种部署方式
|
||||
- 简明的路由目录,便于新增
|
||||
|
||||
## 示例
|
||||
## 👀 示例
|
||||
|
||||
> 这里是使用该 API 的示例站点
|
||||
> 示例站点可能由于访问量或者长久未维护而访问异常
|
||||
@@ -19,40 +19,45 @@
|
||||
|
||||
- [今日热榜 - https://hot.imsyy.top/](https://hot.imsyy.top/)
|
||||
|
||||
## 总览
|
||||
## 🎉 总览
|
||||
|
||||
> 🟢 状态正常 / 🟠 可能失效 / ❌ 无法使用
|
||||
> 🟢 状态正常 / 🟠 可能失效 / ❌ 无法使用 / ⚠️ 需要科学上网
|
||||
|
||||
| **站点** | **类别** | **调用名称** | **状态** |
|
||||
| -------------- | -------- | ------------ | -------- |
|
||||
| 哔哩哔哩 | 热门榜 | bilibili | 🟢 |
|
||||
| AcFun | 排行榜 | acfun | 🟢 |
|
||||
| 微博 | 热搜榜 | weibo | 🟢 |
|
||||
| 知乎 | 热榜 | zhihu | 🟢 |
|
||||
| 知乎日报 | 推荐榜 | zhihu-daily | 🟢 |
|
||||
| 百度 | 热搜榜 | baidu | 🟢 |
|
||||
| 抖音 | 热点榜 | douyin | 🟢 |
|
||||
| 豆瓣电影 | 新片榜 | douban-movie | 🟢 |
|
||||
| 豆瓣讨论小组 | 讨论精选 | douban-group | 🟢 |
|
||||
| 百度贴吧 | 热议榜 | tieba | 🟢 |
|
||||
| 少数派 | 热榜 | sspai | 🟢 |
|
||||
| IT 之家 | 热榜 | ithome | 🟠 |
|
||||
| 简书 | 热门推荐 | jianshu | 🟠 |
|
||||
| 澎湃新闻 | 热榜 | thepaper | 🟢 |
|
||||
| 今日头条 | 热榜 | toutiao | 🟢 |
|
||||
| 36 氪 | 热榜 | 36kr | 🟢 |
|
||||
| 稀土掘金 | 热榜 | juejin | 🟢 |
|
||||
| 腾讯新闻 | 热点榜 | qq-news | 🟢 |
|
||||
| 网易新闻 | 热点榜 | netease-news | 🟢 |
|
||||
| 英雄联盟 | 更新公告 | lol | 🟢 |
|
||||
| 原神 | 最新消息 | genshin | 🟢 |
|
||||
| 崩坏3 | 最新动态 | honkai | 🟢 |
|
||||
| 崩坏:星穹铁道 | 最新动态 | starrail | 🟢 |
|
||||
| 微信读书 | 飙升榜 | weread | 🟢 |
|
||||
| NGA | 热帖 | ngabbs | 🟢 |
|
||||
| HelloGitHub | Trending | hellogithub | 🟢 |
|
||||
| **站点** | **类别** | **调用名称** | **状态** |
|
||||
| ---------------- | ------------ | -------------- | -------- |
|
||||
| 哔哩哔哩 | 热门榜 | bilibili | 🟢 |
|
||||
| AcFun | 排行榜 | acfun | 🟢 |
|
||||
| 微博 | 热搜榜 | weibo | 🟢 |
|
||||
| 知乎 | 热榜 | zhihu | 🟢 |
|
||||
| 知乎日报 | 推荐榜 | zhihu-daily | 🟢 |
|
||||
| 百度 | 热搜榜 | baidu | 🟢 |
|
||||
| 抖音 | 热点榜 | douyin | 🟢 |
|
||||
| 豆瓣电影 | 新片榜 | douban-movie | 🟢 |
|
||||
| 豆瓣讨论小组 | 讨论精选 | douban-group | 🟢 |
|
||||
| 百度贴吧 | 热议榜 | tieba | 🟢 |
|
||||
| 少数派 | 热榜 | sspai | 🟢 |
|
||||
| IT之家 | 热榜 | ithome | 🟠 |
|
||||
| IT之家「喜加一」 | 最新动态 | ithome-xijiayi | 🟠 |
|
||||
| 简书 | 热门推荐 | jianshu | 🟠 |
|
||||
| 澎湃新闻 | 热榜 | thepaper | 🟢 |
|
||||
| 今日头条 | 热榜 | toutiao | 🟢 |
|
||||
| 36 氪 | 热榜 | 36kr | 🟢 |
|
||||
| 51CTO | 推荐榜 | 51cto | 🟢 |
|
||||
| 稀土掘金 | 热榜 | juejin | 🟢 |
|
||||
| 腾讯新闻 | 热点榜 | qq-news | 🟢 |
|
||||
| 网易新闻 | 热点榜 | netease-news | 🟢 |
|
||||
| 英雄联盟 | 更新公告 | lol | 🟢 |
|
||||
| 原神 | 最新消息 | genshin | 🟢 |
|
||||
| 崩坏3 | 最新动态 | honkai | 🟢 |
|
||||
| 崩坏:星穹铁道 | 最新动态 | starrail | 🟢 |
|
||||
| 微信读书 | 飙升榜 | weread | 🟢 |
|
||||
| NGA | 热帖 | ngabbs | 🟢 |
|
||||
| V2EX | 主题榜 | v2ex | ⚠️ |
|
||||
| HelloGitHub | Trending | hellogithub | 🟢 |
|
||||
| 中央气象台 | 全国气象预警 | weatheralarm | 🟢 |
|
||||
| 中国地震台 | 地震速报 | earthquake | 🟢 |
|
||||
|
||||
## 部署
|
||||
## ⚙️ 部署
|
||||
|
||||
具体使用说明可参考 [我的博客](https://blog.imsyy.top/posts/2024/0408),下方仅讲解基础操作:
|
||||
|
||||
@@ -128,14 +133,24 @@ npm run start
|
||||
|
||||
若您目前仅能通过 `Vercel` 进行部署,那么请暂时不要使用最新版本
|
||||
|
||||
## 其他
|
||||
## ⚠️ 须知
|
||||
|
||||
- 本项目为了避免频繁请求官方数据,默认对数据做了缓存处理,默认为 `60` 分钟,如需更改,请自行修改配置
|
||||
- 本项目部分接口使用了 **页面爬虫**,若违反对应页面的相关规则,请 **及时通知我去除该接口**
|
||||
|
||||
## 免责声明
|
||||
## 📢 免责声明
|
||||
|
||||
- 本项目提供的 `API` 仅供开发者进行技术研究和开发测试使用。使用该 `API` 获取的信息仅供参考,不代表本项目对信息的准确性、可靠性、合法性、完整性作出任何承诺或保证。本项目不对任何因使用该 `API` 获取信息而导致的任何直接或间接损失负责。本项目保留随时更改 `API` 接口地址、接口协议、接口参数及其他相关内容的权利。本项目对使用者使用 `API` 的行为不承担任何直接或间接的法律责任
|
||||
- 本项目并未与相关信息提供方建立任何关联或合作关系,获取的信息均来自公开渠道,如因使用该 `API` 获取信息而产生的任何法律责任,由使用者自行承担
|
||||
- 本项目对使用 `API` 获取的信息进行了最大限度的筛选和整理,但不保证信息的准确性和完整性。使用 `API` 获取信息时,请务必自行核实信息的真实性和可靠性,谨慎处理相关事项
|
||||
- 本项目保留对 `API` 的随时更改、停用、限制使用等措施的权利。任何因使用本 `API` 产生的损失,本项目不负担任何赔偿和责任
|
||||
|
||||
## 😘 鸣谢
|
||||
|
||||
特此感谢为本项目提供支持与灵感的项目
|
||||
|
||||
- [RSSHub](https://github.com/DIYgod/RSSHub)
|
||||
|
||||
## ⭐ Star History
|
||||
|
||||
[](https://star-history.com/#imsyy/DailyHotApi&Date)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dailyhot_api",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.0-rc.2",
|
||||
"description": "An Api on Today's Hot list",
|
||||
"keywords": [
|
||||
"API",
|
||||
@@ -33,6 +33,7 @@
|
||||
"dotenv": "^16.4.5",
|
||||
"feed": "^4.2.2",
|
||||
"hono": "^4.2.2",
|
||||
"md5": "^2.3.0",
|
||||
"node-cache": "^5.1.2",
|
||||
"winston": "^3.13.0"
|
||||
},
|
||||
|
||||
23
pnpm-lock.yaml
generated
23
pnpm-lock.yaml
generated
@@ -23,6 +23,9 @@ dependencies:
|
||||
hono:
|
||||
specifier: ^4.2.2
|
||||
version: 4.2.2
|
||||
md5:
|
||||
specifier: ^2.3.0
|
||||
version: 2.3.0
|
||||
node-cache:
|
||||
specifier: ^5.1.2
|
||||
version: 5.1.2
|
||||
@@ -615,6 +618,10 @@ packages:
|
||||
supports-color: 7.2.0
|
||||
dev: true
|
||||
|
||||
/charenc@0.0.2:
|
||||
resolution: {integrity: sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==}
|
||||
dev: false
|
||||
|
||||
/cheerio-select@2.1.0:
|
||||
resolution: {integrity: sha512-9v9kG0LvzrlcungtnJtpGNxY+fzECQKhK4EGJX2vByejiMX84MFNQw4UxPJl3bFbTMw+Dfs37XaIkCwTZfLh4g==}
|
||||
dependencies:
|
||||
@@ -705,6 +712,10 @@ packages:
|
||||
which: 2.0.2
|
||||
dev: true
|
||||
|
||||
/crypt@0.0.2:
|
||||
resolution: {integrity: sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==}
|
||||
dev: false
|
||||
|
||||
/css-select@5.1.0:
|
||||
resolution: {integrity: sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==}
|
||||
dependencies:
|
||||
@@ -1139,6 +1150,10 @@ packages:
|
||||
resolution: {integrity: sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==}
|
||||
dev: false
|
||||
|
||||
/is-buffer@1.1.6:
|
||||
resolution: {integrity: sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==}
|
||||
dev: false
|
||||
|
||||
/is-extglob@2.1.1:
|
||||
resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
@@ -1237,6 +1252,14 @@ packages:
|
||||
yallist: 4.0.0
|
||||
dev: true
|
||||
|
||||
/md5@2.3.0:
|
||||
resolution: {integrity: sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==}
|
||||
dependencies:
|
||||
charenc: 0.0.2
|
||||
crypt: 0.0.2
|
||||
is-buffer: 1.1.6
|
||||
dev: false
|
||||
|
||||
/merge2@1.4.1:
|
||||
resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}
|
||||
engines: {node: '>= 8'}
|
||||
|
||||
@@ -32,6 +32,13 @@ export type RouterType = {
|
||||
url: string;
|
||||
type: number;
|
||||
};
|
||||
"51cto": {
|
||||
title: string;
|
||||
url: string;
|
||||
cover: string;
|
||||
abstract: string;
|
||||
source_id: number;
|
||||
};
|
||||
bilibili: {
|
||||
bvid: string;
|
||||
title: string;
|
||||
@@ -185,4 +192,26 @@ export type RouterType = {
|
||||
summary: string;
|
||||
clicks_total: number;
|
||||
};
|
||||
v2ex: {
|
||||
title: string;
|
||||
url: string;
|
||||
content: string;
|
||||
id: number;
|
||||
replies: number;
|
||||
member: {
|
||||
username: string;
|
||||
};
|
||||
};
|
||||
earthquake: {
|
||||
NEW_DID: string;
|
||||
LOCATION_C: string;
|
||||
M: string;
|
||||
};
|
||||
weatheralarm: {
|
||||
alertid: string;
|
||||
issuetime: string;
|
||||
title: string;
|
||||
url: string;
|
||||
pic: string;
|
||||
};
|
||||
};
|
||||
|
||||
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,6 +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/getToken/bilibili.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "0";
|
||||
@@ -41,11 +42,14 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
|
||||
const getList = async (options: Options, noCache: boolean) => {
|
||||
const { type } = options;
|
||||
const url = `https://api.bilibili.com/x/web-interface/ranking/v2?tid=${type}`;
|
||||
const wbiData = await getBiliWbi();
|
||||
const url = `https://api.bilibili.com/x/web-interface/ranking/v2?tid=${type}&type=all&${wbiData}`;
|
||||
const result = await get({
|
||||
url,
|
||||
headers: {
|
||||
Referer: `https://www.bilibili.com/ranking/all`,
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
|
||||
},
|
||||
noCache,
|
||||
});
|
||||
|
||||
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`,
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
53
src/routes/ithome-xijiayi.ts
Normal file
53
src/routes/ithome-xijiayi.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import type { RouterData } from "../types.js";
|
||||
import { load } from "cheerio";
|
||||
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-xijiayi",
|
||||
title: "IT之家「喜加一」",
|
||||
type: "最新动态",
|
||||
description: "最新最全的「喜加一」游戏动态尽在这里!",
|
||||
link: "https://www.ithome.com/zt/xijiayi",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
|
||||
// 链接处理
|
||||
const replaceLink = (url: string, getId: boolean = false) => {
|
||||
const match = url.match(/https:\/\/www\.ithome\.com\/0\/(\d+)\/(\d+)\.htm/);
|
||||
if (match && match[1] && match[2]) {
|
||||
return getId ? match[1] + match[2] : `https://m.ithome.com/html/${match[1]}${match[2]}.htm`;
|
||||
}
|
||||
return url;
|
||||
};
|
||||
|
||||
const getList = async (noCache: boolean) => {
|
||||
const url = `https://www.ithome.com/zt/xijiayi`;
|
||||
const result = await get({ url, noCache });
|
||||
const $ = load(result.data);
|
||||
const listDom = $(".newslist li");
|
||||
const listData = listDom.toArray().map((item) => {
|
||||
const dom = $(item);
|
||||
const href = dom.find("a").attr("href");
|
||||
return {
|
||||
id: href ? Number(replaceLink(href, true)) : 100000,
|
||||
title: dom.find(".newsbody h2").text().trim(),
|
||||
desc: dom.find(".newsbody p").text().trim(),
|
||||
cover: dom.find("img").attr("data-original"),
|
||||
hot: Number(dom.find(".comment").text().replace(/\D/g, "")),
|
||||
url: href || undefined,
|
||||
mobileUrl: href ? replaceLink(href) : undefined,
|
||||
};
|
||||
});
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: listData,
|
||||
};
|
||||
};
|
||||
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);
|
||||
|
||||
@@ -37,7 +37,7 @@ request.interceptors.response.use(
|
||||
|
||||
// GET
|
||||
export const get = async (options: Get) => {
|
||||
const { url, headers, noCache, ttl = config.CACHE_TTL, originaInfo = false } = options;
|
||||
const { url, headers, params, noCache, ttl = config.CACHE_TTL, originaInfo = false } = options;
|
||||
logger.info("发起 GET 请求", options);
|
||||
try {
|
||||
// 检查缓存
|
||||
@@ -51,7 +51,7 @@ export const get = async (options: Get) => {
|
||||
}
|
||||
// 缓存不存在时请求接口
|
||||
logger.info("请求接口", { url });
|
||||
const response = await request.get(url, { headers });
|
||||
const response = await request.get(url, { headers, params });
|
||||
const responseData = response?.data || response;
|
||||
// 存储新获取的数据到缓存
|
||||
const updateTime = new Date().toISOString();
|
||||
|
||||
29
src/utils/getToken/51cto.ts
Normal file
29
src/utils/getToken/51cto.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { getCache, setCache } from "../cache.js";
|
||||
import { get } from "../getData.js";
|
||||
import md5 from "md5";
|
||||
|
||||
export const getToken = async () => {
|
||||
const cachedData = getCache("51cto-token");
|
||||
if (cachedData && typeof cachedData === "object" && "token" in cachedData) {
|
||||
const { token } = cachedData as { token: string };
|
||||
return token;
|
||||
}
|
||||
const result = await get({
|
||||
url: "https://api-media.51cto.com/api/token-get",
|
||||
});
|
||||
const token = result.data.data.data.token;
|
||||
setCache("51cto-token", { token });
|
||||
return token;
|
||||
};
|
||||
|
||||
export const sign = (
|
||||
requestPath: string,
|
||||
payload: Record<string, unknown> = {},
|
||||
timestamp: number,
|
||||
token: string,
|
||||
) => {
|
||||
payload.timestamp = timestamp;
|
||||
payload.token = token;
|
||||
const sortedParams = Object.keys(payload).sort();
|
||||
return md5(md5(requestPath) + md5(sortedParams + md5(token) + timestamp));
|
||||
};
|
||||
85
src/utils/getToken/bilibili.ts
Normal file
85
src/utils/getToken/bilibili.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
// 获取 Bilibili Web 端 WBI 签名鉴权
|
||||
import { getCache, setCache } from "../cache.js";
|
||||
import { get } from "../getData.js";
|
||||
import md5 from "md5";
|
||||
|
||||
type EncodedKeys = {
|
||||
img_key: string;
|
||||
sub_key: string;
|
||||
};
|
||||
|
||||
interface WbiParams {
|
||||
[key: string]: string | number;
|
||||
}
|
||||
|
||||
const mixinKeyEncTab = [
|
||||
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, 33, 9, 42, 19, 29, 28,
|
||||
14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40, 61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54,
|
||||
21, 56, 59, 6, 63, 57, 62, 11, 36, 20, 34, 44, 52,
|
||||
];
|
||||
|
||||
// 对 imgKey 和 subKey 进行字符顺序打乱编码
|
||||
const getMixinKey = (orig: string): string =>
|
||||
mixinKeyEncTab
|
||||
.map((n) => orig[n])
|
||||
.join("")
|
||||
.slice(0, 32);
|
||||
|
||||
// 为请求参数进行 wbi 签名
|
||||
const encWbi = (params: WbiParams, img_key: string, sub_key: string): string => {
|
||||
const mixin_key = getMixinKey(img_key + sub_key);
|
||||
const curr_time = Math.round(Date.now() / 1000);
|
||||
const chr_filter = /[!'()*]/g;
|
||||
// 添加 wts 字段
|
||||
Object.assign(params, { wts: curr_time });
|
||||
// 按照 key 重排参数
|
||||
const query = Object.keys(params)
|
||||
.sort()
|
||||
.map((key) => {
|
||||
// 过滤 value 中的 "!'()*" 字符
|
||||
const value = params[key].toString().replace(chr_filter, "");
|
||||
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
||||
})
|
||||
.join("&");
|
||||
// 计算 w_rid
|
||||
const wbi_sign = md5(query + mixin_key);
|
||||
return query + "&w_rid=" + wbi_sign;
|
||||
};
|
||||
|
||||
// 获取最新的 img_key 和 sub_key
|
||||
const getWbiKeys = async (): Promise<EncodedKeys> => {
|
||||
const result = await get({
|
||||
url: "https://api.bilibili.com/x/web-interface/nav",
|
||||
headers: {
|
||||
// SESSDATA 字段
|
||||
Cookie: "SESSDATA=xxxxxx",
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
|
||||
Referer: "https://www.bilibili.com/",
|
||||
},
|
||||
});
|
||||
const img_url: string = result.data.wbi_img?.img_url ?? "";
|
||||
const sub_url: string = result.data.wbi_img?.sub_url ?? "";
|
||||
return {
|
||||
img_key: img_url.slice(img_url.lastIndexOf("/") + 1, img_url.lastIndexOf(".")),
|
||||
sub_key: sub_url.slice(sub_url.lastIndexOf("/") + 1, sub_url.lastIndexOf(".")),
|
||||
};
|
||||
};
|
||||
|
||||
const getBiliWbi = async (): Promise<string> => {
|
||||
const cachedData = getCache("bilibili-wbi");
|
||||
console.log(cachedData);
|
||||
if (cachedData && typeof cachedData === "object" && "wbi" in cachedData) {
|
||||
const { wbi } = cachedData as { wbi: string };
|
||||
return wbi;
|
||||
}
|
||||
const web_keys = await getWbiKeys();
|
||||
const params = { foo: "114", bar: "514", baz: 1919810 };
|
||||
const img_key = web_keys.img_key;
|
||||
const sub_key = web_keys.sub_key;
|
||||
const query = encWbi(params, img_key, sub_key);
|
||||
setCache("bilibili-wbi", { wbi: query });
|
||||
return query;
|
||||
};
|
||||
|
||||
export default getBiliWbi;
|
||||
Reference in New Issue
Block a user