mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 13:14:55 +08:00
🦄 refactor: 调整接口结构
This commit is contained in:
19
.env.example
19
.env.example
@@ -1,24 +1,27 @@
|
||||
# 服务端口
|
||||
PORT = 6688
|
||||
PORT=6688
|
||||
|
||||
# 允许的域名
|
||||
ALLOWED_DOMAIN = "*"
|
||||
ALLOWED_DOMAIN="*"
|
||||
|
||||
# 允许的主域名,填写格式为 imsyy.top
|
||||
## 若填写该项,将忽略 ALLOWED_DOMAIN
|
||||
ALLOWED_HOST = ""
|
||||
ALLOWED_HOST=""
|
||||
|
||||
# ROBOT
|
||||
DISALLOW_ROBOT = true
|
||||
DISALLOW_ROBOT=true
|
||||
|
||||
# 缓存时长( 秒 )
|
||||
CACHE_TTL = 3600
|
||||
CACHE_TTL=3600
|
||||
|
||||
# 请求超时( 毫秒 )
|
||||
REQUEST_TIMEOUT = 6000
|
||||
REQUEST_TIMEOUT=6000
|
||||
|
||||
# 是否输出日志
|
||||
USE_LOG_FILE = true
|
||||
USE_LOG_FILE=true
|
||||
|
||||
# RSS Mode
|
||||
RSS_MODE = false
|
||||
RSS_MODE=false
|
||||
|
||||
# Puppeteer
|
||||
USE_PUPPETEER=false
|
||||
17
.github/workflows/docker.yml
vendored
17
.github/workflows/docker.yml
vendored
@@ -43,7 +43,7 @@ jobs:
|
||||
imsyy/dailyhot-api
|
||||
ghcr.io/${{ github.repository }}
|
||||
|
||||
- name: Build and push
|
||||
- name: Build and push regular image (no Puppeteer)
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
@@ -54,3 +54,18 @@ jobs:
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
- name: Build and push Puppeteer image (with Puppeteer)
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: |
|
||||
linux/amd64
|
||||
linux/arm64
|
||||
push: true
|
||||
tags: imsyy/dailyhot-api:web-latest
|
||||
build-args: |
|
||||
USE_PUPPETEER=true
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
|
||||
28
Dockerfile
28
Dockerfile
@@ -3,13 +3,27 @@ FROM node:20-alpine AS base
|
||||
ENV NODE_ENV=docker
|
||||
|
||||
# 安装 Puppeteer 所需的依赖库
|
||||
RUN apk add libc6-compat
|
||||
# RUN apk add chromium nss freetype harfbuzz ca-certificates
|
||||
RUN apk add --no-cache \
|
||||
libc6-compat \
|
||||
nss \
|
||||
freetype \
|
||||
harfbuzz \
|
||||
ca-certificates
|
||||
|
||||
# 判断是否需要安装 Chromium
|
||||
ARG USE_PUPPETEER=false
|
||||
RUN if [ "$USE_PUPPETEER" = "true" ]; then \
|
||||
apk add --no-cache chromium; \
|
||||
fi
|
||||
|
||||
# 配置 Chromium
|
||||
# ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
|
||||
# ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
|
||||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
|
||||
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
|
||||
|
||||
# 清理缓存
|
||||
RUN rm -rf /var/cache/apk/*
|
||||
|
||||
# 构建阶段
|
||||
FROM base AS builder
|
||||
|
||||
RUN npm install -g pnpm
|
||||
@@ -21,13 +35,16 @@ COPY public ./public
|
||||
|
||||
# add .env.example to .env
|
||||
RUN [ ! -e ".env" ] && cp .env.example .env || true
|
||||
RUN if [ "$USE_PUPPETEER" = "true" ]; then \
|
||||
sed -i 's/^USE_PUPPETEER=false/USE_PUPPETEER=true/' .env; \
|
||||
fi
|
||||
|
||||
RUN pnpm install
|
||||
RUN pnpm build
|
||||
RUN pnpm prune --production
|
||||
|
||||
# 运行阶段
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
# 创建用户和组
|
||||
RUN addgroup --system --gid 114514 nodejs
|
||||
@@ -35,6 +52,7 @@ RUN adduser --system --uid 114514 hono
|
||||
|
||||
# 创建日志目录
|
||||
RUN mkdir -p /app/logs && chown -R hono:nodejs /app/logs
|
||||
RUN ln -s /app/logs /logs
|
||||
|
||||
# 复制文件
|
||||
COPY --from=builder --chown=hono:nodejs /app/node_modules /app/node_modules
|
||||
|
||||
22
README.md
22
README.md
@@ -66,6 +66,7 @@
|
||||
| 虎扑 | 步行街热帖 | hupu |  |
|
||||
| 爱范儿 | 快讯 | ifanr |  |
|
||||
| 英雄联盟 | 更新公告 | lol |  |
|
||||
| 米游社 | 最新消息 | miyoushe |  |
|
||||
| 原神 | 最新消息 | genshin |  |
|
||||
| 崩坏3 | 最新动态 | honkai |  |
|
||||
| 崩坏:星穹铁道 | 最新动态 | starrail |  |
|
||||
@@ -83,6 +84,8 @@
|
||||
|
||||
本项目支持 `Node.js` 调用,可在安装完成后调用 `serveHotApi` 来开启服务器
|
||||
|
||||
> 该方式无法使用部分需要 Puppeteer 环境的接口
|
||||
|
||||
```bash
|
||||
pnpm add dailyhot-api
|
||||
```
|
||||
@@ -100,6 +103,8 @@ serveHotApi(3000);
|
||||
|
||||
## ⚙️ 部署
|
||||
|
||||
由于部分接口无法通过接口调用等方式获取数据,故采用 `Puppeteer` 来实现,但由于使用后会造成 **内存占用过大或镜像过大**,可选择性开启,详情请参考下方说明。
|
||||
|
||||
具体使用说明可参考 [我的博客](https://blog.imsyy.top/posts/2024/0408),下方仅讲解基础操作:
|
||||
|
||||
### Docker 部署
|
||||
@@ -111,8 +116,11 @@ serveHotApi(3000);
|
||||
```bash
|
||||
# 构建
|
||||
docker build -t dailyhot-api .
|
||||
# 构建 Puppeteer 版
|
||||
docker build --build-arg USE_PUPPETEER=true -t dailyhot-api .
|
||||
|
||||
# 运行
|
||||
docker run -p 6688:6688 -d dailyhot-api
|
||||
docker run --restart always -p 6688:6688 -d dailyhot-api
|
||||
# 或使用 Docker Compose
|
||||
docker-compose up -d
|
||||
```
|
||||
@@ -122,8 +130,11 @@ docker-compose up -d
|
||||
```bash
|
||||
# 拉取
|
||||
docker pull imsyy/dailyhot-api:latest
|
||||
# 拉取 Puppeteer 版
|
||||
docker pull imsyy/dailyhot-api:web-latest
|
||||
|
||||
# 运行
|
||||
docker run -p 6688:6688 -d imsyy/dailyhot-api:latest
|
||||
docker run --restart always -p 6688:6688 -d imsyy/dailyhot-api:latest
|
||||
```
|
||||
|
||||
### 手动部署
|
||||
@@ -148,7 +159,10 @@ npm install
|
||||
#### 开发
|
||||
|
||||
```bash
|
||||
# 标准运行
|
||||
npm run dev
|
||||
# 采用 Puppeteer 运行
|
||||
npm run dev:web
|
||||
```
|
||||
|
||||
成功启动后程序会在控制台输出可访问的地址
|
||||
@@ -157,7 +171,11 @@ npm run dev
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
|
||||
# 标准运行
|
||||
npm run start
|
||||
# 采用 Puppeteer 运行
|
||||
npm run start:web
|
||||
```
|
||||
|
||||
成功启动后程序会在控制台输出可访问的地址
|
||||
|
||||
@@ -30,9 +30,11 @@
|
||||
"format": "prettier --write .",
|
||||
"lint": "eslint .",
|
||||
"dev": "cross-env NODE_ENV=development tsx watch --no-cache src/index.ts",
|
||||
"dev:web": "cross-env NODE_ENV=development USE_PUPPETEER=true tsx watch --no-cache src/index.ts",
|
||||
"dev:cache": "cross-env NODE_ENV=development tsx watch src/index.ts",
|
||||
"build": "tsc --project tsconfig.json",
|
||||
"start": "cross-env NODE_ENV=development tsx dist/src/index.js"
|
||||
"start": "cross-env NODE_ENV=development tsx dist/index.js",
|
||||
"start:web": "cross-env NODE_ENV=development USE_PUPPETEER=true tsx dist/index.js"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
@@ -46,6 +48,7 @@
|
||||
"hono": "^4.6.12",
|
||||
"md5": "^2.3.0",
|
||||
"node-cache": "^5.1.2",
|
||||
"puppeteer": "^23.10.0",
|
||||
"puppeteer-cluster": "^0.24.0",
|
||||
"rss-parser": "^3.13.0",
|
||||
"winston": "^3.17.0",
|
||||
|
||||
33
pnpm-lock.yaml
generated
33
pnpm-lock.yaml
generated
@@ -38,9 +38,12 @@ importers:
|
||||
node-cache:
|
||||
specifier: ^5.1.2
|
||||
version: 5.1.2
|
||||
puppeteer:
|
||||
specifier: ^23.10.0
|
||||
version: 23.10.0(typescript@5.7.2)
|
||||
puppeteer-cluster:
|
||||
specifier: ^0.24.0
|
||||
version: 0.24.0(puppeteer@23.9.0(typescript@5.7.2))
|
||||
version: 0.24.0(puppeteer@23.10.0(typescript@5.7.2))
|
||||
rss-parser:
|
||||
specifier: ^3.13.0
|
||||
version: 3.13.0
|
||||
@@ -324,8 +327,8 @@ packages:
|
||||
resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==}
|
||||
engines: {node: '>= 8'}
|
||||
|
||||
'@puppeteer/browsers@2.4.1':
|
||||
resolution: {integrity: sha512-0kdAbmic3J09I6dT8e9vE2JOCSt13wHCW5x/ly8TSt2bDtuIWe2TgLZZDHdcziw9AVCzflMAXCrVyRIhIs44Ng==}
|
||||
'@puppeteer/browsers@2.5.0':
|
||||
resolution: {integrity: sha512-6TQAc/5uRILE6deixJ1CR8rXyTbzXIXNgO1D0Woi9Bqicz2FV5iKP3BHYEg6o4UATCMcbQQ0jbmeaOkn/HQk2w==}
|
||||
engines: {node: '>=18'}
|
||||
hasBin: true
|
||||
|
||||
@@ -1117,12 +1120,12 @@ packages:
|
||||
peerDependencies:
|
||||
puppeteer: '>=22.0.0'
|
||||
|
||||
puppeteer-core@23.9.0:
|
||||
resolution: {integrity: sha512-hLVrav2HYMVdK0YILtfJwtnkBAwNOztUdR4aJ5YKDvgsbtagNr6urUJk9HyjRA9e+PaLI3jzJ0wM7A4jSZ7Qxw==}
|
||||
puppeteer-core@23.10.0:
|
||||
resolution: {integrity: sha512-7pv6kFget4Iki0RLBDowi35vaccz73XpC6/FAnfCrYa2IXVUlBHfZw+HGWzlvvTGwM9HHd32rgCrIDzil3kj+w==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
puppeteer@23.9.0:
|
||||
resolution: {integrity: sha512-WfB8jGwFV+qrD9dcJJVvWPFJBU6kxeu2wxJz9WooDGfM3vIiKLgzImEDBxUQnCBK/2cXB3d4dV6gs/LLpgfLDg==}
|
||||
puppeteer@23.10.0:
|
||||
resolution: {integrity: sha512-vLpEvUM8POKBX4j6y/yyD4oGRhS1oBAbMn3lYpz1yeakhRsA8IhF5QmjXwAIQYGdR/INxyFiY6kQDoUtLGDP3g==}
|
||||
engines: {node: '>=18'}
|
||||
hasBin: true
|
||||
|
||||
@@ -1552,7 +1555,7 @@ snapshots:
|
||||
'@nodelib/fs.scandir': 2.1.5
|
||||
fastq: 1.17.1
|
||||
|
||||
'@puppeteer/browsers@2.4.1':
|
||||
'@puppeteer/browsers@2.5.0':
|
||||
dependencies:
|
||||
debug: 4.3.7
|
||||
extract-zip: 2.0.1
|
||||
@@ -2430,16 +2433,16 @@ snapshots:
|
||||
|
||||
punycode@2.3.1: {}
|
||||
|
||||
puppeteer-cluster@0.24.0(puppeteer@23.9.0(typescript@5.7.2)):
|
||||
puppeteer-cluster@0.24.0(puppeteer@23.10.0(typescript@5.7.2)):
|
||||
dependencies:
|
||||
debug: 4.3.7
|
||||
puppeteer: 23.9.0(typescript@5.7.2)
|
||||
puppeteer: 23.10.0(typescript@5.7.2)
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
puppeteer-core@23.9.0:
|
||||
puppeteer-core@23.10.0:
|
||||
dependencies:
|
||||
'@puppeteer/browsers': 2.4.1
|
||||
'@puppeteer/browsers': 2.5.0
|
||||
chromium-bidi: 0.8.0(devtools-protocol@0.0.1367902)
|
||||
debug: 4.3.7
|
||||
devtools-protocol: 0.0.1367902
|
||||
@@ -2450,13 +2453,13 @@ snapshots:
|
||||
- supports-color
|
||||
- utf-8-validate
|
||||
|
||||
puppeteer@23.9.0(typescript@5.7.2):
|
||||
puppeteer@23.10.0(typescript@5.7.2):
|
||||
dependencies:
|
||||
'@puppeteer/browsers': 2.4.1
|
||||
'@puppeteer/browsers': 2.5.0
|
||||
chromium-bidi: 0.8.0(devtools-protocol@0.0.1367902)
|
||||
cosmiconfig: 9.0.0(typescript@5.7.2)
|
||||
devtools-protocol: 0.0.1367902
|
||||
puppeteer-core: 23.9.0
|
||||
puppeteer-core: 23.10.0
|
||||
typed-query-selector: 2.12.0
|
||||
transitivePeerDependencies:
|
||||
- bufferutil
|
||||
|
||||
@@ -12,6 +12,7 @@ export type Config = {
|
||||
ALLOWED_HOST: string;
|
||||
USE_LOG_FILE: boolean;
|
||||
RSS_MODE: boolean;
|
||||
USE_PUPPETEER: boolean;
|
||||
};
|
||||
|
||||
// 验证并提取环境变量
|
||||
@@ -49,4 +50,5 @@ export const config: Config = {
|
||||
ALLOWED_HOST: getEnvVariable("ALLOWED_HOST") || "imsyy.top",
|
||||
USE_LOG_FILE: getBooleanEnvVariable("USE_LOG_FILE", true),
|
||||
RSS_MODE: getBooleanEnvVariable("RSS_MODE", false),
|
||||
USE_PUPPETEER: getBooleanEnvVariable("USE_PUPPETEER", false),
|
||||
};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { serve } from "@hono/node-server";
|
||||
import { config } from "./config.js";
|
||||
import packageJson from "../package.json";
|
||||
import logger from "./utils/logger.js";
|
||||
import app from "./app.js";
|
||||
|
||||
@@ -11,8 +10,8 @@ const serveHotApi: (port?: number) => void = (port: number = config.PORT) => {
|
||||
fetch: app.fetch,
|
||||
port,
|
||||
});
|
||||
logger.info(`📦 Version: ${packageJson.version}`);
|
||||
logger.info(`🔥 DailyHot API 成功在端口 ${port} 上运行`);
|
||||
logger.info(`💻 Puppeteer: ${config.USE_PUPPETEER}`);
|
||||
logger.info(`🔗 Local: 👉 http://localhost:${port}`);
|
||||
return apiServer;
|
||||
} catch (error) {
|
||||
|
||||
@@ -12,7 +12,7 @@ const typeMap: Record<string, string> = {
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "hot";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "36kr",
|
||||
title: "36氪",
|
||||
@@ -24,10 +24,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://m.36kr.com/hot-list-m",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -59,8 +57,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
||||
const list =
|
||||
result.data.data[(listType as Record<string, keyof typeof result.data.data>)[type || "hot"]];
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["36kr"]) => {
|
||||
const item = v.templateMaterial;
|
||||
return {
|
||||
|
||||
@@ -5,16 +5,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "51cto",
|
||||
title: "51CTO",
|
||||
type: "推荐榜",
|
||||
link: "https://www.51cto.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -41,8 +39,7 @@ const getList = async (noCache: boolean): Promise<RouterResType> => {
|
||||
});
|
||||
const list = result.data.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["51cto"]) => ({
|
||||
id: v.source_id,
|
||||
title: v.title,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "hot";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "52pojie",
|
||||
title: "吾爱破解",
|
||||
@@ -22,10 +22,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.52pojie.cn/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData?.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -47,8 +45,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
||||
};
|
||||
const list = await parseData();
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v, i) => ({
|
||||
id: v.guid || i,
|
||||
title: v.title || "",
|
||||
|
||||
@@ -27,7 +27,7 @@ const rangeMap: Record<string, string> = {
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "-1";
|
||||
const range = c.req.query("range") || "DAY";
|
||||
const { fromCache, data, updateTime } = await getList({ type, range }, noCache);
|
||||
const listData = await getList({ type, range }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "acfun",
|
||||
title: "AcFun",
|
||||
@@ -44,10 +44,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.acfun.cn/rank/list/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -64,8 +62,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
||||
});
|
||||
const list = result.data.rankList;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["acfun"]) => ({
|
||||
id: v.dougaId,
|
||||
title: v.contentTitle,
|
||||
|
||||
@@ -13,7 +13,7 @@ const typeMap: Record<string, string> = {
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "realtime";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "baidu",
|
||||
title: "百度",
|
||||
@@ -25,10 +25,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://top.baidu.com/board",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -49,8 +47,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
||||
const matchResult = result.data.match(pattern);
|
||||
const jsonObject = JSON.parse(matchResult[1]).cards[0].content;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: jsonObject.map((v: RouterType["baidu"]) => ({
|
||||
id: v.index,
|
||||
title: v.word,
|
||||
|
||||
@@ -22,7 +22,7 @@ const typeMap: Record<string, string> = {
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "0";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "bilibili",
|
||||
title: "哔哩哔哩",
|
||||
@@ -35,10 +35,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.bilibili.com/v/popular/rank/all",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -89,8 +87,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
||||
});
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["bilibili"]) => ({
|
||||
id: v.bvid,
|
||||
title: v.title,
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { genHeaders } from "../utils/getToken/coolapk.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "coolapk",
|
||||
title: "酷安",
|
||||
type: "热榜",
|
||||
link: "https://www.coolapk.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -27,8 +25,7 @@ const getList = async (noCache: boolean) => {
|
||||
});
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["coolapk"]) => ({
|
||||
id: v.id,
|
||||
title: v.message,
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "csdn",
|
||||
title: "CSDN",
|
||||
type: "排行榜",
|
||||
description: "专业开发者社区",
|
||||
link: "https://www.csdn.net/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean): Promise<RouterResType> => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["csdn"]) => ({
|
||||
id: v.productId,
|
||||
title: v.articleTitle,
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "douban-group",
|
||||
title: "豆瓣讨论",
|
||||
type: "讨论精选",
|
||||
link: "https://www.douban.com/group/explore",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -50,8 +48,7 @@ const getList = async (noCache: boolean) => {
|
||||
};
|
||||
});
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: listData,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -3,16 +3,14 @@ import { load } from "cheerio";
|
||||
import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "douban-movie",
|
||||
title: "豆瓣电影",
|
||||
type: "新片榜",
|
||||
link: "https://movie.douban.com/chart",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -58,8 +56,7 @@ const getList = async (noCache: boolean) => {
|
||||
};
|
||||
});
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: listData,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "douyin",
|
||||
title: "抖音",
|
||||
type: "热榜",
|
||||
description: "实时上升热点",
|
||||
link: "https://www.douyin.com",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -47,8 +45,7 @@ const getList = async (noCache: boolean) => {
|
||||
});
|
||||
const list = result.data.data.word_list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["douyin"]) => ({
|
||||
id: v.sentence_id,
|
||||
title: v.word,
|
||||
|
||||
@@ -14,16 +14,14 @@ const mappings: Record<string, string> = {
|
||||
};
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "earthquake",
|
||||
title: "中国地震台",
|
||||
type: "地震速报",
|
||||
link: "https://news.ceic.ac.cn/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -35,8 +33,7 @@ const getList = async (noCache: boolean) => {
|
||||
const match = result.data.match(regex);
|
||||
const list = match && match[1] ? JSON.parse(match[1]) : [];
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["earthquake"]) => {
|
||||
const contentBuilder = [];
|
||||
const { NEW_DID, LOCATION_C, M } = v;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "genshin",
|
||||
title: "原神",
|
||||
@@ -21,10 +21,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.miyoushe.com/ys/home/28",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -35,8 +33,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["miyoushe"]) => {
|
||||
const data = v.post;
|
||||
return {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const sort = c.req.query("sort") || "featured";
|
||||
const { fromCache, data, updateTime } = await getList({ sort }, noCache);
|
||||
const listData = await getList({ sort }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "hellogithub",
|
||||
title: "HelloGitHub",
|
||||
@@ -21,10 +21,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://hellogithub.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -35,8 +33,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["hellogithub"]) => ({
|
||||
id: v.item_id,
|
||||
title: v.title,
|
||||
|
||||
@@ -8,7 +8,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
// 获取日期
|
||||
const day = c.req.query("day") || getCurrentDateTime(true).day;
|
||||
const month = c.req.query("month") || getCurrentDateTime(true).month;
|
||||
const { fromCache, data, updateTime } = await getList({ month, day }, noCache);
|
||||
const listData = await getList({ month, day }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "history",
|
||||
title: "历史上的今天",
|
||||
@@ -18,10 +18,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
day: "日期",
|
||||
},
|
||||
link: "https://baike.baidu.com/calendar",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -39,8 +37,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
});
|
||||
const list = monthStr ? result.data[monthStr][monthStr + dayStr] : [];
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["history"], index: number) => ({
|
||||
id: index,
|
||||
title: load(v.title).text().trim(),
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "honkai",
|
||||
title: "崩坏3",
|
||||
@@ -21,10 +21,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.miyoushe.com/bh3/home/6",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -35,8 +33,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["miyoushe"]) => {
|
||||
const data = v.post;
|
||||
return {
|
||||
|
||||
@@ -12,7 +12,7 @@ const typeMap: Record<string, string> = {
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "hot";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "hostloc",
|
||||
title: "全球主机交流",
|
||||
@@ -24,10 +24,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://hostloc.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -49,8 +47,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
};
|
||||
const list = await parseData();
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v, i) => ({
|
||||
id: v.guid || i,
|
||||
title: v.title || "",
|
||||
|
||||
@@ -4,7 +4,7 @@ import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "hupu",
|
||||
title: "虎扑",
|
||||
@@ -22,10 +22,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://bbs.hupu.com/all-gambia",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -36,8 +34,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.topicThreads;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["hupu"]) => ({
|
||||
id: v.tid,
|
||||
title: v.title,
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "huxiu",
|
||||
title: "虎嗅",
|
||||
type: "24小时",
|
||||
link: "https://www.huxiu.com/moment/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -38,8 +36,7 @@ const getList = async (noCache: boolean) => {
|
||||
const matchResult = result.data.match(pattern);
|
||||
const jsonObject = JSON.parse(matchResult[1]).moment.momentList.moment_list.datalist;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: jsonObject.map((v: RouterType["huxiu"]) => ({
|
||||
id: v.object_id,
|
||||
title: titleProcessing(v.content).title,
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "ifanr",
|
||||
title: "爱范儿",
|
||||
type: "快讯",
|
||||
description: "15秒了解全球新鲜事",
|
||||
link: "https://www.ifanr.com/digest/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.objects;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["ifanr"]) => ({
|
||||
id: v.id,
|
||||
title: v.post_title,
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "ithome-xijiayi",
|
||||
title: "IT之家「喜加一」",
|
||||
type: "最新动态",
|
||||
description: "最新最全的「喜加一」游戏动态尽在这里!",
|
||||
link: "https://www.ithome.com/zt/xijiayi",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -51,8 +49,7 @@ const getList = async (noCache: boolean) => {
|
||||
};
|
||||
});
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: listData,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "ithome",
|
||||
title: "IT之家",
|
||||
type: "热榜",
|
||||
description: "爱科技,爱这里 - 前沿科技新闻网站",
|
||||
link: "https://m.ithome.com/rankm/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -51,8 +49,7 @@ const getList = async (noCache: boolean) => {
|
||||
};
|
||||
});
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: listData,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -3,17 +3,15 @@ import { load } from "cheerio";
|
||||
import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "jianshu",
|
||||
title: "简书",
|
||||
type: "热门推荐",
|
||||
description: "一个优质的创作社区",
|
||||
link: "https://www.jianshu.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -52,8 +50,7 @@ const getList = async (noCache: boolean) => {
|
||||
};
|
||||
});
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: listData,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -3,16 +3,14 @@ import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "juejin",
|
||||
title: "稀土掘金",
|
||||
type: "文章榜",
|
||||
link: "https://juejin.cn/hot/articles",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -22,8 +20,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["juejin"]) => ({
|
||||
id: v.content.content_id,
|
||||
title: v.content.title,
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "lol",
|
||||
title: "英雄联盟",
|
||||
type: "更新公告",
|
||||
link: "https://lol.qq.com/gicp/news/423/2/1334/1.html",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.result;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["lol"]) => ({
|
||||
id: v.iDocID,
|
||||
title: v.sTitle,
|
||||
|
||||
@@ -25,7 +25,7 @@ const typeMap: Record<string, string> = {
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const game = c.req.query("game") || "1";
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ game, type }, noCache);
|
||||
const listData = await getList({ game, type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "miyoushe",
|
||||
title: `米游社 · ${gameMap[game]}`,
|
||||
@@ -41,10 +41,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.miyoushe.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -55,8 +53,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["miyoushe"]) => {
|
||||
const data = v.post;
|
||||
return {
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "netease-news",
|
||||
title: "网易新闻",
|
||||
type: "热点榜",
|
||||
link: "https://m.163.com/hot",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["netease-news"]) => ({
|
||||
id: v.docid,
|
||||
title: v.title,
|
||||
|
||||
@@ -4,17 +4,15 @@ import { post } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "ngabbs",
|
||||
title: "NGA",
|
||||
type: "论坛热帖",
|
||||
description: "精英玩家俱乐部",
|
||||
link: "https://ngabbs.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -42,8 +40,7 @@ const getList = async (noCache: boolean) => {
|
||||
});
|
||||
const list = result.data.result[0];
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["ngabbs"]) => ({
|
||||
id: v.tid,
|
||||
title: v.subject,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { parseStringPromise } from "xml2js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "nodeseek",
|
||||
title: "NodeSeek",
|
||||
@@ -19,10 +19,8 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.nodeseek.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -33,8 +31,7 @@ const getList = async (noCache: boolean) => {
|
||||
const rssData = await parseStringPromise(result.data);
|
||||
const list = rssData.rss.channel[0].item;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["nodeseek"]) => ({
|
||||
id: v.guid[0]._,
|
||||
title: v.title[0],
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "qq-news",
|
||||
title: "腾讯新闻",
|
||||
type: "热点榜",
|
||||
link: "https://news.qq.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.idlist[0].newslist.slice(1);
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["qq-news"]) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
|
||||
@@ -64,7 +64,7 @@ const listType = {
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "sina-news",
|
||||
title: "新浪新闻",
|
||||
@@ -76,10 +76,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://sinanews.sina.cn/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -122,8 +120,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = parseData(result.data).data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["sina-news"]) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "sina",
|
||||
title: "新浪网",
|
||||
@@ -28,10 +28,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://sinanews.sina.cn/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -42,8 +40,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.hotList;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["sina"]) => {
|
||||
const base = v.base;
|
||||
const info = v.info;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "热门文章";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "sspai",
|
||||
title: "少数派",
|
||||
@@ -17,10 +17,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://sspai.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -31,8 +29,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["sspai"]) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "starrail",
|
||||
title: "崩坏:星穹铁道",
|
||||
@@ -21,10 +21,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.miyoushe.com/sr/home/53",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -35,8 +33,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["miyoushe"]) => {
|
||||
const data = v.post;
|
||||
return {
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "thepaper",
|
||||
title: "澎湃新闻",
|
||||
type: "热榜",
|
||||
link: "https://www.thepaper.cn/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.hotNews;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["thepaper"]) => ({
|
||||
id: v.contId,
|
||||
title: v.name,
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "tieba",
|
||||
title: "百度贴吧",
|
||||
type: "热议榜",
|
||||
description: "全球领先的中文社区",
|
||||
link: "https://tieba.baidu.com/hottopic/browse/topicList",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.bang_topic.topic_list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["tieba"]) => ({
|
||||
id: v.topic_id,
|
||||
title: v.topic_name,
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "toutiao",
|
||||
title: "今日头条",
|
||||
type: "热榜",
|
||||
link: "https://www.toutiao.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["toutiao"]) => ({
|
||||
id: v.ClusterIdStr,
|
||||
title: v.Title,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "hot";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const listData = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "v2ex",
|
||||
title: "V2EX",
|
||||
@@ -19,10 +19,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "https://www.v2ex.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -33,8 +31,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["v2ex"]) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
|
||||
@@ -5,11 +5,11 @@ import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const province = c.req.query("province") || "";
|
||||
const { fromCache, data, type, updateTime } = await getList({ province }, noCache);
|
||||
const listData = await getList({ province }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "weatheralarm",
|
||||
title: "中央气象台",
|
||||
type: type || "全国气象预警",
|
||||
type: `${province || "全国"}气象预警`,
|
||||
params: {
|
||||
province: {
|
||||
name: "预警区域",
|
||||
@@ -17,10 +17,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
},
|
||||
},
|
||||
link: "http://nmc.cn/publish/alarm.html",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -31,9 +29,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.page.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
type: province + "气象预警",
|
||||
...result,
|
||||
data: list.map((v: RouterType["weatheralarm"]) => ({
|
||||
id: v.alertid,
|
||||
title: v.title,
|
||||
|
||||
@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "weibo",
|
||||
title: "微博",
|
||||
type: "热搜榜",
|
||||
description: "实时热点,每分钟更新一次",
|
||||
link: "https://s.weibo.com/top/summary/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache, ttl: 60 });
|
||||
const list = result.data.data.realtime;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["weibo"]) => {
|
||||
const key = v.word_scheme ? v.word_scheme : `#${v.word}`;
|
||||
return {
|
||||
|
||||
@@ -5,16 +5,14 @@ import getWereadID from "../utils/getToken/weread.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "weread",
|
||||
title: "微信读书",
|
||||
type: "飙升榜",
|
||||
link: "https://weread.qq.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -31,8 +29,7 @@ const getList = async (noCache: boolean) => {
|
||||
});
|
||||
const list = result.data.books;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["weread"]) => {
|
||||
const data = v.bookInfo;
|
||||
return {
|
||||
|
||||
@@ -3,17 +3,15 @@ import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "zhihu-daily",
|
||||
title: "知乎日报",
|
||||
type: "推荐榜",
|
||||
description: "每天三次,每次七分钟",
|
||||
link: "https://daily.zhihu.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -30,8 +28,7 @@ const getList = async (noCache: boolean) => {
|
||||
});
|
||||
const list = result.data.stories.filter((el: RouterType["zhihu-daily"]) => el.type === 0);
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["zhihu-daily"]) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
|
||||
@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
|
||||
import { getTime } from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const listData = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "zhihu",
|
||||
title: "知乎",
|
||||
type: "热榜",
|
||||
link: "https://www.zhihu.com/hot",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
total: listData.data?.length || 0,
|
||||
...listData,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
...result,
|
||||
data: list.map((v: RouterType["zhihu"]) => {
|
||||
const data = v.target;
|
||||
return {
|
||||
|
||||
3
src/types.d.ts
vendored
3
src/types.d.ts
vendored
@@ -18,9 +18,10 @@ export interface ListItem {
|
||||
|
||||
// 路由接口数据
|
||||
export interface RouterResType {
|
||||
updateTime: string;
|
||||
updateTime: string | number;
|
||||
fromCache: boolean;
|
||||
data: ListItem[];
|
||||
message?: string;
|
||||
}
|
||||
|
||||
// 路由数据
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Get, Post, Web } from "../types.ts";
|
||||
import type { Get, Post, Web } from "../types.js";
|
||||
import type { Page } from "puppeteer";
|
||||
import { config } from "../config.js";
|
||||
import { getCache, setCache, delCache } from "./cache.js";
|
||||
import { Cluster } from "puppeteer-cluster";
|
||||
@@ -12,24 +13,50 @@ const request = axios.create({
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
// puppeteer-cluster
|
||||
export const createCluster = async () => {
|
||||
return await Cluster.launch({
|
||||
concurrency: Cluster.CONCURRENCY_BROWSER,
|
||||
maxConcurrency: 5,
|
||||
// puppeteer
|
||||
puppeteerOptions: {
|
||||
headless: true,
|
||||
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
||||
},
|
||||
});
|
||||
// Puppeteer Cluster
|
||||
let cluster: Cluster | null = null;
|
||||
|
||||
/**
|
||||
* 创建 Puppeteer Cluster
|
||||
* @returns {Promise<Cluster|null>} Puppeteer Cluster
|
||||
*/
|
||||
export const createCluster = async (): Promise<Cluster | null> => {
|
||||
if (cluster) return cluster;
|
||||
try {
|
||||
cluster = await Cluster.launch({
|
||||
concurrency: Cluster.CONCURRENCY_BROWSER,
|
||||
maxConcurrency: 5,
|
||||
puppeteerOptions: {
|
||||
headless: true,
|
||||
args: [
|
||||
"--no-sandbox",
|
||||
"--disable-gpu",
|
||||
"--disable-setuid-sandbox",
|
||||
"--disable-dev-shm-usage",
|
||||
],
|
||||
},
|
||||
});
|
||||
logger.info("Puppeteer Cluster 已成功初始化");
|
||||
} catch (error) {
|
||||
logger.warn("启动 Puppeteer Cluster 失败,可能是没有 Chromium 安装", error);
|
||||
cluster = null;
|
||||
}
|
||||
return cluster;
|
||||
};
|
||||
|
||||
// Cluster
|
||||
const cluster = await createCluster();
|
||||
|
||||
// Cluster configuration
|
||||
cluster.task(async ({ page, data: { url, userAgent } }) => {
|
||||
/**
|
||||
* 处理任务
|
||||
* @param page 页面
|
||||
* @param data 数据
|
||||
* @returns
|
||||
*/
|
||||
const taskHandler = async ({
|
||||
page,
|
||||
data: { url, userAgent },
|
||||
}: {
|
||||
page: Page;
|
||||
data: { url: string; userAgent?: string };
|
||||
}): Promise<string> => {
|
||||
// 用户代理
|
||||
if (userAgent) await page.setUserAgent(userAgent);
|
||||
// 请求拦截
|
||||
@@ -45,9 +72,9 @@ cluster.task(async ({ page, data: { url, userAgent } }) => {
|
||||
});
|
||||
// 加载页面
|
||||
await page.goto(url, { waitUntil: "networkidle0", timeout: config.REQUEST_TIMEOUT });
|
||||
const pageContent = await page.content();
|
||||
return pageContent;
|
||||
});
|
||||
// 返回页面内容
|
||||
return page.content();
|
||||
};
|
||||
|
||||
// 请求拦截
|
||||
request.interceptors.request.use(
|
||||
@@ -137,12 +164,25 @@ export const post = async (options: Post) => {
|
||||
}
|
||||
};
|
||||
|
||||
// puppeteer
|
||||
// WEB - Puppeteer
|
||||
export const web = async (options: Web) => {
|
||||
const { url, noCache, ttl = config.CACHE_TTL, userAgent } = options;
|
||||
logger.info("使用 Puppeteer 发起页面请求", options);
|
||||
if (config.USE_PUPPETEER === false) {
|
||||
return {
|
||||
fromCache: false,
|
||||
data: [],
|
||||
message: "Puppeteer is not enabled, please set USE_PUPPETEER=true",
|
||||
updateTime: 0,
|
||||
};
|
||||
}
|
||||
// 初始化 Cluster
|
||||
const clusterInstance = await createCluster();
|
||||
if (!clusterInstance) {
|
||||
logger.error("Cluster 初始化失败,无法继续");
|
||||
throw new Error("Cluster 初始化失败");
|
||||
}
|
||||
try {
|
||||
if (!cluster) throw new Error("Cluster is not initialized");
|
||||
// 检查缓存
|
||||
if (noCache) {
|
||||
delCache(url);
|
||||
@@ -155,7 +195,7 @@ export const web = async (options: Web) => {
|
||||
}
|
||||
// 缓存不存在时使用 Puppeteer 请求页面
|
||||
logger.info("启动浏览器请求页面", { url });
|
||||
const pageContent = await cluster.execute({ url, userAgent });
|
||||
const pageContent = await clusterInstance.execute({ url, userAgent }, taskHandler);
|
||||
// 存储新获取的数据到缓存
|
||||
const updateTime = new Date().toISOString();
|
||||
setCache(url, { data: pageContent, updateTime }, ttl);
|
||||
@@ -167,3 +207,17 @@ export const web = async (options: Web) => {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 关闭 Cluster
|
||||
*/
|
||||
export const closeCluster = async () => {
|
||||
if (cluster) {
|
||||
try {
|
||||
await cluster.close();
|
||||
logger.info("Puppeteer Cluster 已成功关闭");
|
||||
} catch (error) {
|
||||
logger.error("关闭 Puppeteer Cluster 时出错", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,8 +25,8 @@ export const parseRSS = async (rssContent: string) => {
|
||||
try {
|
||||
new URL(url);
|
||||
return true;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user