mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 21:24:55 +08:00
Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7260cf569 | ||
|
|
3343f2b5db | ||
|
|
2b91f3f32b | ||
|
|
fa8fb5a47f | ||
|
|
c0cbb3591b | ||
|
|
4c54be315f | ||
|
|
71a3621fd8 | ||
|
|
e6a02c667f | ||
|
|
07c0f6ed9b | ||
|
|
b8c16ad88a | ||
|
|
5df634058c | ||
|
|
029fed603b | ||
|
|
69fb0640be | ||
|
|
a4394588c1 | ||
|
|
b90c144a62 | ||
|
|
36c40b7870 | ||
|
|
b0dc506cc6 | ||
|
|
68edae7e74 | ||
|
|
d6fcb1628e | ||
|
|
9eb76a5f52 | ||
|
|
aab54d2190 | ||
|
|
85567ea638 | ||
|
|
6330914d09 | ||
|
|
813e88c993 | ||
|
|
e9dfcad437 | ||
|
|
8d7f394153 | ||
|
|
c42573c37c | ||
|
|
8cffc6c701 | ||
|
|
e079e2efb5 | ||
|
|
9e9fc713de | ||
|
|
4ae8e6cfd8 | ||
|
|
eaba3db4de | ||
|
|
c71e4267ff | ||
|
|
30f99cd010 | ||
|
|
87f0ca3c78 | ||
|
|
5b63365423 | ||
|
|
78e25f8b3a |
15
.dockerignore
Normal file
15
.dockerignore
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
Dockerfile*
|
||||||
|
docker-compose*
|
||||||
|
.dockerignore
|
||||||
|
.git
|
||||||
|
.github
|
||||||
|
.gitignore
|
||||||
|
README.md
|
||||||
|
LICENSE
|
||||||
|
.vscode
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
images
|
||||||
|
script
|
||||||
19
.eslintrc.json
Normal file
19
.eslintrc.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"es2021": true
|
||||||
|
},
|
||||||
|
"extends": ["eslint:recommended", "plugin:vue/vue3-essential"],
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": "latest",
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"plugins": ["vue"],
|
||||||
|
"rules": {},
|
||||||
|
"globals": {
|
||||||
|
"require": true,
|
||||||
|
"module": true,
|
||||||
|
"process": true,
|
||||||
|
"__dirname": true
|
||||||
|
}
|
||||||
|
}
|
||||||
46
.github/workflows/docker.yml
vendored
Normal file
46
.github/workflows/docker.yml
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
name: Publish Docker image
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
push_to_registry:
|
||||||
|
name: Push Docker image to multiple registries
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
packages: write
|
||||||
|
contents: read
|
||||||
|
steps:
|
||||||
|
- name: Check out the repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Log in to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Log in to the Container registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
imsyy/dailyhot-api
|
||||||
|
ghcr.io/${{ github.repository }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
8
.prettierrc.json
Normal file
8
.prettierrc.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/prettierrc",
|
||||||
|
"singleQuote": false,
|
||||||
|
"trailingComma": "all",
|
||||||
|
"tabWidth": 2,
|
||||||
|
"semi": true,
|
||||||
|
"printWidth": 100
|
||||||
|
}
|
||||||
10
Dockerfile
Normal file
10
Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
FROM node:18-alpine
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install --production
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
EXPOSE 6688
|
||||||
|
CMD ["npm", "start"]
|
||||||
115
README.md
115
README.md
@@ -14,35 +14,78 @@
|
|||||||
|
|
||||||
> 🟢 状态正常
|
> 🟢 状态正常
|
||||||
> 🟠 可能失效
|
> 🟠 可能失效
|
||||||
> 🔴 无法使用
|
> ❌ 无法使用
|
||||||
|
|
||||||
| **站点** | **类别** | **调用名称** | **状态** |
|
| **站点** | **类别** | **调用名称** | **状态** |
|
||||||
| ------------ | -------- | ------------ | -------- |
|
| ------------ | -------- | --------------------- | -------- |
|
||||||
| 哔哩哔哩 | 热门榜 | bilibili | 🟢 |
|
| 哔哩哔哩 | 热门榜 | bilibili | 🟢 |
|
||||||
| 知乎 | 热榜 | zhihu | 🟢 |
|
| 微博 | 热搜榜 | weibo | 🟢 |
|
||||||
| 百度 | 热搜榜 | baidu | 🟢 |
|
| 知乎 | 热榜 | zhihu | 🟢 |
|
||||||
| 百度贴吧 | 热议榜 | tieba | 🟢 |
|
| 百度 | 热搜榜 | baidu | 🟢 |
|
||||||
| 少数派 | 热榜 | sspai | 🟢 |
|
| 抖音 | 热点榜 | douyin / douyin_new | 🟢 |
|
||||||
| IT 之家 | 热榜 | ithome | 🟠 |
|
| 抖音 | 热歌榜 | douyin_music | 🟢 |
|
||||||
| 澎湃新闻 | 热榜 | thepaper | 🟢 |
|
| 豆瓣 | 新片榜 | douban_new | 🟢 |
|
||||||
| 今日头条 | 热榜 | toutiao | 🟢 |
|
| 豆瓣讨论小组 | 讨论精选 | douban_group | 🟢 |
|
||||||
| 微博热搜 | 热搜榜 | weibo | 🟢 |
|
| 百度贴吧 | 热议榜 | tieba | 🟢 |
|
||||||
| 36 氪 | 热榜 | 36kr | 🟢 |
|
| 少数派 | 热榜 | sspai | 🟢 |
|
||||||
| 稀土掘金 | 热榜 | juejin | 🟢 |
|
| IT 之家 | 热榜 | ithome | 🟠 |
|
||||||
| 腾讯新闻 | 热点榜 | newsqq | 🟢 |
|
| 澎湃新闻 | 热榜 | thepaper | 🟢 |
|
||||||
| 抖音热榜 | 热点榜 | douyin | 🟢 |
|
| 今日头条 | 热榜 | toutiao | 🟢 |
|
||||||
| 英雄联盟 | 更新公告 | lol | 🟢 |
|
| 36 氪 | 热榜 | 36kr | 🟢 |
|
||||||
| 微信读书 | 飙升榜 | weread | 🟢 |
|
| 稀土掘金 | 热榜 | juejin | 🟢 |
|
||||||
| 历史上的今天 | 指定日期 | calendar | 🟢 |
|
| 腾讯新闻 | 热点榜 | newsqq | 🟢 |
|
||||||
|
| 网易新闻 | 热点榜 | netease | 🟢 |
|
||||||
|
| 英雄联盟 | 更新公告 | lol | 🟢 |
|
||||||
|
| 原神 | 最新消息 | genshin | 🟢 |
|
||||||
|
| 微信读书 | 飙升榜 | weread | 🟢 |
|
||||||
|
| 快手 | 热榜 | kuaishou | 🟢 |
|
||||||
|
| 网易云音乐 | 排行榜 | netease_music_toplist | 🟢 |
|
||||||
|
| QQ音乐 | 排行榜 | qq_music_toplist | 🟢 |
|
||||||
|
| NGA | 热帖 | ngabbs | 🟢 |
|
||||||
|
| Github | Trending | github | 🟢 |
|
||||||
|
| V2EX | 热榜 | v2ex | 🟠 |
|
||||||
|
| 历史上的今天 | 指定日期 | calendar | 🟢 |
|
||||||
|
|
||||||
### 特殊接口说明
|
### 特殊接口说明
|
||||||
|
|
||||||
|
#### 网易云音乐
|
||||||
|
|
||||||
|
调用网易云音乐排行榜需要传入指定榜单类别
|
||||||
|
|
||||||
|
| 参数名 | 参数值 | 说明 |
|
||||||
|
| ------ | ------ | ------ |
|
||||||
|
| type | 1 | 飙升榜 |
|
||||||
|
| type | 2 | 新歌榜 |
|
||||||
|
| type | 3 | 原创榜 |
|
||||||
|
| type | 4 | 热歌榜 |
|
||||||
|
|
||||||
|
```http
|
||||||
|
GET https://example.com/netease_music_toplist?type=1
|
||||||
|
```
|
||||||
|
|
||||||
|
#### QQ音乐
|
||||||
|
|
||||||
|
调用QQ音乐排行榜需要传入指定榜单类别
|
||||||
|
|
||||||
|
| 参数名 | 参数值 | 说明 |
|
||||||
|
| ------ | ------ | ---------------- |
|
||||||
|
| type | 1 | 飙升榜 |
|
||||||
|
| type | 2 | 热歌榜 |
|
||||||
|
| type | 3 | 新歌榜 |
|
||||||
|
| type | 4 | 流行指数榜 |
|
||||||
|
| type | 5 | 腾讯音乐人原创榜 |
|
||||||
|
| type | 6 | 听歌识曲榜 |
|
||||||
|
|
||||||
|
```http
|
||||||
|
GET https://example.com/qq_music_toplist?type=1
|
||||||
|
```
|
||||||
|
|
||||||
#### 获取全部接口信息
|
#### 获取全部接口信息
|
||||||
|
|
||||||
获取除了下方特殊接口外的全部接口列表
|
获取除了下方特殊接口外的全部接口列表
|
||||||
|
|
||||||
```http
|
```http
|
||||||
GET https://{example.com}/all
|
GET https://example.com/all
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 历史上的今天(指定日期)
|
#### 历史上的今天(指定日期)
|
||||||
@@ -50,19 +93,43 @@ GET https://{example.com}/all
|
|||||||
将指定的月份和日期传入即可得到当天数据,请注意格式
|
将指定的月份和日期传入即可得到当天数据,请注意格式
|
||||||
|
|
||||||
```http
|
```http
|
||||||
GET https://{example.com}/calendar/date?month=06&day=01
|
GET https://example.com/calendar/date?month=06&day=01
|
||||||
```
|
```
|
||||||
|
|
||||||
## 部署
|
## 部署
|
||||||
|
|
||||||
```js
|
```bash
|
||||||
// 安装依赖
|
# 安装依赖
|
||||||
pnpm install
|
pnpm install
|
||||||
|
|
||||||
// 运行
|
# 运行
|
||||||
pnpm start
|
pnpm start
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Docker 部署
|
||||||
|
|
||||||
|
> 安装及配置 Docker 将不在此处说明,请自行解决
|
||||||
|
|
||||||
|
### 本地构建
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 构建
|
||||||
|
docker build -t dailyhot-api .
|
||||||
|
# 运行
|
||||||
|
docker run -p 6688:6688 -d dailyhot-api
|
||||||
|
# 或使用 Docker Compose
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
### 在线部署
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 拉取
|
||||||
|
docker pull imsyy/dailyhot-api:latest
|
||||||
|
# 运行
|
||||||
|
docker run -p 6688:6688 -d imsyy/dailyhot-api:latest
|
||||||
|
```
|
||||||
|
|
||||||
## Vercel 部署
|
## Vercel 部署
|
||||||
|
|
||||||
现已支持 Vercel 部署,无需服务器
|
现已支持 Vercel 部署,无需服务器
|
||||||
|
|||||||
12
docker-compose.yml
Normal file
12
docker-compose.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
services:
|
||||||
|
DailyhotApi:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
image: dailyhot-api
|
||||||
|
container_name: dailyhot-api
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime:ro
|
||||||
|
- /etc/timezone:/etc/timezone:ro
|
||||||
|
ports:
|
||||||
|
- 6688:6688
|
||||||
|
restart: always
|
||||||
32
index.js
32
index.js
@@ -24,21 +24,31 @@ app.use(views(__dirname + "/public"));
|
|||||||
app.use(
|
app.use(
|
||||||
cors({
|
cors({
|
||||||
origin: domain,
|
origin: domain,
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// CORS
|
||||||
app.use(async (ctx, next) => {
|
app.use(async (ctx, next) => {
|
||||||
if (domain === "*") {
|
ctx.set("Access-Control-Allow-Origin", domain);
|
||||||
await next();
|
ctx.set("Access-Control-Allow-Methods", "GET, OPTIONS");
|
||||||
|
ctx.set("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
||||||
|
ctx.set("Access-Control-Allow-Credentials", "true");
|
||||||
|
// 处理预检请求
|
||||||
|
if (ctx.method === "OPTIONS") {
|
||||||
|
ctx.status = 200;
|
||||||
} else {
|
} else {
|
||||||
if (ctx.headers.origin === domain || ctx.headers.referer === domain) {
|
if (domain === "*") {
|
||||||
await next();
|
await next();
|
||||||
} else {
|
} else {
|
||||||
ctx.status = 403;
|
if (ctx.headers.origin === domain || ctx.headers.referer === domain) {
|
||||||
ctx.body = {
|
await next();
|
||||||
code: 403,
|
} else {
|
||||||
message: "请通过正确的域名访问",
|
ctx.status = 403;
|
||||||
};
|
ctx.body = {
|
||||||
|
code: 403,
|
||||||
|
message: "请通过正确的域名访问",
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -50,7 +60,7 @@ app.use(router.allowedMethods());
|
|||||||
// 启动应用程序并监听端口
|
// 启动应用程序并监听端口
|
||||||
const startApp = (port) => {
|
const startApp = (port) => {
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`成功在 ${port} 端口上运行`);
|
console.info(`成功在 ${port} 端口上运行`);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,7 +71,7 @@ const checkPort = (port) => {
|
|||||||
.createServer()
|
.createServer()
|
||||||
.once("error", (err) => {
|
.once("error", (err) => {
|
||||||
if (err.code === "EADDRINUSE") {
|
if (err.code === "EADDRINUSE") {
|
||||||
console.log(`端口 ${port} 已被占用, 正在尝试其他端口...`);
|
console.info(`端口 ${port} 已被占用, 正在尝试其他端口...`);
|
||||||
server.close();
|
server.close();
|
||||||
resolve(false);
|
resolve(false);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
25
package.json
25
package.json
@@ -1,27 +1,32 @@
|
|||||||
{
|
{
|
||||||
"name": "dailyhot_api",
|
"name": "dailyhot_api",
|
||||||
"version": "1.0.0",
|
"version": "1.0.8",
|
||||||
"description": "一个今日热榜",
|
"description": "An api on Today's Hot list",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"format": "prettier --write .",
|
||||||
|
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
"dev": "./node_modules/.bin/nodemon index.js",
|
"dev": "npx nodemon index.js",
|
||||||
"prd": "pm2 start index.js",
|
"prd": "pm2 start index.js",
|
||||||
"build": "node index.js"
|
"build": "node index.js"
|
||||||
},
|
},
|
||||||
"author": "imsyy",
|
"author": "imsyy",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.3.4",
|
"axios": "^1.6.3",
|
||||||
"cheerio": "1.0.0-rc.12",
|
"cheerio": "1.0.0-rc.12",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.3.1",
|
||||||
"koa": "^2.14.1",
|
"eslint": "^8.56.0",
|
||||||
"koa-bodyparser": "^4.3.0",
|
"eslint-plugin-vue": "^9.19.2",
|
||||||
"koa-router": "^12.0.0",
|
"koa": "^2.15.0",
|
||||||
|
"koa-bodyparser": "^4.4.1",
|
||||||
|
"koa-router": "^12.0.1",
|
||||||
"koa-static": "^5.0.0",
|
"koa-static": "^5.0.0",
|
||||||
"koa-views": "^8.0.0",
|
"koa-views": "^8.1.0",
|
||||||
"koa2-cors": "^2.0.6",
|
"koa2-cors": "^2.0.6",
|
||||||
"node-cache": "^5.1.2",
|
"node-cache": "^5.1.2",
|
||||||
"nodemon": "^2.0.22"
|
"nodemon": "^2.0.22",
|
||||||
|
"prettier": "^3.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1398
pnpm-lock.yaml
generated
1398
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,9 @@
|
|||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>404 | Linkbook API</title>
|
<title>404 | DailyHot API</title>
|
||||||
<link
|
<link rel="shortcut icon" href="https://img.imsyy.top/logo/imsyy.png" type="image/x-icon" />
|
||||||
rel="shortcut icon"
|
|
||||||
href="https://img.imsyy.top/logo/imsyy.png"
|
|
||||||
type="image/x-icon"
|
|
||||||
/>
|
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/font-awesome/6.0.0/css/all.min.css"
|
href="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/font-awesome/6.0.0/css/all.min.css"
|
||||||
@@ -38,7 +34,9 @@
|
|||||||
background-color: var(--text-color-hover);
|
background-color: var(--text-color-hover);
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
font-family: "PingFang SC", "Open Sans", "Microsoft YaHei", sans-serif;
|
font-family: "PingFang SC", "Open Sans", "Microsoft YaHei", sans-serif;
|
||||||
transition: background-color 0.5s, color 0.5s;
|
transition:
|
||||||
|
background-color 0.5s,
|
||||||
|
color 0.5s;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -149,16 +147,12 @@
|
|||||||
<a href="https://imsyy.top/" target="_blank">無名</a>
|
<a href="https://imsyy.top/" target="_blank">無名</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="icp">
|
<div class="icp">
|
||||||
<a href="https://beian.miit.gov.cn/" target="_blank"
|
<a href="https://beian.miit.gov.cn/" target="_blank">豫ICP备2022018134号-1</a>
|
||||||
>豫ICP备2022018134号-1</a
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
<script>
|
<script>
|
||||||
// 跟随系统主题
|
// 跟随系统主题
|
||||||
const darkModeMediaQuery = window.matchMedia(
|
const darkModeMediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||||
"(prefers-color-scheme: dark)"
|
|
||||||
);
|
|
||||||
const toggleDarkMode = (darkModeMediaQuery) => {
|
const toggleDarkMode = (darkModeMediaQuery) => {
|
||||||
if (darkModeMediaQuery.matches) {
|
if (darkModeMediaQuery.matches) {
|
||||||
document.documentElement.classList.add("dark-mode");
|
document.documentElement.classList.add("dark-mode");
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>DailyHot API</title>
|
<title>DailyHot API</title>
|
||||||
<link
|
<link rel="shortcut icon" href="./favicon.svg" type="image/x-icon" />
|
||||||
rel="shortcut icon"
|
|
||||||
href="./favicon.svg"
|
|
||||||
type="image/x-icon"
|
|
||||||
/>
|
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/font-awesome/6.0.0/css/all.min.css"
|
href="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/font-awesome/6.0.0/css/all.min.css"
|
||||||
@@ -38,7 +34,9 @@
|
|||||||
background-color: var(--text-color-hover);
|
background-color: var(--text-color-hover);
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
font-family: "PingFang SC", "Open Sans", "Microsoft YaHei", sans-serif;
|
font-family: "PingFang SC", "Open Sans", "Microsoft YaHei", sans-serif;
|
||||||
transition: background-color 0.5s, color 0.5s;
|
transition:
|
||||||
|
background-color 0.5s,
|
||||||
|
color 0.5s;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -155,16 +153,12 @@
|
|||||||
<a href="https://imsyy.top/" target="_blank">無名</a>
|
<a href="https://imsyy.top/" target="_blank">無名</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="icp">
|
<div class="icp">
|
||||||
<a href="https://beian.miit.gov.cn/" target="_blank"
|
<a href="https://beian.miit.gov.cn/" target="_blank">豫ICP备2022018134号-1</a>
|
||||||
>豫ICP备2022018134号-1</a
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
<script>
|
<script>
|
||||||
// 跟随系统主题
|
// 跟随系统主题
|
||||||
const darkModeMediaQuery = window.matchMedia(
|
const darkModeMediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||||
"(prefers-color-scheme: dark)"
|
|
||||||
);
|
|
||||||
const toggleDarkMode = (darkModeMediaQuery) => {
|
const toggleDarkMode = (darkModeMediaQuery) => {
|
||||||
if (darkModeMediaQuery.matches) {
|
if (darkModeMediaQuery.matches) {
|
||||||
document.documentElement.classList.add("dark-mode");
|
document.documentElement.classList.add("dark-mode");
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const { get, set, del } = require("../utils/cacheData");
|
|||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
|
name: "36kr",
|
||||||
title: "36氪",
|
title: "36氪",
|
||||||
subtitle: "热榜",
|
subtitle: "热榜",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const axios = require("axios");
|
|||||||
const { get, set, del } = require("../utils/cacheData");
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = { title: "百度", subtitle: "热搜榜" };
|
const routerInfo = { name: "baidu", title: "百度", subtitle: "热搜榜" };
|
||||||
|
|
||||||
// 缓存键名
|
// 缓存键名
|
||||||
const cacheKey = "baiduData";
|
const cacheKey = "baiduData";
|
||||||
@@ -20,7 +20,7 @@ const getData = (data) => {
|
|||||||
if (!data) return [];
|
if (!data) return [];
|
||||||
const dataList = [];
|
const dataList = [];
|
||||||
try {
|
try {
|
||||||
const pattern = /<\!--s-data:(.*?)-->/s;
|
const pattern = /<!--s-data:(.*?)-->/s;
|
||||||
const matchResult = data.match(pattern);
|
const matchResult = data.match(pattern);
|
||||||
const jsonObject = JSON.parse(matchResult[1]).cards[0].content;
|
const jsonObject = JSON.parse(matchResult[1]).cards[0].content;
|
||||||
jsonObject.forEach((v) => {
|
jsonObject.forEach((v) => {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const { get, set, del } = require("../utils/cacheData");
|
|||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
|
name: "bilibili",
|
||||||
title: "哔哩哔哩",
|
title: "哔哩哔哩",
|
||||||
subtitle: "热门榜",
|
subtitle: "热门榜",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const Router = require("koa-router");
|
const Router = require("koa-router");
|
||||||
const calendarRouter = new Router();
|
const calendarRouter = new Router();
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const { get, set, del } = require("../utils/cacheData");
|
const { get, set } = require("../utils/cacheData");
|
||||||
|
|
||||||
// 缓存键名
|
// 缓存键名
|
||||||
const cacheKey = "calendarData";
|
const cacheKey = "calendarData";
|
||||||
@@ -96,7 +96,7 @@ calendarRouter.get("/calendar/date", async (ctx) => {
|
|||||||
}
|
}
|
||||||
// 从服务器拉取最新数据
|
// 从服务器拉取最新数据
|
||||||
const response = await axios.get(
|
const response = await axios.get(
|
||||||
`https://baike.baidu.com/cms/home/eventsOnHistory/${month}.json`
|
`https://baike.baidu.com/cms/home/eventsOnHistory/${month}.json`,
|
||||||
);
|
);
|
||||||
const newData = getData(response.data[month][month + day]);
|
const newData = getData(response.data[month][month + day]);
|
||||||
updateTime = new Date().toISOString();
|
updateTime = new Date().toISOString();
|
||||||
|
|||||||
181
routes/douban_group.js
Normal file
181
routes/douban_group.js
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
/**
|
||||||
|
* @author: x-dr
|
||||||
|
* @date: 2023-12-26
|
||||||
|
* @customEditors: imsyy
|
||||||
|
* @lastEditTime: 2024-01-02
|
||||||
|
*/
|
||||||
|
|
||||||
|
const Router = require("koa-router");
|
||||||
|
const doubanGroupNewRouter = new Router();
|
||||||
|
const axios = require("axios");
|
||||||
|
const cheerio = require("cheerio");
|
||||||
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
|
// 接口信息
|
||||||
|
const routerInfo = {
|
||||||
|
name: "douban_group",
|
||||||
|
title: "豆瓣讨论小组",
|
||||||
|
subtitle: "精选",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 缓存键名
|
||||||
|
const cacheKey = "doubanGroupData";
|
||||||
|
|
||||||
|
// 调用时间
|
||||||
|
let updateTime = new Date().toISOString();
|
||||||
|
|
||||||
|
const url = "https://www.douban.com/group/explore";
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
accept:
|
||||||
|
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
||||||
|
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
|
||||||
|
"cache-control": "max-age=0",
|
||||||
|
"sec-ch-ua": '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
|
||||||
|
"sec-ch-ua-mobile": "?0",
|
||||||
|
"sec-ch-ua-platform": '"Windows"',
|
||||||
|
"sec-fetch-dest": "document",
|
||||||
|
"sec-fetch-mode": "navigate",
|
||||||
|
"sec-fetch-site": "none",
|
||||||
|
"sec-fetch-user": "?1",
|
||||||
|
"upgrade-insecure-requests": "1",
|
||||||
|
// "cookie": "bid=lLpb6D1JLuw; douban-fav-remind=1; _pk_id.100001.8cb4=e7d91ae46530fd1d.1680518589.; ll=\"118281\"; _pk_ref.100001.8cb4=%5B%22%22%2C%22%22%2C1703602972%2C%22http%3A%2F%2Fnew.xianbao.fun%2F%22%5D; _pk_ses.100001.8cb4=1; ap_v=0,6.0"
|
||||||
|
};
|
||||||
|
|
||||||
|
// 数据处理
|
||||||
|
const getData = (data) => {
|
||||||
|
if (!data) return false;
|
||||||
|
const dataList = [];
|
||||||
|
const $ = cheerio.load(data);
|
||||||
|
try {
|
||||||
|
$(`.channel-item`).each((i, e) => {
|
||||||
|
// console.log($(e).html());
|
||||||
|
const item = cheerio.load($(e).html());
|
||||||
|
const title = item("h3")
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
const url = item("h3 a").attr("href");
|
||||||
|
const hot = item('div[class="likes"]')
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
const desc = item('div[class="block"]')
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$|\n)/g, "");
|
||||||
|
const source = item('div[class="source"] a')
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
// const excerpt = item('.channel-item-desc').text().replace(/(^\s*)|(\s*$)/g, "")
|
||||||
|
// console.log(title);
|
||||||
|
// console.log(url);
|
||||||
|
dataList.push({
|
||||||
|
title: title,
|
||||||
|
desc: desc,
|
||||||
|
url: url,
|
||||||
|
mobileUrl: url,
|
||||||
|
hot: hot,
|
||||||
|
source: source,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return dataList;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("数据处理出错" + error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// trending
|
||||||
|
doubanGroupNewRouter.get("/douban_group", async (ctx) => {
|
||||||
|
console.log("获取豆瓣讨论小组精选");
|
||||||
|
try {
|
||||||
|
// 从缓存中获取数据
|
||||||
|
let data = await get(cacheKey);
|
||||||
|
const from = data ? "cache" : "server";
|
||||||
|
if (!data) {
|
||||||
|
// 如果缓存中不存在数据
|
||||||
|
console.log("从服务端重新豆瓣讨论小组精选");
|
||||||
|
// 从服务器拉取数据
|
||||||
|
const response = await axios.get(url, { headers });
|
||||||
|
// console.log(response.data);
|
||||||
|
data = getData(response.data);
|
||||||
|
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
if (!data) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 将数据写入缓存
|
||||||
|
await set(cacheKey, data);
|
||||||
|
}
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
from,
|
||||||
|
total: data.length,
|
||||||
|
updateTime,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 豆瓣新片榜 - 获取最新数据
|
||||||
|
doubanGroupNewRouter.get("/douban_group/new", async (ctx) => {
|
||||||
|
console.log("获取豆瓣讨论小组精选 - 最新数据");
|
||||||
|
try {
|
||||||
|
// 从服务器拉取最新数据
|
||||||
|
const response = await axios.get(url, { headers });
|
||||||
|
const newData = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
console.log("从服务端重新豆瓣讨论小组精选");
|
||||||
|
|
||||||
|
// 返回最新数据
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
updateTime,
|
||||||
|
total: newData.length,
|
||||||
|
data: newData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除旧数据
|
||||||
|
await del(cacheKey);
|
||||||
|
// 将最新数据写入缓存
|
||||||
|
await set(cacheKey, newData);
|
||||||
|
} catch (error) {
|
||||||
|
// 如果拉取最新数据失败,尝试从缓存中获取数据
|
||||||
|
console.error(error);
|
||||||
|
const cachedData = await get(cacheKey);
|
||||||
|
if (cachedData) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: cachedData.length,
|
||||||
|
updateTime,
|
||||||
|
data: cachedData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 如果缓存中也没有数据,则返回错误信息
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
doubanGroupNewRouter.info = routerInfo;
|
||||||
|
module.exports = doubanGroupNewRouter;
|
||||||
159
routes/douban_new.js
Normal file
159
routes/douban_new.js
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
/*
|
||||||
|
* @author: MyFaith
|
||||||
|
* @date: 2023-09-06
|
||||||
|
* @customEditors: imsyy
|
||||||
|
* @lastEditTime: 2023-09-06
|
||||||
|
*/
|
||||||
|
|
||||||
|
const Router = require("koa-router");
|
||||||
|
const doubanNewRouter = new Router();
|
||||||
|
const axios = require("axios");
|
||||||
|
const cheerio = require("cheerio");
|
||||||
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
|
// 接口信息
|
||||||
|
const routerInfo = {
|
||||||
|
name: "douban_new",
|
||||||
|
title: "豆瓣",
|
||||||
|
subtitle: "新片榜",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 缓存键名
|
||||||
|
const cacheKey = "doubanNewData";
|
||||||
|
|
||||||
|
// 调用时间
|
||||||
|
let updateTime = new Date().toISOString();
|
||||||
|
|
||||||
|
// 调用路径
|
||||||
|
const url = "https://movie.douban.com/chart/";
|
||||||
|
const headers = {
|
||||||
|
"User-Agent":
|
||||||
|
"Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 豆瓣新片榜单特殊处理 - 标题
|
||||||
|
const replaceTitle = (title, score) => {
|
||||||
|
return `[★${score}] ` + title.replace(/\n/g, "").replace(/ /g, "").replace(/\//g, " / ").trim();
|
||||||
|
};
|
||||||
|
|
||||||
|
// 数据处理
|
||||||
|
const getData = (data) => {
|
||||||
|
if (!data) return false;
|
||||||
|
const dataList = [];
|
||||||
|
const $ = cheerio.load(data);
|
||||||
|
try {
|
||||||
|
$(".article .item").map((idx, item) => {
|
||||||
|
const id = $(item).find("a").attr("href").split("/").at(-2) ?? "";
|
||||||
|
const score = $(item).find(".rating_nums").text() ?? "";
|
||||||
|
|
||||||
|
dataList.push({
|
||||||
|
title: replaceTitle($(item).find("a").text(), score),
|
||||||
|
desc: $(item).find("p").text(),
|
||||||
|
score,
|
||||||
|
comments: $(item).find("span.pl").text().match(/\d+/)?.[0] ?? "",
|
||||||
|
pic: $(item).find("img").attr("src") ?? "",
|
||||||
|
url: $(item).find("a").attr("href") ?? "",
|
||||||
|
mobileUrl: `https://m.douban.com/movie/subject/${id}`,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return dataList;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("数据处理出错" + error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 豆瓣新片榜
|
||||||
|
doubanNewRouter.get("/douban_new", async (ctx) => {
|
||||||
|
console.log("获取豆瓣新片榜");
|
||||||
|
try {
|
||||||
|
// 从缓存中获取数据
|
||||||
|
let data = await get(cacheKey);
|
||||||
|
const from = data ? "cache" : "server";
|
||||||
|
if (!data) {
|
||||||
|
// 如果缓存中不存在数据
|
||||||
|
console.log("从服务端重新获取豆瓣新片榜");
|
||||||
|
// 从服务器拉取数据
|
||||||
|
const response = await axios.get(url, { headers });
|
||||||
|
data = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
if (!data) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 将数据写入缓存
|
||||||
|
await set(cacheKey, data);
|
||||||
|
}
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
from,
|
||||||
|
total: data.length,
|
||||||
|
updateTime,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 豆瓣新片榜 - 获取最新数据
|
||||||
|
doubanNewRouter.get("/douban_new/new", async (ctx) => {
|
||||||
|
console.log("获取豆瓣新片榜 - 最新数据");
|
||||||
|
try {
|
||||||
|
// 从服务器拉取最新数据
|
||||||
|
const response = await axios.get(url, { headers });
|
||||||
|
const newData = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
console.log("从服务端重新获取豆瓣新片榜");
|
||||||
|
|
||||||
|
// 返回最新数据
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
updateTime,
|
||||||
|
total: newData.length,
|
||||||
|
data: newData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除旧数据
|
||||||
|
await del(cacheKey);
|
||||||
|
// 将最新数据写入缓存
|
||||||
|
await set(cacheKey, newData);
|
||||||
|
} catch (error) {
|
||||||
|
// 如果拉取最新数据失败,尝试从缓存中获取数据
|
||||||
|
console.error(error);
|
||||||
|
const cachedData = await get(cacheKey);
|
||||||
|
if (cachedData) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: cachedData.length,
|
||||||
|
updateTime,
|
||||||
|
data: cachedData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 如果缓存中也没有数据,则返回错误信息
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
doubanNewRouter.info = routerInfo;
|
||||||
|
module.exports = doubanNewRouter;
|
||||||
@@ -5,6 +5,7 @@ const { get, set, del } = require("../utils/cacheData");
|
|||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
|
name: "douyin",
|
||||||
title: "抖音",
|
title: "抖音",
|
||||||
subtitle: "热点榜",
|
subtitle: "热点榜",
|
||||||
};
|
};
|
||||||
@@ -21,8 +22,7 @@ const url =
|
|||||||
"https://www.douyin.com/aweme/v1/web/hot/search/list/?device_platform=webapp&aid=6383&channel=channel_pc_web&detail_list=1&round_trip_time=50";
|
"https://www.douyin.com/aweme/v1/web/hot/search/list/?device_platform=webapp&aid=6383&channel=channel_pc_web&detail_list=1&round_trip_time=50";
|
||||||
|
|
||||||
// Token 获取路径
|
// Token 获取路径
|
||||||
const cookisUrl =
|
const cookisUrl = "https://www.douyin.com/passport/general/login_guiding_strategy/?aid=6383";
|
||||||
"https://www.douyin.com/passport/general/login_guiding_strategy/?aid=6383";
|
|
||||||
|
|
||||||
// 数据处理
|
// 数据处理
|
||||||
const getData = (data) => {
|
const getData = (data) => {
|
||||||
@@ -36,9 +36,7 @@ const getData = (data) => {
|
|||||||
pic: `${v.word_cover.url_list[0]}`,
|
pic: `${v.word_cover.url_list[0]}`,
|
||||||
hot: Number(v.hot_value),
|
hot: Number(v.hot_value),
|
||||||
url: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
|
url: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
|
||||||
mobileUrl: `https://www.douyin.com/hot/${encodeURIComponent(
|
mobileUrl: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
|
||||||
v.sentence_id
|
|
||||||
)}`,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return dataList;
|
return dataList;
|
||||||
|
|||||||
155
routes/douyin_music.js
Normal file
155
routes/douyin_music.js
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
/*
|
||||||
|
* @author: WangPeng
|
||||||
|
* @date: 2023-07-11 16:41:48
|
||||||
|
* @customEditors: imsyy
|
||||||
|
* @lastEditTime: 2023-07-11 16:03:12
|
||||||
|
*/
|
||||||
|
|
||||||
|
const Router = require("koa-router");
|
||||||
|
const douyinMusicRouter = new Router();
|
||||||
|
const axios = require("axios");
|
||||||
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
|
// 接口信息
|
||||||
|
const routerInfo = {
|
||||||
|
name: "douyin_music",
|
||||||
|
title: "抖音",
|
||||||
|
subtitle: "热歌榜",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 缓存键名
|
||||||
|
const cacheKey = "douyinMusicData";
|
||||||
|
|
||||||
|
// 调用时间
|
||||||
|
let updateTime = new Date().toISOString();
|
||||||
|
|
||||||
|
// 调用路径
|
||||||
|
const url = "https://aweme.snssdk.com/aweme/v1/chart/music/list/";
|
||||||
|
const HEADERS = {
|
||||||
|
"user-agent": "okhttp3",
|
||||||
|
};
|
||||||
|
const QUERIES = {
|
||||||
|
device_platform: "android",
|
||||||
|
version_name: "13.2.0",
|
||||||
|
version_code: "130200",
|
||||||
|
aid: "1128",
|
||||||
|
chart_id: "6853972723954146568",
|
||||||
|
count: "100",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 数据处理
|
||||||
|
const getData = (data) => {
|
||||||
|
if (!data) return [];
|
||||||
|
try {
|
||||||
|
return data.map((v) => {
|
||||||
|
const item = v.music_info;
|
||||||
|
return {
|
||||||
|
id: item.id,
|
||||||
|
title: item.title,
|
||||||
|
album: item.album,
|
||||||
|
artist: item.author,
|
||||||
|
pic: item?.cover_large.url_list[0],
|
||||||
|
lyric: item.lyric_url,
|
||||||
|
url: item.play_url.uri,
|
||||||
|
mobileUrl: item.play_url.uri,
|
||||||
|
// h5Url: item.matched_song?.h5_url,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("数据处理出错" + error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 抖音热歌榜
|
||||||
|
douyinMusicRouter.get("/douyin_music", async (ctx) => {
|
||||||
|
console.log("获取抖音热歌榜");
|
||||||
|
try {
|
||||||
|
// 从缓存中获取数据
|
||||||
|
let data = await get(cacheKey);
|
||||||
|
const from = data ? "cache" : "server";
|
||||||
|
if (!data) {
|
||||||
|
// 如果缓存中不存在数据
|
||||||
|
console.log("从服务端重新获取抖音热歌榜");
|
||||||
|
// 从服务器拉取数据
|
||||||
|
const response = await axios.get(url, {
|
||||||
|
headers: HEADERS,
|
||||||
|
params: QUERIES,
|
||||||
|
});
|
||||||
|
data = getData(response.data.music_list);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
// 将数据写入缓存
|
||||||
|
await set(cacheKey, data);
|
||||||
|
}
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
from,
|
||||||
|
total: data.length,
|
||||||
|
updateTime,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 抖音热歌榜 - 获取最新数据
|
||||||
|
douyinMusicRouter.get("/douyin_music/new", async (ctx) => {
|
||||||
|
console.log("获取抖音热歌榜 - 最新数据");
|
||||||
|
try {
|
||||||
|
// 从服务器拉取最新数据
|
||||||
|
const response = await axios.get(url, {
|
||||||
|
headers: HEADERS,
|
||||||
|
params: QUERIES,
|
||||||
|
});
|
||||||
|
const newData = getData(response.data.word_list);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
console.log("从服务端重新获取抖音热歌榜");
|
||||||
|
|
||||||
|
// 返回最新数据
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: newData.length,
|
||||||
|
updateTime,
|
||||||
|
data: newData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除旧数据
|
||||||
|
await del(cacheKey);
|
||||||
|
// 将最新数据写入缓存
|
||||||
|
await set(cacheKey, newData);
|
||||||
|
} catch (error) {
|
||||||
|
// 如果拉取最新数据失败,尝试从缓存中获取数据
|
||||||
|
console.error(error);
|
||||||
|
const cachedData = await get(cacheKey);
|
||||||
|
if (cachedData) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: cachedData.length,
|
||||||
|
updateTime,
|
||||||
|
data: cachedData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 如果缓存中也没有数据,则返回错误信息
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
douyinMusicRouter.info = routerInfo;
|
||||||
|
module.exports = douyinMusicRouter;
|
||||||
149
routes/douyin_new.js
Normal file
149
routes/douyin_new.js
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
/*
|
||||||
|
* @author: WangPeng
|
||||||
|
* @date: 2023-07-10 16:56:01
|
||||||
|
* @customEditors: imsyy
|
||||||
|
* @lastEditTime: 2023-07-11 16:54:38
|
||||||
|
*/
|
||||||
|
|
||||||
|
const Router = require("koa-router");
|
||||||
|
const douyinNewRouter = new Router();
|
||||||
|
const axios = require("axios");
|
||||||
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
|
// 接口信息
|
||||||
|
const routerInfo = {
|
||||||
|
name: "douyin",
|
||||||
|
title: "抖音",
|
||||||
|
subtitle: "热点榜",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 缓存键名
|
||||||
|
const cacheKey = "douyinHotNewData";
|
||||||
|
|
||||||
|
// 调用时间
|
||||||
|
let updateTime = new Date().toISOString();
|
||||||
|
|
||||||
|
// 调用路径
|
||||||
|
const url = "https://aweme.snssdk.com/aweme/v1/hot/search/list/";
|
||||||
|
const HEADERS = {
|
||||||
|
"user-agent": "okhttp3",
|
||||||
|
};
|
||||||
|
const QUERIES = {
|
||||||
|
device_platform: "android",
|
||||||
|
version_name: "13.2.0",
|
||||||
|
version_code: "130200",
|
||||||
|
aid: "1128",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 数据处理
|
||||||
|
const getData = (data) => {
|
||||||
|
if (!data) return [];
|
||||||
|
try {
|
||||||
|
const jsonObject = data.data.word_list;
|
||||||
|
return jsonObject.map((v) => {
|
||||||
|
return {
|
||||||
|
title: v.word,
|
||||||
|
pic: `${v.word_cover.url_list[0]}`,
|
||||||
|
hot: Number(v.hot_value),
|
||||||
|
url: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
|
||||||
|
mobileUrl: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("数据处理出错" + error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 抖音热点榜
|
||||||
|
douyinNewRouter.get("/douyin_new", async (ctx) => {
|
||||||
|
console.log("获取抖音热点榜");
|
||||||
|
try {
|
||||||
|
// 从缓存中获取数据
|
||||||
|
let data = await get(cacheKey);
|
||||||
|
const from = data ? "cache" : "server";
|
||||||
|
if (!data) {
|
||||||
|
// 如果缓存中不存在数据
|
||||||
|
console.log("从服务端重新获取抖音热点榜");
|
||||||
|
// 从服务器拉取数据
|
||||||
|
const response = await axios.get(url, {
|
||||||
|
headers: HEADERS,
|
||||||
|
params: QUERIES,
|
||||||
|
});
|
||||||
|
data = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
// 将数据写入缓存
|
||||||
|
await set(cacheKey, data);
|
||||||
|
}
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
from,
|
||||||
|
total: data.length,
|
||||||
|
updateTime,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 抖音热点榜 - 获取最新数据
|
||||||
|
douyinNewRouter.get("/douyin_new/new", async (ctx) => {
|
||||||
|
console.log("获取抖音热点榜 - 最新数据");
|
||||||
|
try {
|
||||||
|
// 从服务器拉取最新数据
|
||||||
|
const response = await axios.get(url, {
|
||||||
|
headers: HEADERS,
|
||||||
|
params: QUERIES,
|
||||||
|
});
|
||||||
|
const newData = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
console.log("从服务端重新获取抖音热点榜");
|
||||||
|
|
||||||
|
// 返回最新数据
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: newData.length,
|
||||||
|
updateTime,
|
||||||
|
data: newData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除旧数据
|
||||||
|
await del(cacheKey);
|
||||||
|
// 将最新数据写入缓存
|
||||||
|
await set(cacheKey, newData);
|
||||||
|
} catch (error) {
|
||||||
|
// 如果拉取最新数据失败,尝试从缓存中获取数据
|
||||||
|
console.error(error);
|
||||||
|
const cachedData = await get(cacheKey);
|
||||||
|
if (cachedData) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: cachedData.length,
|
||||||
|
updateTime,
|
||||||
|
data: cachedData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 如果缓存中也没有数据,则返回错误信息
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
douyinNewRouter.info = routerInfo;
|
||||||
|
module.exports = douyinNewRouter;
|
||||||
123
routes/genshin.js
Normal file
123
routes/genshin.js
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
const Router = require("koa-router");
|
||||||
|
const genshinRouter = new Router();
|
||||||
|
const axios = require("axios");
|
||||||
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
|
// 接口信息
|
||||||
|
const routerInfo = {
|
||||||
|
name: "genshin",
|
||||||
|
title: "原神",
|
||||||
|
subtitle: "最新信息",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 缓存键名
|
||||||
|
const cacheKey = "genshinData";
|
||||||
|
|
||||||
|
// 调用时间
|
||||||
|
let updateTime = new Date().toISOString();
|
||||||
|
|
||||||
|
// 调用路径
|
||||||
|
const url =
|
||||||
|
"https://content-static.mihoyo.com/content/ysCn/getContentList?pageSize=50&pageNum=1&channelId=10";
|
||||||
|
|
||||||
|
// 数据处理
|
||||||
|
const getData = (data) => {
|
||||||
|
if (!data) return [];
|
||||||
|
return data.map((v) => {
|
||||||
|
return {
|
||||||
|
id: v.id,
|
||||||
|
title: v.title,
|
||||||
|
pic: v.ext[1]?.value[0]?.url,
|
||||||
|
start_time: v?.start_time,
|
||||||
|
url: `https://ys.mihoyo.com/main/news/detail/${v.id}`,
|
||||||
|
mobileUrl: `https://ys.mihoyo.com/main/m/news/detail/${v.id}`,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 原神最新信息
|
||||||
|
genshinRouter.get("/genshin", async (ctx) => {
|
||||||
|
console.log("获取原神最新信息");
|
||||||
|
try {
|
||||||
|
// 从缓存中获取数据
|
||||||
|
let data = await get(cacheKey);
|
||||||
|
const from = data ? "cache" : "server";
|
||||||
|
if (!data) {
|
||||||
|
// 如果缓存中不存在数据
|
||||||
|
console.log("从服务端重新获取原神最新信息");
|
||||||
|
// 从服务器拉取数据
|
||||||
|
const response = await axios.get(url);
|
||||||
|
data = getData(response.data.data.list);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
// 将数据写入缓存
|
||||||
|
await set(cacheKey, data);
|
||||||
|
}
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
from,
|
||||||
|
total: data.length,
|
||||||
|
updateTime,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 原神最新信息 - 获取最新数据
|
||||||
|
genshinRouter.get("/genshin/new", async (ctx) => {
|
||||||
|
console.log("获取原神最新信息 - 最新数据");
|
||||||
|
try {
|
||||||
|
// 从服务器拉取最新数据
|
||||||
|
const response = await axios.get(url);
|
||||||
|
const newData = getData(response.data.data.list);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
console.log("从服务端重新获取原神最新信息");
|
||||||
|
|
||||||
|
// 返回最新数据
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: newData.length,
|
||||||
|
updateTime,
|
||||||
|
data: newData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除旧数据
|
||||||
|
await del(cacheKey);
|
||||||
|
// 将最新数据写入缓存
|
||||||
|
await set(cacheKey, newData);
|
||||||
|
} catch (error) {
|
||||||
|
// 如果拉取最新数据失败,尝试从缓存中获取数据
|
||||||
|
console.error(error);
|
||||||
|
const cachedData = await get(cacheKey);
|
||||||
|
if (cachedData) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: cachedData.length,
|
||||||
|
updateTime,
|
||||||
|
data: cachedData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 如果缓存中也没有数据,则返回错误信息
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
genshinRouter.info = routerInfo;
|
||||||
|
module.exports = genshinRouter;
|
||||||
174
routes/github.js
Normal file
174
routes/github.js
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
/*
|
||||||
|
* @author: x-dr
|
||||||
|
* @date: 2023-12-25
|
||||||
|
* @customEditors: imsyy
|
||||||
|
* @lastEditTime: 2023-12-27
|
||||||
|
*/
|
||||||
|
|
||||||
|
const Router = require("koa-router");
|
||||||
|
const githubNewRouter = new Router();
|
||||||
|
const axios = require("axios");
|
||||||
|
const cheerio = require("cheerio");
|
||||||
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
|
// 接口信息
|
||||||
|
const routerInfo = {
|
||||||
|
name: "github",
|
||||||
|
title: "Github",
|
||||||
|
subtitle: "trending",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 缓存键名
|
||||||
|
const cacheKey = "githubData";
|
||||||
|
|
||||||
|
// 调用时间
|
||||||
|
let updateTime = new Date().toISOString();
|
||||||
|
|
||||||
|
const url = "https://github.com/trending";
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
"User-Agent":
|
||||||
|
"Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 数据处理
|
||||||
|
const getData = (data) => {
|
||||||
|
if (!data) return false;
|
||||||
|
const dataList = [];
|
||||||
|
const $ = cheerio.load(data);
|
||||||
|
try {
|
||||||
|
$(`.Box-row`).each((i, e) => {
|
||||||
|
// console.log(getCheerio(e).html());
|
||||||
|
const item = cheerio.load($(e).html());
|
||||||
|
// console.log(item);
|
||||||
|
const title = item("h2 a").attr("href").replace("/", "");
|
||||||
|
const url = `https://github.com/${title}`;
|
||||||
|
const excerpt = item("p")
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
const language = item('.f6 span[itemprop="programmingLanguage"]')
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
const stars = item(".f6 a:first")
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
const forks = item(".f6 a:eq(1)")
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
const starstoday = item(".f6 span:eq(4)")
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
|
||||||
|
dataList.push({
|
||||||
|
title: title,
|
||||||
|
desc: excerpt,
|
||||||
|
url: url,
|
||||||
|
language: language,
|
||||||
|
stars: stars,
|
||||||
|
forks: forks,
|
||||||
|
starstoday: starstoday,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return dataList;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("数据处理出错" + error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// trending
|
||||||
|
githubNewRouter.get("/github", async (ctx) => {
|
||||||
|
console.log("获取github trending");
|
||||||
|
try {
|
||||||
|
// 从缓存中获取数据
|
||||||
|
let data = await get(cacheKey);
|
||||||
|
const from = data ? "cache" : "server";
|
||||||
|
if (!data) {
|
||||||
|
// 如果缓存中不存在数据
|
||||||
|
console.log("从服务端重新github trending");
|
||||||
|
// 从服务器拉取数据
|
||||||
|
const response = await axios.get(url, { headers });
|
||||||
|
// console.log(response.data);
|
||||||
|
data = getData(response.data);
|
||||||
|
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
if (!data) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 将数据写入缓存
|
||||||
|
await set(cacheKey, data);
|
||||||
|
}
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
from,
|
||||||
|
total: data.length,
|
||||||
|
updateTime,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// trending - 获取最新数据
|
||||||
|
githubNewRouter.get("/github/new", async (ctx) => {
|
||||||
|
console.log("获取github trending - 最新数据");
|
||||||
|
try {
|
||||||
|
// 从服务器拉取最新数据
|
||||||
|
const response = await axios.get(url, { headers });
|
||||||
|
const newData = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
console.log("从服务端重新github trending");
|
||||||
|
|
||||||
|
// 返回最新数据
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
updateTime,
|
||||||
|
total: newData.length,
|
||||||
|
data: newData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除旧数据
|
||||||
|
await del(cacheKey);
|
||||||
|
// 将最新数据写入缓存
|
||||||
|
await set(cacheKey, newData);
|
||||||
|
} catch (error) {
|
||||||
|
// 如果拉取最新数据失败,尝试从缓存中获取数据
|
||||||
|
console.error(error);
|
||||||
|
const cachedData = await get(cacheKey);
|
||||||
|
if (cachedData) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: cachedData.length,
|
||||||
|
updateTime,
|
||||||
|
data: cachedData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 如果缓存中也没有数据,则返回错误信息
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
githubNewRouter.info = routerInfo;
|
||||||
|
module.exports = githubNewRouter;
|
||||||
@@ -6,6 +6,7 @@ const { get, set, del } = require("../utils/cacheData");
|
|||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
|
name: "ithome",
|
||||||
title: "IT之家",
|
title: "IT之家",
|
||||||
subtitle: "热榜",
|
subtitle: "热榜",
|
||||||
};
|
};
|
||||||
@@ -35,14 +36,13 @@ const getData = (data) => {
|
|||||||
const dataList = [];
|
const dataList = [];
|
||||||
const $ = cheerio.load(data);
|
const $ = cheerio.load(data);
|
||||||
try {
|
try {
|
||||||
$(".rank-name").each(function () {
|
$(".rank-name").each(() => {
|
||||||
const type = $(this).data("rank-type");
|
const type = $(this).data("rank-type");
|
||||||
const newListHtml = $(this).next(".rank-box").html();
|
const newListHtml = $(this).next(".rank-box").html();
|
||||||
cheerio
|
cheerio
|
||||||
.load(newListHtml)(".placeholder")
|
.load(newListHtml)(".placeholder")
|
||||||
.get()
|
.get()
|
||||||
.map((v) => {
|
.map((v) => {
|
||||||
console.log($(v));
|
|
||||||
dataList.push({
|
dataList.push({
|
||||||
title: $(v).find(".plc-title").text(),
|
title: $(v).find(".plc-title").text(),
|
||||||
img: $(v).find("img").attr("data-original"),
|
img: $(v).find("img").attr("data-original"),
|
||||||
@@ -127,7 +127,7 @@ itHomeRouter.get("/ithome/new", async (ctx) => {
|
|||||||
message: "获取成功",
|
message: "获取成功",
|
||||||
...routerInfo,
|
...routerInfo,
|
||||||
updateTime,
|
updateTime,
|
||||||
total: data.length,
|
total: newData.length,
|
||||||
data: newData,
|
data: newData,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ itHomeRouter.get("/ithome/new", async (ctx) => {
|
|||||||
code: 200,
|
code: 200,
|
||||||
message: "获取成功",
|
message: "获取成功",
|
||||||
...routerInfo,
|
...routerInfo,
|
||||||
total: data.length,
|
total: cachedData.length,
|
||||||
updateTime,
|
updateTime,
|
||||||
data: cachedData,
|
data: cachedData,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const { get, set, del } = require("../utils/cacheData");
|
|||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
|
name: "juejin",
|
||||||
title: "稀土掘金",
|
title: "稀土掘金",
|
||||||
subtitle: "热榜",
|
subtitle: "热榜",
|
||||||
};
|
};
|
||||||
@@ -16,8 +17,7 @@ const cacheKey = "juejinData";
|
|||||||
let updateTime = new Date().toISOString();
|
let updateTime = new Date().toISOString();
|
||||||
|
|
||||||
// 调用路径
|
// 调用路径
|
||||||
const url =
|
const url = "https://api.juejin.cn/content_api/v1/content/article_rank?category_id=1&type=hot";
|
||||||
"https://api.juejin.cn/content_api/v1/content/article_rank?category_id=1&type=hot";
|
|
||||||
|
|
||||||
// 数据处理
|
// 数据处理
|
||||||
const getData = (data) => {
|
const getData = (data) => {
|
||||||
|
|||||||
162
routes/kuaishou.js
Normal file
162
routes/kuaishou.js
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
/*
|
||||||
|
* @author: MCBBC
|
||||||
|
* @date: 2023-07-17
|
||||||
|
* @customEditors: imsyy
|
||||||
|
* @lastEditTime: 2023-07-17
|
||||||
|
*/
|
||||||
|
|
||||||
|
const Router = require("koa-router");
|
||||||
|
const kuaishouRouter = new Router();
|
||||||
|
const axios = require("axios");
|
||||||
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
|
// 接口信息
|
||||||
|
const routerInfo = {
|
||||||
|
name: "kuaishou",
|
||||||
|
title: "快手",
|
||||||
|
subtitle: "热榜",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 缓存键名
|
||||||
|
const cacheKey = "kuaishouData";
|
||||||
|
|
||||||
|
// 调用时间
|
||||||
|
let updateTime = new Date().toISOString();
|
||||||
|
|
||||||
|
// 调用路径
|
||||||
|
const url = "https://www.kuaishou.com/?isHome=1";
|
||||||
|
|
||||||
|
// Unicode 解码
|
||||||
|
const decodedString = (encodedString) => {
|
||||||
|
return encodedString.replace(/\\u([\d\w]{4})/gi, (match, grp) =>
|
||||||
|
String.fromCharCode(parseInt(grp, 16)),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 数据处理
|
||||||
|
const getData = (data) => {
|
||||||
|
if (!data) return [];
|
||||||
|
const dataList = [];
|
||||||
|
try {
|
||||||
|
const pattern = /window.__APOLLO_STATE__=(.*);\(function\(\)/s;
|
||||||
|
const idPattern = /clientCacheKey=([A-Za-z0-9]+)/s;
|
||||||
|
const matchResult = data.match(pattern);
|
||||||
|
const jsonObject = JSON.parse(matchResult[1])["defaultClient"];
|
||||||
|
|
||||||
|
// 获取所有分类
|
||||||
|
const allItems = jsonObject['$ROOT_QUERY.visionHotRank({"page":"home"})']["items"];
|
||||||
|
// 遍历所有分类
|
||||||
|
allItems.forEach((v) => {
|
||||||
|
// 基础数据
|
||||||
|
const image = jsonObject[v.id]["poster"];
|
||||||
|
const id = image.match(idPattern)[1];
|
||||||
|
// 数据处理
|
||||||
|
dataList.push({
|
||||||
|
title: jsonObject[v.id]["name"],
|
||||||
|
pic: decodedString(image),
|
||||||
|
hot: jsonObject[v.id]["hotValue"],
|
||||||
|
url: `https://www.kuaishou.com/short-video/${id}`,
|
||||||
|
mobileUrl: `https://www.kuaishou.com/short-video/${id}`,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return dataList;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("数据处理出错" + error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 快手热榜
|
||||||
|
kuaishouRouter.get("/kuaishou", async (ctx) => {
|
||||||
|
console.log("获取快手热榜");
|
||||||
|
try {
|
||||||
|
// 从缓存中获取数据
|
||||||
|
let data = await get(cacheKey);
|
||||||
|
const from = data ? "cache" : "server";
|
||||||
|
if (!data) {
|
||||||
|
// 如果缓存中不存在数据
|
||||||
|
console.log("从服务端重新获取快手热榜");
|
||||||
|
// 从服务器拉取数据
|
||||||
|
const response = await axios.get(url);
|
||||||
|
data = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
if (!data) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 将数据写入缓存
|
||||||
|
await set(cacheKey, data);
|
||||||
|
}
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
from,
|
||||||
|
total: data.length,
|
||||||
|
updateTime,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 快手热榜 - 获取最新数据
|
||||||
|
kuaishouRouter.get("/kuaishou/new", async (ctx) => {
|
||||||
|
console.log("获取快手热榜 - 最新数据");
|
||||||
|
try {
|
||||||
|
// 从服务器拉取最新数据
|
||||||
|
const response = await axios.get(url);
|
||||||
|
const newData = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
console.log("从服务端重新获取快手热榜");
|
||||||
|
|
||||||
|
// 返回最新数据
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: newData.length,
|
||||||
|
updateTime,
|
||||||
|
data: newData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除旧数据
|
||||||
|
await del(cacheKey);
|
||||||
|
// 将最新数据写入缓存
|
||||||
|
await set(cacheKey, newData);
|
||||||
|
} catch (error) {
|
||||||
|
// 如果拉取最新数据失败,尝试从缓存中获取数据
|
||||||
|
console.error(error);
|
||||||
|
const cachedData = await get(cacheKey);
|
||||||
|
if (cachedData) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: cachedData.length,
|
||||||
|
updateTime,
|
||||||
|
data: cachedData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 如果缓存中也没有数据,则返回错误信息
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
kuaishouRouter.info = routerInfo;
|
||||||
|
module.exports = kuaishouRouter;
|
||||||
@@ -5,6 +5,7 @@ const { get, set, del } = require("../utils/cacheData");
|
|||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
|
name: "lol",
|
||||||
title: "英雄联盟",
|
title: "英雄联盟",
|
||||||
subtitle: "更新公告",
|
subtitle: "更新公告",
|
||||||
};
|
};
|
||||||
@@ -17,28 +18,23 @@ let updateTime = new Date().toISOString();
|
|||||||
|
|
||||||
// 调用路径
|
// 调用路径
|
||||||
const url =
|
const url =
|
||||||
"https://apps.game.qq.com/cmc/zmMcnTargetContentList?r0=jsonp&page=1&num=16&target=24&source=web_pc&r1=jQuery191002324053053181463_1687855508930&_=1687855508933";
|
"https://apps.game.qq.com/cmc/zmMcnTargetContentList?r0=jsonp&page=1&num=16&target=24&source=web_pc";
|
||||||
|
|
||||||
// 数据处理
|
// 数据处理
|
||||||
const getData = (data) => {
|
const getData = (data) => {
|
||||||
if (!data) return [];
|
if (!data) return [];
|
||||||
const dataList = [];
|
const dataList = [];
|
||||||
try {
|
try {
|
||||||
const pattern = /jQuery191002324053053181463_1687855508930\((.*?)\)/s;
|
const match = data.match(/callback\((.*)\)/);
|
||||||
const matchResult = data.match(pattern);
|
const jsonObject = JSON.parse(match[1]).data.result;
|
||||||
const jsonObject = JSON.parse(matchResult[1])["data"].result;
|
|
||||||
jsonObject.forEach((v) => {
|
jsonObject.forEach((v) => {
|
||||||
dataList.push({
|
dataList.push({
|
||||||
title: v.sTitle,
|
title: v.sTitle,
|
||||||
desc: v.sAuthor,
|
desc: v.sAuthor,
|
||||||
pic: `https:${v.sIMG}`,
|
pic: `https:${v.sIMG}`,
|
||||||
hot: Number(v.iTotalPlay),
|
hot: Number(v.iTotalPlay),
|
||||||
url: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(
|
url: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(v.iDocID)}`,
|
||||||
v.iDocID
|
mobileUrl: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(v.iDocID)}`,
|
||||||
)}`,
|
|
||||||
mobileUrl: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(
|
|
||||||
v.iDocID
|
|
||||||
)}`,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return dataList;
|
return dataList;
|
||||||
|
|||||||
130
routes/netease.js
Normal file
130
routes/netease.js
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
/*
|
||||||
|
* @author: MCBBC
|
||||||
|
* @date: 2023-07-17
|
||||||
|
* @customEditors: imsyy
|
||||||
|
* @lastEditTime: 2023-07-17
|
||||||
|
*/
|
||||||
|
|
||||||
|
const Router = require("koa-router");
|
||||||
|
const neteaseRouter = new Router();
|
||||||
|
const axios = require("axios");
|
||||||
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
|
// 接口信息
|
||||||
|
const routerInfo = {
|
||||||
|
name: "netease",
|
||||||
|
title: "网易新闻",
|
||||||
|
subtitle: "热点榜",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 缓存键名
|
||||||
|
const cacheKey = "neteaseData";
|
||||||
|
|
||||||
|
// 调用时间
|
||||||
|
let updateTime = new Date().toISOString();
|
||||||
|
|
||||||
|
// 调用路径
|
||||||
|
const url = "https://m.163.com/fe/api/hot/news/flow";
|
||||||
|
|
||||||
|
// 数据处理
|
||||||
|
const getData = (data) => {
|
||||||
|
if (!data) return [];
|
||||||
|
return data.map((v) => {
|
||||||
|
return {
|
||||||
|
id: v.skipID,
|
||||||
|
title: v.title,
|
||||||
|
desc: v._keyword,
|
||||||
|
pic: v.imgsrc,
|
||||||
|
owner: v.source,
|
||||||
|
url: `https://www.163.com/dy/article/${v.skipID}.html`,
|
||||||
|
mobileUrl: v.url,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 网易新闻热榜
|
||||||
|
neteaseRouter.get("/netease", async (ctx) => {
|
||||||
|
console.log("获取网易新闻热榜");
|
||||||
|
try {
|
||||||
|
// 从缓存中获取数据
|
||||||
|
let data = await get(cacheKey);
|
||||||
|
const from = data ? "cache" : "server";
|
||||||
|
if (!data) {
|
||||||
|
// 如果缓存中不存在数据
|
||||||
|
console.log("从服务端重新获取网易新闻热榜");
|
||||||
|
// 从服务器拉取数据
|
||||||
|
const response = await axios.get(url);
|
||||||
|
data = getData(response.data.data.list);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
// 将数据写入缓存
|
||||||
|
await set(cacheKey, data);
|
||||||
|
}
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
from,
|
||||||
|
total: data.length,
|
||||||
|
updateTime,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 网易新闻热榜 - 获取最新数据
|
||||||
|
neteaseRouter.get("/netease/new", async (ctx) => {
|
||||||
|
console.log("获取网易新闻热榜 - 最新数据");
|
||||||
|
try {
|
||||||
|
// 从服务器拉取最新数据
|
||||||
|
const response = await axios.get(url);
|
||||||
|
const newData = getData(response.data.data.list);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
console.log("从服务端重新获取网易新闻热榜");
|
||||||
|
|
||||||
|
// 返回最新数据
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: newData.length,
|
||||||
|
updateTime,
|
||||||
|
data: newData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除旧数据
|
||||||
|
await del(cacheKey);
|
||||||
|
// 将最新数据写入缓存
|
||||||
|
await set(cacheKey, newData);
|
||||||
|
} catch (error) {
|
||||||
|
// 如果拉取最新数据失败,尝试从缓存中获取数据
|
||||||
|
console.error(error);
|
||||||
|
const cachedData = await get(cacheKey);
|
||||||
|
if (cachedData) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: cachedData.length,
|
||||||
|
updateTime,
|
||||||
|
data: cachedData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 如果缓存中也没有数据,则返回错误信息
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
neteaseRouter.info = routerInfo;
|
||||||
|
module.exports = neteaseRouter;
|
||||||
198
routes/netease_music_toplist.js
Normal file
198
routes/netease_music_toplist.js
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
/**
|
||||||
|
* @author: x-dr
|
||||||
|
* @date: 2023-12-27
|
||||||
|
* @customEditors: imsyy
|
||||||
|
* @lastEditTime: 2024-01-02
|
||||||
|
*/
|
||||||
|
|
||||||
|
const URL = require("url");
|
||||||
|
const Router = require("koa-router");
|
||||||
|
const neteaseMusicRouter = new Router();
|
||||||
|
const axios = require("axios");
|
||||||
|
const cheerio = require("cheerio");
|
||||||
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
|
// 接口信息
|
||||||
|
const routerInfo = {
|
||||||
|
name: "netease_music_toplist",
|
||||||
|
title: "网易云音乐",
|
||||||
|
subtitle: "排行榜",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 缓存键名
|
||||||
|
const cacheKey = "neteasemusicToplistData";
|
||||||
|
|
||||||
|
// 调用时间
|
||||||
|
let updateTime = new Date().toISOString();
|
||||||
|
|
||||||
|
const url = "https://music.163.com/discover/toplist?id=";
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
authority: "music.163.com",
|
||||||
|
referer: "https://music.163.com/",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 榜单类别
|
||||||
|
const listType = {
|
||||||
|
1: {
|
||||||
|
id: 19723756,
|
||||||
|
name: "飙升榜",
|
||||||
|
},
|
||||||
|
2: {
|
||||||
|
id: 3779629,
|
||||||
|
name: "新歌榜",
|
||||||
|
},
|
||||||
|
3: {
|
||||||
|
id: 2884035,
|
||||||
|
name: "原创榜",
|
||||||
|
},
|
||||||
|
4: {
|
||||||
|
id: 3778678,
|
||||||
|
name: "热歌榜",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// 数据处理
|
||||||
|
const getData = (data) => {
|
||||||
|
if (!data) return false;
|
||||||
|
const dataList = [];
|
||||||
|
const $ = cheerio.load(data);
|
||||||
|
try {
|
||||||
|
$(".m-sgitem").each((i, e) => {
|
||||||
|
const urlString = $(e).attr("href");
|
||||||
|
const parsedUrl = URL.parse(urlString, true);
|
||||||
|
const urlidValue = parsedUrl.query.id;
|
||||||
|
const item = cheerio.load($(e).html());
|
||||||
|
const author = item('div[class="f-thide sginfo"]')
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
const title = item('div[class="f-thide sgtl"]')
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
dataList.push({
|
||||||
|
title: title,
|
||||||
|
desc: author,
|
||||||
|
url: `https://music.163.com/#/song?id=${urlidValue}`,
|
||||||
|
mobileUrl: `https://music.163.com/m/song?id=${urlidValue}`,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return dataList;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("数据处理出错" + error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 网易云音乐排行榜
|
||||||
|
neteaseMusicRouter.get("/netease_music_toplist", async (ctx) => {
|
||||||
|
console.log("获取网易云音乐排行榜");
|
||||||
|
try {
|
||||||
|
// 获取参数
|
||||||
|
const { type } = ctx.query;
|
||||||
|
const typeNum = Number(type);
|
||||||
|
if (!typeNum || typeNum > 4 || typeNum < 1) {
|
||||||
|
ctx.body = { code: 400, ...routerInfo, message: "参数不完整或不正确" };
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 更改名称
|
||||||
|
routerInfo.subtitle = listType[typeNum].name;
|
||||||
|
// 从缓存中获取数据
|
||||||
|
let data = await get(cacheKey + listType[typeNum].id);
|
||||||
|
const from = data ? "cache" : "server";
|
||||||
|
if (!data) {
|
||||||
|
// 如果缓存中不存在数据
|
||||||
|
console.log("从服务端重新获取网易云音乐排行榜");
|
||||||
|
// 从服务器拉取数据
|
||||||
|
const response = await axios.get(url + listType[typeNum].id, { headers });
|
||||||
|
// console.log(response.data);
|
||||||
|
data = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
if (!data) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 将数据写入缓存
|
||||||
|
await set(cacheKey + listType[typeNum].id, data);
|
||||||
|
}
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
from,
|
||||||
|
total: data.length,
|
||||||
|
updateTime,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 网易云音乐排行榜 - 获取最新数据
|
||||||
|
neteaseMusicRouter.get("/netease_music_toplist/new", async (ctx) => {
|
||||||
|
console.log("获取网易云音乐排行榜 - 最新数据");
|
||||||
|
try {
|
||||||
|
// 获取参数
|
||||||
|
const { type } = ctx.query;
|
||||||
|
const typeNum = Number(type);
|
||||||
|
if (!typeNum || typeNum > 4 || typeNum < 1) {
|
||||||
|
ctx.body = { code: 400, ...routerInfo, message: "参数不完整或不正确" };
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 更改名称
|
||||||
|
routerInfo.subtitle = listType[typeNum].name;
|
||||||
|
// 从服务器拉取最新数据
|
||||||
|
const response = await axios.get(url + listType[typeNum].id, { headers });
|
||||||
|
const newData = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
console.log("从服务端重新获取网易云音乐排行榜");
|
||||||
|
|
||||||
|
// 返回最新数据
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
updateTime,
|
||||||
|
total: newData.length,
|
||||||
|
data: newData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除旧数据
|
||||||
|
await del(cacheKey + listType[typeNum].id);
|
||||||
|
// 将最新数据写入缓存
|
||||||
|
await set(cacheKey + listType[typeNum].id, newData);
|
||||||
|
} catch (error) {
|
||||||
|
// 如果拉取最新数据失败,尝试从缓存中获取数据
|
||||||
|
console.error(error);
|
||||||
|
const cachedData = await get(cacheKey);
|
||||||
|
if (cachedData) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: cachedData.length,
|
||||||
|
updateTime,
|
||||||
|
data: cachedData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 如果缓存中也没有数据,则返回错误信息
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
neteaseMusicRouter.info = routerInfo;
|
||||||
|
module.exports = neteaseMusicRouter;
|
||||||
@@ -5,6 +5,7 @@ const { get, set, del } = require("../utils/cacheData");
|
|||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
|
name: "newsqq",
|
||||||
title: "腾讯新闻",
|
title: "腾讯新闻",
|
||||||
subtitle: "热点榜",
|
subtitle: "热点榜",
|
||||||
};
|
};
|
||||||
|
|||||||
155
routes/ngabbs.js
Normal file
155
routes/ngabbs.js
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
/**
|
||||||
|
* @author: x-dr
|
||||||
|
* @date: 2023-12-25
|
||||||
|
* @customEditors: imsyy
|
||||||
|
* @lastEditTime: 2024-01-02
|
||||||
|
*/
|
||||||
|
|
||||||
|
const Router = require("koa-router");
|
||||||
|
const ngabbsRouter = new Router();
|
||||||
|
const axios = require("axios");
|
||||||
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
|
// 接口信息
|
||||||
|
const routerInfo = { name: "ngabbs", title: "NGA", subtitle: "论坛热帖" };
|
||||||
|
|
||||||
|
// 缓存键名
|
||||||
|
const cacheKey = "ngabbsData";
|
||||||
|
|
||||||
|
// 调用时间
|
||||||
|
let updateTime = new Date().toISOString();
|
||||||
|
|
||||||
|
const url =
|
||||||
|
"https://ngabbs.com/nuke.php?__lib=load_topic&__act=load_topic_reply_ladder2&opt=1&all=1";
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
Host: "ngabbs.com",
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
Accept: "*/*",
|
||||||
|
"Accept-Encoding": "gzip, deflate, br",
|
||||||
|
Connection: "keep-alive",
|
||||||
|
"Content-Length": "11",
|
||||||
|
"User-Agent": "NGA/7.3.1 (iPhone; iOS 17.2.1; Scale/3.00)",
|
||||||
|
"Accept-Language": "zh-Hans-CN;q=1",
|
||||||
|
Referer: "https://ngabbs.com/",
|
||||||
|
"X-User-Agent": "NGA_skull/7.3.1(iPhone13,2;iOS 17.2.1)",
|
||||||
|
};
|
||||||
|
const postData = { __output: "14" };
|
||||||
|
|
||||||
|
// 数据处理
|
||||||
|
const getData = (data) => {
|
||||||
|
if (!data) return [];
|
||||||
|
const dataList = [];
|
||||||
|
try {
|
||||||
|
const result = data.result[0];
|
||||||
|
result.forEach((result) => {
|
||||||
|
dataList.push({
|
||||||
|
author: result.author,
|
||||||
|
desc: result.subject,
|
||||||
|
parent: result.parent["2"],
|
||||||
|
tid: result.tid,
|
||||||
|
comments: Number(result.replies),
|
||||||
|
url: `https://bbs.nga.cn/read.php?tid=${result.tid}`,
|
||||||
|
mobileUrl: `https://bbs.nga.cn/read.php?tid=${result.tid}`,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return dataList;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("数据处理出错" + error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// NGA论坛热帖
|
||||||
|
ngabbsRouter.get("/ngabbs", async (ctx) => {
|
||||||
|
console.log("获取NGA论坛热帖");
|
||||||
|
try {
|
||||||
|
// 从缓存中获取数据
|
||||||
|
let data = await get(cacheKey);
|
||||||
|
const from = data ? "cache" : "server";
|
||||||
|
if (!data) {
|
||||||
|
// 如果缓存中不存在数据
|
||||||
|
console.log("从服务端重新获取NGA论坛热帖");
|
||||||
|
// 从服务器拉取数据
|
||||||
|
const response = await axios.post(url, postData, { headers });
|
||||||
|
data = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
if (!data) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 将数据写入缓存
|
||||||
|
await set(cacheKey, data);
|
||||||
|
}
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
from,
|
||||||
|
total: data.length,
|
||||||
|
updateTime,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// NGA论坛热帖 - 获取最新数据
|
||||||
|
ngabbsRouter.get("/ngabbs/new", async (ctx) => {
|
||||||
|
console.log("获取NGA论坛热帖 - 最新数据");
|
||||||
|
try {
|
||||||
|
// 从服务器拉取最新数据
|
||||||
|
const response = await axios.post(url, postData, { headers });
|
||||||
|
const newData = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
console.log("从服务端重新获取NGA论坛热帖");
|
||||||
|
|
||||||
|
// 返回最新数据
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: newData.length,
|
||||||
|
updateTime,
|
||||||
|
data: newData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除旧数据
|
||||||
|
await del(cacheKey);
|
||||||
|
// 将最新数据写入缓存
|
||||||
|
await set(cacheKey, newData);
|
||||||
|
} catch (error) {
|
||||||
|
// 如果拉取最新数据失败,尝试从缓存中获取数据
|
||||||
|
console.error(error);
|
||||||
|
const cachedData = await get(cacheKey);
|
||||||
|
if (cachedData) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: cachedData.length,
|
||||||
|
updateTime,
|
||||||
|
data: cachedData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 如果缓存中也没有数据,则返回错误信息
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ngabbsRouter.info = routerInfo;
|
||||||
|
module.exports = ngabbsRouter;
|
||||||
211
routes/qq_music_toplist.js
Normal file
211
routes/qq_music_toplist.js
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
/**
|
||||||
|
* @author: x-dr
|
||||||
|
* @date: 2023-12-27
|
||||||
|
* @customEditors: imsyy
|
||||||
|
* @lastEditTime: 2024-01-02
|
||||||
|
*/
|
||||||
|
|
||||||
|
// const fs = require("fs");
|
||||||
|
const Router = require("koa-router");
|
||||||
|
const qqMusicRouter = new Router();
|
||||||
|
const axios = require("axios");
|
||||||
|
const cheerio = require("cheerio");
|
||||||
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
|
// 接口信息
|
||||||
|
const routerInfo = {
|
||||||
|
name: "qq_music_toplist",
|
||||||
|
title: "QQ音乐",
|
||||||
|
subtitle: "排行榜",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 缓存键名
|
||||||
|
const cacheKey = "qqmusicData";
|
||||||
|
|
||||||
|
// 调用时间
|
||||||
|
let updateTime = new Date().toISOString();
|
||||||
|
|
||||||
|
const url = "https://y.qq.com/n/ryqq/toplist/";
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
authority: "y.qq.com",
|
||||||
|
referer: "https://www.google.com/",
|
||||||
|
"user-agent":
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 榜单类别
|
||||||
|
const listType = {
|
||||||
|
1: {
|
||||||
|
id: 62,
|
||||||
|
name: "飙升榜",
|
||||||
|
},
|
||||||
|
2: {
|
||||||
|
id: 26,
|
||||||
|
name: "热歌榜",
|
||||||
|
},
|
||||||
|
3: {
|
||||||
|
id: 27,
|
||||||
|
name: "新歌榜",
|
||||||
|
},
|
||||||
|
4: {
|
||||||
|
id: 4,
|
||||||
|
name: "流行指数榜",
|
||||||
|
},
|
||||||
|
5: {
|
||||||
|
id: 52,
|
||||||
|
name: "腾讯音乐人原创榜",
|
||||||
|
},
|
||||||
|
6: {
|
||||||
|
id: 67,
|
||||||
|
name: "听歌识曲榜",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// 数据处理
|
||||||
|
const getData = (data) => {
|
||||||
|
if (!data) return false;
|
||||||
|
const dataList = [];
|
||||||
|
const $ = cheerio.load(data);
|
||||||
|
// fs.writeFileSync('qq.html', $.html());
|
||||||
|
try {
|
||||||
|
$(".songlist__item").each((i, e) => {
|
||||||
|
const item = cheerio.load($(e).html());
|
||||||
|
const title = item('a[class="songlist__cover"]').attr("title");
|
||||||
|
const urlPath = item('a[class="songlist__cover"]').attr("href");
|
||||||
|
const author = item('div[class="songlist__artist"]')
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
const songtime = item('div[class="songlist__time"]')
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
// const title = item('div[class="f-thide sgtl"]').text().replace(/(^\s*)|(\s*$)/g, "")
|
||||||
|
dataList.push({
|
||||||
|
title: title,
|
||||||
|
desc: author,
|
||||||
|
songtime: songtime,
|
||||||
|
url: `https://y.qq.com${urlPath}`,
|
||||||
|
mobileUrl: `https://y.qq.com${urlPath}`,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return dataList;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("数据处理出错" + error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取QQ音乐排行榜
|
||||||
|
qqMusicRouter.get("/qq_music_toplist", async (ctx) => {
|
||||||
|
console.log("获取QQ音乐排行榜");
|
||||||
|
try {
|
||||||
|
// 获取参数
|
||||||
|
const { type } = ctx.query;
|
||||||
|
const typeNum = Number(type);
|
||||||
|
if (!typeNum || typeNum > 6 || typeNum < 1) {
|
||||||
|
ctx.body = { code: 400, ...routerInfo, message: "参数不完整或不正确" };
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 更改名称
|
||||||
|
routerInfo.subtitle = listType[typeNum].name;
|
||||||
|
// 从缓存中获取数据
|
||||||
|
let data = await get(cacheKey + listType[typeNum].id);
|
||||||
|
const from = data ? "cache" : "server";
|
||||||
|
if (!data) {
|
||||||
|
// 如果缓存中不存在数据
|
||||||
|
console.log("从服务端重新QQ音乐排行榜");
|
||||||
|
// 从服务器拉取数据
|
||||||
|
const response = await axios.get(url + listType[typeNum].id, { headers });
|
||||||
|
// console.log(response.data);
|
||||||
|
data = getData(response.data);
|
||||||
|
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
if (!data) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 将数据写入缓存
|
||||||
|
await set(cacheKey + listType[typeNum].id, data);
|
||||||
|
}
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
from,
|
||||||
|
total: data.length,
|
||||||
|
updateTime,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取QQ音乐排行榜 - 获取最新数据
|
||||||
|
qqMusicRouter.get("/qq_music_toplist/new", async (ctx) => {
|
||||||
|
console.log("获取QQ音乐排行榜 - 最新数据");
|
||||||
|
try {
|
||||||
|
// 获取参数
|
||||||
|
const { type } = ctx.query;
|
||||||
|
const typeNum = Number(type);
|
||||||
|
if (!typeNum || typeNum > 4 || typeNum < 1) {
|
||||||
|
ctx.body = { code: 400, ...routerInfo, message: "参数不完整或不正确" };
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 更改名称
|
||||||
|
routerInfo.subtitle = listType[typeNum].name;
|
||||||
|
// 从服务器拉取最新数据
|
||||||
|
const response = await axios.get(url + listType[typeNum].id, { headers });
|
||||||
|
const newData = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
console.log("从服务端重新QQ音乐排行榜");
|
||||||
|
|
||||||
|
// 返回最新数据
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
updateTime,
|
||||||
|
total: newData.length,
|
||||||
|
data: newData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除旧数据
|
||||||
|
await del(cacheKey + listType[typeNum].id);
|
||||||
|
// 将最新数据写入缓存
|
||||||
|
await set(cacheKey + listType[typeNum].id, newData);
|
||||||
|
} catch (error) {
|
||||||
|
// 如果拉取最新数据失败,尝试从缓存中获取数据
|
||||||
|
console.error(error);
|
||||||
|
const cachedData = await get(cacheKey);
|
||||||
|
if (cachedData) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: cachedData.length,
|
||||||
|
updateTime,
|
||||||
|
data: cachedData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 如果缓存中也没有数据,则返回错误信息
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
qqMusicRouter.info = routerInfo;
|
||||||
|
module.exports = qqMusicRouter;
|
||||||
@@ -5,6 +5,7 @@ const { get, set, del } = require("../utils/cacheData");
|
|||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
|
name: "sspai",
|
||||||
title: "少数派",
|
title: "少数派",
|
||||||
subtitle: "热榜",
|
subtitle: "热榜",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const { get, set, del } = require("../utils/cacheData");
|
|||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
|
name: "thepaper",
|
||||||
title: "澎湃新闻",
|
title: "澎湃新闻",
|
||||||
subtitle: "热榜",
|
subtitle: "热榜",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const { get, set, del } = require("../utils/cacheData");
|
|||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
|
name: "tieba",
|
||||||
title: "百度贴吧",
|
title: "百度贴吧",
|
||||||
subtitle: "热议榜",
|
subtitle: "热议榜",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const { get, set, del } = require("../utils/cacheData");
|
|||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
|
name: "toutiao",
|
||||||
title: "今日头条",
|
title: "今日头条",
|
||||||
subtitle: "热榜",
|
subtitle: "热榜",
|
||||||
};
|
};
|
||||||
|
|||||||
175
routes/v2ex.js
Normal file
175
routes/v2ex.js
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
/**
|
||||||
|
* @author: x-dr
|
||||||
|
* @date: 2023-12-25
|
||||||
|
* @customEditors: imsyy
|
||||||
|
* @lastEditTime: 2024-01-02
|
||||||
|
*/
|
||||||
|
|
||||||
|
const Router = require("koa-router");
|
||||||
|
const v2exRouter = new Router();
|
||||||
|
const axios = require("axios");
|
||||||
|
const cheerio = require("cheerio");
|
||||||
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
|
// 接口信息
|
||||||
|
const routerInfo = {
|
||||||
|
name: "v2ex",
|
||||||
|
title: "V2EX",
|
||||||
|
subtitle: "hot",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 缓存键名
|
||||||
|
const cacheKey = "v2exData";
|
||||||
|
|
||||||
|
// 调用时间
|
||||||
|
let updateTime = new Date().toISOString();
|
||||||
|
|
||||||
|
const url = "https://www.v2ex.com/?tab=hot";
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"User-Agent":
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
|
||||||
|
authority: "www.v2ex.com",
|
||||||
|
referer: "https://www.v2ex.com/",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 数据处理
|
||||||
|
const getData = (data) => {
|
||||||
|
if (!data) return false;
|
||||||
|
const dataList = [];
|
||||||
|
const $ = cheerio.load(data);
|
||||||
|
try {
|
||||||
|
$(`div[class="cell item"]`).each((i, e) => {
|
||||||
|
const item = cheerio.load($(e).html());
|
||||||
|
const title = item('span[class="item_title"]')
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
const href = item(".item_title a").attr("href");
|
||||||
|
const url = `https://www.v2ex.com${href}`;
|
||||||
|
const comments = item(".count_livid")
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
const member = item(".topic_info strong a:first")
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
const node = item(".topic_info .node")
|
||||||
|
.text()
|
||||||
|
.replace(/(^\s*)|(\s*$)/g, "");
|
||||||
|
const avatar_img = item(".avatar").attr("src");
|
||||||
|
// console.log( url);
|
||||||
|
|
||||||
|
dataList.push({
|
||||||
|
title: title,
|
||||||
|
url: url,
|
||||||
|
mobileUrl: url,
|
||||||
|
comments: comments,
|
||||||
|
member: member,
|
||||||
|
node: node,
|
||||||
|
avatar: avatar_img,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return dataList;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("数据处理出错" + error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// v2ex
|
||||||
|
v2exRouter.get("/v2ex", async (ctx) => {
|
||||||
|
console.log("获取v2ex");
|
||||||
|
try {
|
||||||
|
// 从缓存中获取数据
|
||||||
|
let data = await get(cacheKey);
|
||||||
|
const from = data ? "cache" : "server";
|
||||||
|
if (!data) {
|
||||||
|
// 如果缓存中不存在数据
|
||||||
|
console.log("从服务端重新获取v2ex");
|
||||||
|
// 从服务器拉取数据
|
||||||
|
const response = await axios.get(url, { headers });
|
||||||
|
// console.log(response.data);
|
||||||
|
data = getData(response.data);
|
||||||
|
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
if (!data) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 将数据写入缓存
|
||||||
|
await set(cacheKey, data);
|
||||||
|
}
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
from,
|
||||||
|
total: data.length,
|
||||||
|
updateTime,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// v2ex - 获取最新数据
|
||||||
|
v2exRouter.get("/v2ex/new", async (ctx) => {
|
||||||
|
console.log("获取v2ex - 最新数据");
|
||||||
|
try {
|
||||||
|
// 从服务器拉取最新数据
|
||||||
|
const response = await axios.get(url, { headers });
|
||||||
|
const newData = getData(response.data);
|
||||||
|
updateTime = new Date().toISOString();
|
||||||
|
console.log("从服务端重新获取v2ex");
|
||||||
|
|
||||||
|
// 返回最新数据
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
updateTime,
|
||||||
|
total: newData.length,
|
||||||
|
data: newData,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除旧数据
|
||||||
|
await del(cacheKey);
|
||||||
|
// 将最新数据写入缓存
|
||||||
|
await set(cacheKey, newData);
|
||||||
|
} catch (error) {
|
||||||
|
// 如果拉取最新数据失败,尝试从缓存中获取数据
|
||||||
|
console.error(error);
|
||||||
|
const cachedData = await get(cacheKey);
|
||||||
|
if (cachedData) {
|
||||||
|
ctx.body = {
|
||||||
|
code: 200,
|
||||||
|
message: "获取成功",
|
||||||
|
...routerInfo,
|
||||||
|
total: cachedData.length,
|
||||||
|
updateTime,
|
||||||
|
data: cachedData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// 如果缓存中也没有数据,则返回错误信息
|
||||||
|
ctx.body = {
|
||||||
|
code: 500,
|
||||||
|
...routerInfo,
|
||||||
|
message: "获取失败",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
v2exRouter.info = routerInfo;
|
||||||
|
module.exports = v2exRouter;
|
||||||
@@ -6,6 +6,7 @@ const { get, set, del } = require("../utils/cacheData");
|
|||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
|
name: "weibo",
|
||||||
title: "微博",
|
title: "微博",
|
||||||
subtitle: "热搜榜",
|
subtitle: "热搜榜",
|
||||||
};
|
};
|
||||||
@@ -29,11 +30,9 @@ const getData = (data) => {
|
|||||||
title: v.word,
|
title: v.word,
|
||||||
desc: key,
|
desc: key,
|
||||||
hot: v.raw_hot,
|
hot: v.raw_hot,
|
||||||
url: `https://s.weibo.com/weibo?q=${encodeURIComponent(
|
url: `https://s.weibo.com/weibo?q=${encodeURIComponent(key)}&t=31&band_rank=1&Refer=top`,
|
||||||
key
|
|
||||||
)}&t=31&band_rank=1&Refer=top`,
|
|
||||||
mobileUrl: `https://s.weibo.com/weibo?q=${encodeURIComponent(
|
mobileUrl: `https://s.weibo.com/weibo?q=${encodeURIComponent(
|
||||||
key
|
key,
|
||||||
)}&t=31&band_rank=1&Refer=top`,
|
)}&t=31&band_rank=1&Refer=top`,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
const Router = require("koa-router");
|
const Router = require("koa-router");
|
||||||
const wereadRouter = new Router();
|
const wereadRouter = new Router();
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
|
const getWereadID = require("../utils/getWereadID");
|
||||||
const { get, set, del } = require("../utils/cacheData");
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
|
name: "weread",
|
||||||
title: "微信读书",
|
title: "微信读书",
|
||||||
subtitle: "飙升榜",
|
subtitle: "飙升榜",
|
||||||
};
|
};
|
||||||
@@ -23,7 +25,6 @@ const getData = (data) => {
|
|||||||
if (!data) return [];
|
if (!data) return [];
|
||||||
return data.map((v) => {
|
return data.map((v) => {
|
||||||
const book = v.bookInfo;
|
const book = v.bookInfo;
|
||||||
console.log(book);
|
|
||||||
return {
|
return {
|
||||||
id: book.bookId,
|
id: book.bookId,
|
||||||
title: book.title,
|
title: book.title,
|
||||||
@@ -31,8 +32,8 @@ const getData = (data) => {
|
|||||||
pic: book.cover.replace("s_", "t9_"),
|
pic: book.cover.replace("s_", "t9_"),
|
||||||
hot: v.readingCount,
|
hot: v.readingCount,
|
||||||
author: book.author,
|
author: book.author,
|
||||||
url: "https://weread.qq.com/web/category/rising",
|
url: `https://weread.qq.com/web/bookDetail/${getWereadID(book.bookId)}`,
|
||||||
mobileUrl: "https://weread.qq.com/web/category/rising",
|
mobileUrl: `https://weread.qq.com/web/bookDetail/${getWereadID(book.bookId)}`,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const Router = require("koa-router");
|
|||||||
const zhihuRouter = new Router();
|
const zhihuRouter = new Router();
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const { get, set, del } = require("../utils/cacheData");
|
const { get, set, del } = require("../utils/cacheData");
|
||||||
const router = require(".");
|
|
||||||
|
|
||||||
// 接口信息
|
// 接口信息
|
||||||
const routerInfo = {
|
const routerInfo = {
|
||||||
@@ -28,8 +27,7 @@ const getData = (data) => {
|
|||||||
if (!data) return [];
|
if (!data) return [];
|
||||||
const dataList = [];
|
const dataList = [];
|
||||||
try {
|
try {
|
||||||
const pattern =
|
const pattern = /<script id="js-initialData" type="text\/json">(.*?)<\/script>/;
|
||||||
/<script id="js-initialData" type="text\/json">(.*?)<\/script>/;
|
|
||||||
const matchResult = data.match(pattern);
|
const matchResult = data.match(pattern);
|
||||||
const jsonObject = JSON.parse(matchResult[1]).initialState.topstory.hotList;
|
const jsonObject = JSON.parse(matchResult[1]).initialState.topstory.hotList;
|
||||||
jsonObject.forEach((v) => {
|
jsonObject.forEach((v) => {
|
||||||
|
|||||||
81
utils/getWereadID.js
Normal file
81
utils/getWereadID.js
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
const crypto = require("crypto");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取微信读书的书籍 ID
|
||||||
|
* 感谢 @MCBBC 及 ChatGPT
|
||||||
|
* @param {string} bookId - 书籍 ID
|
||||||
|
* @returns {string} - 唯一的书籍 ID
|
||||||
|
*/
|
||||||
|
const getWereadID = (bookId) => {
|
||||||
|
try {
|
||||||
|
// 使用 MD5 哈希算法创建哈希对象
|
||||||
|
const hash = crypto.createHash("md5");
|
||||||
|
hash.update(bookId);
|
||||||
|
const str = hash.digest("hex");
|
||||||
|
|
||||||
|
// 取哈希结果的前三个字符作为初始值
|
||||||
|
let strSub = str.substring(0, 3);
|
||||||
|
|
||||||
|
// 判断书籍 ID 的类型并进行转换
|
||||||
|
let fa;
|
||||||
|
if (/^\d*$/.test(bookId)) {
|
||||||
|
// 如果书籍 ID 只包含数字,则将其拆分成长度为 9 的子字符串,并转换为十六进制表示
|
||||||
|
const chunks = [];
|
||||||
|
for (let i = 0; i < bookId.length; i += 9) {
|
||||||
|
const chunk = bookId.substring(i, i + 9);
|
||||||
|
chunks.push(parseInt(chunk).toString(16));
|
||||||
|
}
|
||||||
|
fa = ["3", chunks];
|
||||||
|
} else {
|
||||||
|
// 如果书籍 ID 包含其他字符,则将每个字符的 Unicode 编码转换为十六进制表示
|
||||||
|
let hexStr = "";
|
||||||
|
for (let i = 0; i < bookId.length; i++) {
|
||||||
|
hexStr += bookId.charCodeAt(i).toString(16);
|
||||||
|
}
|
||||||
|
fa = ["4", [hexStr]];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将类型添加到初始值中
|
||||||
|
strSub += fa[0];
|
||||||
|
|
||||||
|
// 将数字2和哈希结果的后两个字符添加到初始值中
|
||||||
|
strSub += "2" + str.substring(str.length - 2);
|
||||||
|
|
||||||
|
// 处理转换后的子字符串数组
|
||||||
|
for (let i = 0; i < fa[1].length; i++) {
|
||||||
|
const sub = fa[1][i];
|
||||||
|
const subLength = sub.length.toString(16);
|
||||||
|
|
||||||
|
// 如果长度只有一位数,则在前面添加0
|
||||||
|
const subLengthPadded = subLength.length === 1 ? "0" + subLength : subLength;
|
||||||
|
|
||||||
|
// 将长度和子字符串添加到初始值中
|
||||||
|
strSub += subLengthPadded + sub;
|
||||||
|
|
||||||
|
// 如果不是最后一个子字符串,则添加分隔符 'g'
|
||||||
|
if (i < fa[1].length - 1) {
|
||||||
|
strSub += "g";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果初始值长度不足 20,从哈希结果中取足够的字符补齐
|
||||||
|
if (strSub.length < 20) {
|
||||||
|
strSub += str.substring(0, 20 - strSub.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用 MD5 哈希算法创建新的哈希对象
|
||||||
|
const finalHash = crypto.createHash("md5");
|
||||||
|
finalHash.update(strSub);
|
||||||
|
const finalStr = finalHash.digest("hex");
|
||||||
|
|
||||||
|
// 取最终哈希结果的前三个字符并添加到初始值的末尾
|
||||||
|
strSub += finalStr.substring(0, 3);
|
||||||
|
|
||||||
|
return strSub;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("处理微信读书 ID 时出现错误:" + error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = getWereadID;
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
{
|
|
||||||
"opts": {},
|
|
||||||
"methods": ["HEAD", "OPTIONS", "GET", "PUT", "PATCH", "POST", "DELETE"],
|
|
||||||
"exclusive": false,
|
|
||||||
"params": {},
|
|
||||||
"stack": [
|
|
||||||
{
|
|
||||||
"opts": {
|
|
||||||
"end": true,
|
|
||||||
"name": null,
|
|
||||||
"sensitive": false,
|
|
||||||
"strict": false,
|
|
||||||
"prefix": ""
|
|
||||||
},
|
|
||||||
"name": null,
|
|
||||||
"methods": ["HEAD", "GET"],
|
|
||||||
"paramNames": [],
|
|
||||||
"stack": [null],
|
|
||||||
"path": "/zhihu",
|
|
||||||
"regexp": {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"opts": {
|
|
||||||
"end": true,
|
|
||||||
"name": null,
|
|
||||||
"sensitive": false,
|
|
||||||
"strict": false,
|
|
||||||
"prefix": ""
|
|
||||||
},
|
|
||||||
"name": null,
|
|
||||||
"methods": ["HEAD", "GET"],
|
|
||||||
"paramNames": [],
|
|
||||||
"stack": [null],
|
|
||||||
"path": "/zhihu/new",
|
|
||||||
"regexp": {}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"info": { "title": "知乎", "subtitle": "热榜" }
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user