🦄 refactor: 调整接口结构

This commit is contained in:
imsyy
2024-12-04 17:47:48 +08:00
parent 0cce0d6067
commit f38d264366
54 changed files with 348 additions and 362 deletions

View File

@@ -1,24 +1,27 @@
# 服务端口 # 服务端口
PORT = 6688 PORT=6688
# 允许的域名 # 允许的域名
ALLOWED_DOMAIN = "*" ALLOWED_DOMAIN="*"
# 允许的主域名,填写格式为 imsyy.top # 允许的主域名,填写格式为 imsyy.top
## 若填写该项,将忽略 ALLOWED_DOMAIN ## 若填写该项,将忽略 ALLOWED_DOMAIN
ALLOWED_HOST = "" ALLOWED_HOST=""
# ROBOT # 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
RSS_MODE = false RSS_MODE=false
# Puppeteer
USE_PUPPETEER=false

View File

@@ -43,7 +43,7 @@ jobs:
imsyy/dailyhot-api imsyy/dailyhot-api
ghcr.io/${{ github.repository }} ghcr.io/${{ github.repository }}
- name: Build and push - name: Build and push regular image (no Puppeteer)
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:
context: . context: .
@@ -54,3 +54,18 @@ jobs:
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} 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 }}

View File

@@ -3,13 +3,27 @@ FROM node:20-alpine AS base
ENV NODE_ENV=docker ENV NODE_ENV=docker
# 安装 Puppeteer 所需的依赖库 # 安装 Puppeteer 所需的依赖库
RUN apk add libc6-compat RUN apk add --no-cache \
# RUN apk add chromium nss freetype harfbuzz ca-certificates 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 # 配置 Chromium
# ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
# ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
# 清理缓存
RUN rm -rf /var/cache/apk/*
# 构建阶段
FROM base AS builder FROM base AS builder
RUN npm install -g pnpm RUN npm install -g pnpm
@@ -21,13 +35,16 @@ COPY public ./public
# add .env.example to .env # add .env.example to .env
RUN [ ! -e ".env" ] && cp .env.example .env || true 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 install
RUN pnpm build RUN pnpm build
RUN pnpm prune --production RUN pnpm prune --production
# 运行阶段
FROM base AS runner FROM base AS runner
WORKDIR /app
# 创建用户和组 # 创建用户和组
RUN addgroup --system --gid 114514 nodejs 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 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 COPY --from=builder --chown=hono:nodejs /app/node_modules /app/node_modules

View File

@@ -66,6 +66,7 @@
| 虎扑 | 步行街热帖 | hupu | ![](https://img.shields.io/website.svg?label=hupu&url=https://api-hot.imsyy.top/hupu&cacheSeconds=7200) | | 虎扑 | 步行街热帖 | hupu | ![](https://img.shields.io/website.svg?label=hupu&url=https://api-hot.imsyy.top/hupu&cacheSeconds=7200) |
| 爱范儿 | 快讯 | ifanr | ![](https://img.shields.io/website.svg?label=ifanr&url=https://api-hot.imsyy.top/ifanr&cacheSeconds=7200) | | 爱范儿 | 快讯 | ifanr | ![](https://img.shields.io/website.svg?label=ifanr&url=https://api-hot.imsyy.top/ifanr&cacheSeconds=7200) |
| 英雄联盟 | 更新公告 | lol | ![](https://img.shields.io/website.svg?label=lol&url=https://api-hot.imsyy.top/lol&cacheSeconds=7200) | | 英雄联盟 | 更新公告 | lol | ![](https://img.shields.io/website.svg?label=lol&url=https://api-hot.imsyy.top/lol&cacheSeconds=7200) |
| 米游社 | 最新消息 | miyoushe | ![](https://img.shields.io/website.svg?label=miyoushe&url=https://api-hot.imsyy.top/miyoushe&cacheSeconds=7200) |
| 原神 | 最新消息 | genshin | ![](https://img.shields.io/website.svg?label=genshin&url=https://api-hot.imsyy.top/genshin&cacheSeconds=7200) | | 原神 | 最新消息 | genshin | ![](https://img.shields.io/website.svg?label=genshin&url=https://api-hot.imsyy.top/genshin&cacheSeconds=7200) |
| 崩坏3 | 最新动态 | honkai | ![](https://img.shields.io/website.svg?label=honkai&url=https://api-hot.imsyy.top/honkai&cacheSeconds=7200) | | 崩坏3 | 最新动态 | honkai | ![](https://img.shields.io/website.svg?label=honkai&url=https://api-hot.imsyy.top/honkai&cacheSeconds=7200) |
| 崩坏:星穹铁道 | 最新动态 | starrail | ![](https://img.shields.io/website.svg?label=starrail&url=https://api-hot.imsyy.top/starrail&cacheSeconds=7200) | | 崩坏:星穹铁道 | 最新动态 | starrail | ![](https://img.shields.io/website.svg?label=starrail&url=https://api-hot.imsyy.top/starrail&cacheSeconds=7200) |
@@ -83,6 +84,8 @@
本项目支持 `Node.js` 调用,可在安装完成后调用 `serveHotApi` 来开启服务器 本项目支持 `Node.js` 调用,可在安装完成后调用 `serveHotApi` 来开启服务器
> 该方式无法使用部分需要 Puppeteer 环境的接口
```bash ```bash
pnpm add dailyhot-api pnpm add dailyhot-api
``` ```
@@ -100,6 +103,8 @@ serveHotApi(3000);
## ⚙️ 部署 ## ⚙️ 部署
由于部分接口无法通过接口调用等方式获取数据,故采用 `Puppeteer` 来实现,但由于使用后会造成 **内存占用过大或镜像过大**,可选择性开启,详情请参考下方说明。
具体使用说明可参考 [我的博客](https://blog.imsyy.top/posts/2024/0408),下方仅讲解基础操作: 具体使用说明可参考 [我的博客](https://blog.imsyy.top/posts/2024/0408),下方仅讲解基础操作:
### Docker 部署 ### Docker 部署
@@ -111,8 +116,11 @@ serveHotApi(3000);
```bash ```bash
# 构建 # 构建
docker build -t dailyhot-api . 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
docker-compose up -d docker-compose up -d
``` ```
@@ -122,8 +130,11 @@ docker-compose up -d
```bash ```bash
# 拉取 # 拉取
docker pull imsyy/dailyhot-api:latest 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 ```bash
# 标准运行
npm run dev npm run dev
# 采用 Puppeteer 运行
npm run dev:web
``` ```
成功启动后程序会在控制台输出可访问的地址 成功启动后程序会在控制台输出可访问的地址
@@ -157,7 +171,11 @@ npm run dev
```bash ```bash
npm run build npm run build
# 标准运行
npm run start npm run start
# 采用 Puppeteer 运行
npm run start:web
``` ```
成功启动后程序会在控制台输出可访问的地址 成功启动后程序会在控制台输出可访问的地址

View File

@@ -30,9 +30,11 @@
"format": "prettier --write .", "format": "prettier --write .",
"lint": "eslint .", "lint": "eslint .",
"dev": "cross-env NODE_ENV=development tsx watch --no-cache src/index.ts", "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", "dev:cache": "cross-env NODE_ENV=development tsx watch src/index.ts",
"build": "tsc --project tsconfig.json", "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", "type": "module",
"dependencies": { "dependencies": {
@@ -46,6 +48,7 @@
"hono": "^4.6.12", "hono": "^4.6.12",
"md5": "^2.3.0", "md5": "^2.3.0",
"node-cache": "^5.1.2", "node-cache": "^5.1.2",
"puppeteer": "^23.10.0",
"puppeteer-cluster": "^0.24.0", "puppeteer-cluster": "^0.24.0",
"rss-parser": "^3.13.0", "rss-parser": "^3.13.0",
"winston": "^3.17.0", "winston": "^3.17.0",

33
pnpm-lock.yaml generated
View File

@@ -38,9 +38,12 @@ importers:
node-cache: node-cache:
specifier: ^5.1.2 specifier: ^5.1.2
version: 5.1.2 version: 5.1.2
puppeteer:
specifier: ^23.10.0
version: 23.10.0(typescript@5.7.2)
puppeteer-cluster: puppeteer-cluster:
specifier: ^0.24.0 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: rss-parser:
specifier: ^3.13.0 specifier: ^3.13.0
version: 3.13.0 version: 3.13.0
@@ -324,8 +327,8 @@ packages:
resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==}
engines: {node: '>= 8'} engines: {node: '>= 8'}
'@puppeteer/browsers@2.4.1': '@puppeteer/browsers@2.5.0':
resolution: {integrity: sha512-0kdAbmic3J09I6dT8e9vE2JOCSt13wHCW5x/ly8TSt2bDtuIWe2TgLZZDHdcziw9AVCzflMAXCrVyRIhIs44Ng==} resolution: {integrity: sha512-6TQAc/5uRILE6deixJ1CR8rXyTbzXIXNgO1D0Woi9Bqicz2FV5iKP3BHYEg6o4UATCMcbQQ0jbmeaOkn/HQk2w==}
engines: {node: '>=18'} engines: {node: '>=18'}
hasBin: true hasBin: true
@@ -1117,12 +1120,12 @@ packages:
peerDependencies: peerDependencies:
puppeteer: '>=22.0.0' puppeteer: '>=22.0.0'
puppeteer-core@23.9.0: puppeteer-core@23.10.0:
resolution: {integrity: sha512-hLVrav2HYMVdK0YILtfJwtnkBAwNOztUdR4aJ5YKDvgsbtagNr6urUJk9HyjRA9e+PaLI3jzJ0wM7A4jSZ7Qxw==} resolution: {integrity: sha512-7pv6kFget4Iki0RLBDowi35vaccz73XpC6/FAnfCrYa2IXVUlBHfZw+HGWzlvvTGwM9HHd32rgCrIDzil3kj+w==}
engines: {node: '>=18'} engines: {node: '>=18'}
puppeteer@23.9.0: puppeteer@23.10.0:
resolution: {integrity: sha512-WfB8jGwFV+qrD9dcJJVvWPFJBU6kxeu2wxJz9WooDGfM3vIiKLgzImEDBxUQnCBK/2cXB3d4dV6gs/LLpgfLDg==} resolution: {integrity: sha512-vLpEvUM8POKBX4j6y/yyD4oGRhS1oBAbMn3lYpz1yeakhRsA8IhF5QmjXwAIQYGdR/INxyFiY6kQDoUtLGDP3g==}
engines: {node: '>=18'} engines: {node: '>=18'}
hasBin: true hasBin: true
@@ -1552,7 +1555,7 @@ snapshots:
'@nodelib/fs.scandir': 2.1.5 '@nodelib/fs.scandir': 2.1.5
fastq: 1.17.1 fastq: 1.17.1
'@puppeteer/browsers@2.4.1': '@puppeteer/browsers@2.5.0':
dependencies: dependencies:
debug: 4.3.7 debug: 4.3.7
extract-zip: 2.0.1 extract-zip: 2.0.1
@@ -2430,16 +2433,16 @@ snapshots:
punycode@2.3.1: {} 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: dependencies:
debug: 4.3.7 debug: 4.3.7
puppeteer: 23.9.0(typescript@5.7.2) puppeteer: 23.10.0(typescript@5.7.2)
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
puppeteer-core@23.9.0: puppeteer-core@23.10.0:
dependencies: dependencies:
'@puppeteer/browsers': 2.4.1 '@puppeteer/browsers': 2.5.0
chromium-bidi: 0.8.0(devtools-protocol@0.0.1367902) chromium-bidi: 0.8.0(devtools-protocol@0.0.1367902)
debug: 4.3.7 debug: 4.3.7
devtools-protocol: 0.0.1367902 devtools-protocol: 0.0.1367902
@@ -2450,13 +2453,13 @@ snapshots:
- supports-color - supports-color
- utf-8-validate - utf-8-validate
puppeteer@23.9.0(typescript@5.7.2): puppeteer@23.10.0(typescript@5.7.2):
dependencies: dependencies:
'@puppeteer/browsers': 2.4.1 '@puppeteer/browsers': 2.5.0
chromium-bidi: 0.8.0(devtools-protocol@0.0.1367902) chromium-bidi: 0.8.0(devtools-protocol@0.0.1367902)
cosmiconfig: 9.0.0(typescript@5.7.2) cosmiconfig: 9.0.0(typescript@5.7.2)
devtools-protocol: 0.0.1367902 devtools-protocol: 0.0.1367902
puppeteer-core: 23.9.0 puppeteer-core: 23.10.0
typed-query-selector: 2.12.0 typed-query-selector: 2.12.0
transitivePeerDependencies: transitivePeerDependencies:
- bufferutil - bufferutil

View File

@@ -12,6 +12,7 @@ export type Config = {
ALLOWED_HOST: string; ALLOWED_HOST: string;
USE_LOG_FILE: boolean; USE_LOG_FILE: boolean;
RSS_MODE: boolean; RSS_MODE: boolean;
USE_PUPPETEER: boolean;
}; };
// 验证并提取环境变量 // 验证并提取环境变量
@@ -49,4 +50,5 @@ export const config: Config = {
ALLOWED_HOST: getEnvVariable("ALLOWED_HOST") || "imsyy.top", ALLOWED_HOST: getEnvVariable("ALLOWED_HOST") || "imsyy.top",
USE_LOG_FILE: getBooleanEnvVariable("USE_LOG_FILE", true), USE_LOG_FILE: getBooleanEnvVariable("USE_LOG_FILE", true),
RSS_MODE: getBooleanEnvVariable("RSS_MODE", false), RSS_MODE: getBooleanEnvVariable("RSS_MODE", false),
USE_PUPPETEER: getBooleanEnvVariable("USE_PUPPETEER", false),
}; };

View File

@@ -1,6 +1,5 @@
import { serve } from "@hono/node-server"; import { serve } from "@hono/node-server";
import { config } from "./config.js"; import { config } from "./config.js";
import packageJson from "../package.json";
import logger from "./utils/logger.js"; import logger from "./utils/logger.js";
import app from "./app.js"; import app from "./app.js";
@@ -11,8 +10,8 @@ const serveHotApi: (port?: number) => void = (port: number = config.PORT) => {
fetch: app.fetch, fetch: app.fetch,
port, port,
}); });
logger.info(`📦 Version: ${packageJson.version}`);
logger.info(`🔥 DailyHot API 成功在端口 ${port} 上运行`); logger.info(`🔥 DailyHot API 成功在端口 ${port} 上运行`);
logger.info(`💻 Puppeteer: ${config.USE_PUPPETEER}`);
logger.info(`🔗 Local: 👉 http://localhost:${port}`); logger.info(`🔗 Local: 👉 http://localhost:${port}`);
return apiServer; return apiServer;
} catch (error) { } catch (error) {

View File

@@ -12,7 +12,7 @@ const typeMap: Record<string, string> = {
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "hot"; const type = c.req.query("type") || "hot";
const { fromCache, data, updateTime } = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "36kr", name: "36kr",
title: "36氪", title: "36氪",
@@ -24,10 +24,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://m.36kr.com/hot-list-m", link: "https://m.36kr.com/hot-list-m",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -59,8 +57,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
const list = const list =
result.data.data[(listType as Record<string, keyof typeof result.data.data>)[type || "hot"]]; result.data.data[(listType as Record<string, keyof typeof result.data.data>)[type || "hot"]];
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["36kr"]) => { data: list.map((v: RouterType["36kr"]) => {
const item = v.templateMaterial; const item = v.templateMaterial;
return { return {

View File

@@ -5,16 +5,14 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "51cto", name: "51cto",
title: "51CTO", title: "51CTO",
type: "推荐榜", type: "推荐榜",
link: "https://www.51cto.com/", link: "https://www.51cto.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -41,8 +39,7 @@ const getList = async (noCache: boolean): Promise<RouterResType> => {
}); });
const list = result.data.data.data.list; const list = result.data.data.data.list;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["51cto"]) => ({ data: list.map((v: RouterType["51cto"]) => ({
id: v.source_id, id: v.source_id,
title: v.title, title: v.title,

View File

@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "hot"; const type = c.req.query("type") || "hot";
const { fromCache, data, updateTime } = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "52pojie", name: "52pojie",
title: "吾爱破解", title: "吾爱破解",
@@ -22,10 +22,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://www.52pojie.cn/", link: "https://www.52pojie.cn/",
total: data?.length || 0, total: listData?.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -47,8 +45,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
}; };
const list = await parseData(); const list = await parseData();
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v, i) => ({ data: list.map((v, i) => ({
id: v.guid || i, id: v.guid || i,
title: v.title || "", title: v.title || "",

View File

@@ -27,7 +27,7 @@ const rangeMap: Record<string, string> = {
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "-1"; const type = c.req.query("type") || "-1";
const range = c.req.query("range") || "DAY"; 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 = { const routeData: RouterData = {
name: "acfun", name: "acfun",
title: "AcFun", title: "AcFun",
@@ -44,10 +44,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://www.acfun.cn/rank/list/", link: "https://www.acfun.cn/rank/list/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -64,8 +62,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
}); });
const list = result.data.rankList; const list = result.data.rankList;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["acfun"]) => ({ data: list.map((v: RouterType["acfun"]) => ({
id: v.dougaId, id: v.dougaId,
title: v.contentTitle, title: v.contentTitle,

View File

@@ -13,7 +13,7 @@ const typeMap: Record<string, string> = {
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "realtime"; const type = c.req.query("type") || "realtime";
const { fromCache, data, updateTime } = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "baidu", name: "baidu",
title: "百度", title: "百度",
@@ -25,10 +25,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://top.baidu.com/board", link: "https://top.baidu.com/board",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -49,8 +47,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
const matchResult = result.data.match(pattern); const matchResult = result.data.match(pattern);
const jsonObject = JSON.parse(matchResult[1]).cards[0].content; const jsonObject = JSON.parse(matchResult[1]).cards[0].content;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: jsonObject.map((v: RouterType["baidu"]) => ({ data: jsonObject.map((v: RouterType["baidu"]) => ({
id: v.index, id: v.index,
title: v.word, title: v.word,

View File

@@ -22,7 +22,7 @@ const typeMap: Record<string, string> = {
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "0"; const type = c.req.query("type") || "0";
const { fromCache, data, updateTime } = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "bilibili", name: "bilibili",
title: "哔哩哔哩", title: "哔哩哔哩",
@@ -35,10 +35,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://www.bilibili.com/v/popular/rank/all", link: "https://www.bilibili.com/v/popular/rank/all",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -89,8 +87,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
}); });
const list = result.data.data.list; const list = result.data.data.list;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["bilibili"]) => ({ data: list.map((v: RouterType["bilibili"]) => ({
id: v.bvid, id: v.bvid,
title: v.title, title: v.title,

View File

@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
import { genHeaders } from "../utils/getToken/coolapk.js"; import { genHeaders } from "../utils/getToken/coolapk.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "coolapk", name: "coolapk",
title: "酷安", title: "酷安",
type: "热榜", type: "热榜",
link: "https://www.coolapk.com/", link: "https://www.coolapk.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -27,8 +25,7 @@ const getList = async (noCache: boolean) => {
}); });
const list = result.data.data; const list = result.data.data;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["coolapk"]) => ({ data: list.map((v: RouterType["coolapk"]) => ({
id: v.id, id: v.id,
title: v.message, title: v.message,

View File

@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "csdn", name: "csdn",
title: "CSDN", title: "CSDN",
type: "排行榜", type: "排行榜",
description: "专业开发者社区", description: "专业开发者社区",
link: "https://www.csdn.net/", link: "https://www.csdn.net/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean): Promise<RouterResType> => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data; const list = result.data.data;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["csdn"]) => ({ data: list.map((v: RouterType["csdn"]) => ({
id: v.productId, id: v.productId,
title: v.articleTitle, title: v.articleTitle,

View File

@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "douban-group", name: "douban-group",
title: "豆瓣讨论", title: "豆瓣讨论",
type: "讨论精选", type: "讨论精选",
link: "https://www.douban.com/group/explore", link: "https://www.douban.com/group/explore",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -50,8 +48,7 @@ const getList = async (noCache: boolean) => {
}; };
}); });
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: listData, data: listData,
}; };
}; };

View File

@@ -3,16 +3,14 @@ import { load } from "cheerio";
import { get } from "../utils/getData.js"; import { get } from "../utils/getData.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "douban-movie", name: "douban-movie",
title: "豆瓣电影", title: "豆瓣电影",
type: "新片榜", type: "新片榜",
link: "https://movie.douban.com/chart", link: "https://movie.douban.com/chart",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -58,8 +56,7 @@ const getList = async (noCache: boolean) => {
}; };
}); });
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: listData, data: listData,
}; };
}; };

View File

@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "douyin", name: "douyin",
title: "抖音", title: "抖音",
type: "热榜", type: "热榜",
description: "实时上升热点", description: "实时上升热点",
link: "https://www.douyin.com", link: "https://www.douyin.com",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -47,8 +45,7 @@ const getList = async (noCache: boolean) => {
}); });
const list = result.data.data.word_list; const list = result.data.data.word_list;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["douyin"]) => ({ data: list.map((v: RouterType["douyin"]) => ({
id: v.sentence_id, id: v.sentence_id,
title: v.word, title: v.word,

View File

@@ -14,16 +14,14 @@ const mappings: Record<string, string> = {
}; };
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "earthquake", name: "earthquake",
title: "中国地震台", title: "中国地震台",
type: "地震速报", type: "地震速报",
link: "https://news.ceic.ac.cn/", link: "https://news.ceic.ac.cn/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -35,8 +33,7 @@ const getList = async (noCache: boolean) => {
const match = result.data.match(regex); const match = result.data.match(regex);
const list = match && match[1] ? JSON.parse(match[1]) : []; const list = match && match[1] ? JSON.parse(match[1]) : [];
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["earthquake"]) => { data: list.map((v: RouterType["earthquake"]) => {
const contentBuilder = []; const contentBuilder = [];
const { NEW_DID, LOCATION_C, M } = v; const { NEW_DID, LOCATION_C, M } = v;

View File

@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "1"; const type = c.req.query("type") || "1";
const { fromCache, data, updateTime } = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "genshin", name: "genshin",
title: "原神", title: "原神",
@@ -21,10 +21,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://www.miyoushe.com/ys/home/28", link: "https://www.miyoushe.com/ys/home/28",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -35,8 +33,7 @@ const getList = async (options: Options, noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data.list; const list = result.data.data.list;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["miyoushe"]) => { data: list.map((v: RouterType["miyoushe"]) => {
const data = v.post; const data = v.post;
return { return {

View File

@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const sort = c.req.query("sort") || "featured"; const sort = c.req.query("sort") || "featured";
const { fromCache, data, updateTime } = await getList({ sort }, noCache); const listData = await getList({ sort }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "hellogithub", name: "hellogithub",
title: "HelloGitHub", title: "HelloGitHub",
@@ -21,10 +21,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://hellogithub.com/", link: "https://hellogithub.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -35,8 +33,7 @@ const getList = async (options: Options, noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data; const list = result.data.data;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["hellogithub"]) => ({ data: list.map((v: RouterType["hellogithub"]) => ({
id: v.item_id, id: v.item_id,
title: v.title, title: v.title,

View File

@@ -8,7 +8,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
// 获取日期 // 获取日期
const day = c.req.query("day") || getCurrentDateTime(true).day; const day = c.req.query("day") || getCurrentDateTime(true).day;
const month = c.req.query("month") || getCurrentDateTime(true).month; 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 = { const routeData: RouterData = {
name: "history", name: "history",
title: "历史上的今天", title: "历史上的今天",
@@ -18,10 +18,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
day: "日期", day: "日期",
}, },
link: "https://baike.baidu.com/calendar", link: "https://baike.baidu.com/calendar",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -39,8 +37,7 @@ const getList = async (options: Options, noCache: boolean) => {
}); });
const list = monthStr ? result.data[monthStr][monthStr + dayStr] : []; const list = monthStr ? result.data[monthStr][monthStr + dayStr] : [];
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["history"], index: number) => ({ data: list.map((v: RouterType["history"], index: number) => ({
id: index, id: index,
title: load(v.title).text().trim(), title: load(v.title).text().trim(),

View File

@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "1"; const type = c.req.query("type") || "1";
const { fromCache, data, updateTime } = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "honkai", name: "honkai",
title: "崩坏3", title: "崩坏3",
@@ -21,10 +21,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://www.miyoushe.com/bh3/home/6", link: "https://www.miyoushe.com/bh3/home/6",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -35,8 +33,7 @@ const getList = async (options: Options, noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data.list; const list = result.data.data.list;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["miyoushe"]) => { data: list.map((v: RouterType["miyoushe"]) => {
const data = v.post; const data = v.post;
return { return {

View File

@@ -12,7 +12,7 @@ const typeMap: Record<string, string> = {
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "hot"; const type = c.req.query("type") || "hot";
const { fromCache, data, updateTime } = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "hostloc", name: "hostloc",
title: "全球主机交流", title: "全球主机交流",
@@ -24,10 +24,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://hostloc.com/", link: "https://hostloc.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -49,8 +47,7 @@ const getList = async (options: Options, noCache: boolean) => {
}; };
const list = await parseData(); const list = await parseData();
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v, i) => ({ data: list.map((v, i) => ({
id: v.guid || i, id: v.guid || i,
title: v.title || "", title: v.title || "",

View File

@@ -4,7 +4,7 @@ import { get } from "../utils/getData.js";
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "1"; const type = c.req.query("type") || "1";
const { fromCache, data, updateTime } = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "hupu", name: "hupu",
title: "虎扑", title: "虎扑",
@@ -22,10 +22,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://bbs.hupu.com/all-gambia", link: "https://bbs.hupu.com/all-gambia",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -36,8 +34,7 @@ const getList = async (options: Options, noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data.topicThreads; const list = result.data.data.topicThreads;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["hupu"]) => ({ data: list.map((v: RouterType["hupu"]) => ({
id: v.tid, id: v.tid,
title: v.title, title: v.title,

View File

@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "huxiu", name: "huxiu",
title: "虎嗅", title: "虎嗅",
type: "24小时", type: "24小时",
link: "https://www.huxiu.com/moment/", link: "https://www.huxiu.com/moment/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -38,8 +36,7 @@ const getList = async (noCache: boolean) => {
const matchResult = result.data.match(pattern); const matchResult = result.data.match(pattern);
const jsonObject = JSON.parse(matchResult[1]).moment.momentList.moment_list.datalist; const jsonObject = JSON.parse(matchResult[1]).moment.momentList.moment_list.datalist;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: jsonObject.map((v: RouterType["huxiu"]) => ({ data: jsonObject.map((v: RouterType["huxiu"]) => ({
id: v.object_id, id: v.object_id,
title: titleProcessing(v.content).title, title: titleProcessing(v.content).title,

View File

@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "ifanr", name: "ifanr",
title: "爱范儿", title: "爱范儿",
type: "快讯", type: "快讯",
description: "15秒了解全球新鲜事", description: "15秒了解全球新鲜事",
link: "https://www.ifanr.com/digest/", link: "https://www.ifanr.com/digest/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.objects; const list = result.data.objects;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["ifanr"]) => ({ data: list.map((v: RouterType["ifanr"]) => ({
id: v.id, id: v.id,
title: v.post_title, title: v.post_title,

View File

@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "ithome-xijiayi", name: "ithome-xijiayi",
title: "IT之家「喜加一」", title: "IT之家「喜加一」",
type: "最新动态", type: "最新动态",
description: "最新最全的「喜加一」游戏动态尽在这里!", description: "最新最全的「喜加一」游戏动态尽在这里!",
link: "https://www.ithome.com/zt/xijiayi", link: "https://www.ithome.com/zt/xijiayi",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -51,8 +49,7 @@ const getList = async (noCache: boolean) => {
}; };
}); });
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: listData, data: listData,
}; };
}; };

View File

@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "ithome", name: "ithome",
title: "IT之家", title: "IT之家",
type: "热榜", type: "热榜",
description: "爱科技,爱这里 - 前沿科技新闻网站", description: "爱科技,爱这里 - 前沿科技新闻网站",
link: "https://m.ithome.com/rankm/", link: "https://m.ithome.com/rankm/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -51,8 +49,7 @@ const getList = async (noCache: boolean) => {
}; };
}); });
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: listData, data: listData,
}; };
}; };

View File

@@ -3,17 +3,15 @@ import { load } from "cheerio";
import { get } from "../utils/getData.js"; import { get } from "../utils/getData.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "jianshu", name: "jianshu",
title: "简书", title: "简书",
type: "热门推荐", type: "热门推荐",
description: "一个优质的创作社区", description: "一个优质的创作社区",
link: "https://www.jianshu.com/", link: "https://www.jianshu.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -52,8 +50,7 @@ const getList = async (noCache: boolean) => {
}; };
}); });
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: listData, data: listData,
}; };
}; };

View File

@@ -3,16 +3,14 @@ import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js"; import { get } from "../utils/getData.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "juejin", name: "juejin",
title: "稀土掘金", title: "稀土掘金",
type: "文章榜", type: "文章榜",
link: "https://juejin.cn/hot/articles", link: "https://juejin.cn/hot/articles",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -22,8 +20,7 @@ const getList = async (noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data; const list = result.data.data;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["juejin"]) => ({ data: list.map((v: RouterType["juejin"]) => ({
id: v.content.content_id, id: v.content.content_id,
title: v.content.title, title: v.content.title,

View File

@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "lol", name: "lol",
title: "英雄联盟", title: "英雄联盟",
type: "更新公告", type: "更新公告",
link: "https://lol.qq.com/gicp/news/423/2/1334/1.html", link: "https://lol.qq.com/gicp/news/423/2/1334/1.html",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data.result; const list = result.data.data.result;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["lol"]) => ({ data: list.map((v: RouterType["lol"]) => ({
id: v.iDocID, id: v.iDocID,
title: v.sTitle, title: v.sTitle,

View File

@@ -25,7 +25,7 @@ const typeMap: Record<string, string> = {
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const game = c.req.query("game") || "1"; const game = c.req.query("game") || "1";
const type = c.req.query("type") || "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 = { const routeData: RouterData = {
name: "miyoushe", name: "miyoushe",
title: `米游社 · ${gameMap[game]}`, title: `米游社 · ${gameMap[game]}`,
@@ -41,10 +41,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://www.miyoushe.com/", link: "https://www.miyoushe.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -55,8 +53,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data.list; const list = result.data.data.list;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["miyoushe"]) => { data: list.map((v: RouterType["miyoushe"]) => {
const data = v.post; const data = v.post;
return { return {

View File

@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "netease-news", name: "netease-news",
title: "网易新闻", title: "网易新闻",
type: "热点榜", type: "热点榜",
link: "https://m.163.com/hot", link: "https://m.163.com/hot",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data.list; const list = result.data.data.list;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["netease-news"]) => ({ data: list.map((v: RouterType["netease-news"]) => ({
id: v.docid, id: v.docid,
title: v.title, title: v.title,

View File

@@ -4,17 +4,15 @@ import { post } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "ngabbs", name: "ngabbs",
title: "NGA", title: "NGA",
type: "论坛热帖", type: "论坛热帖",
description: "精英玩家俱乐部", description: "精英玩家俱乐部",
link: "https://ngabbs.com/", link: "https://ngabbs.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -42,8 +40,7 @@ const getList = async (noCache: boolean) => {
}); });
const list = result.data.result[0]; const list = result.data.result[0];
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["ngabbs"]) => ({ data: list.map((v: RouterType["ngabbs"]) => ({
id: v.tid, id: v.tid,
title: v.subject, title: v.subject,

View File

@@ -5,7 +5,7 @@ import { parseStringPromise } from "xml2js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "nodeseek", name: "nodeseek",
title: "NodeSeek", title: "NodeSeek",
@@ -19,10 +19,8 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
}, },
}, },
link: "https://www.nodeseek.com/", link: "https://www.nodeseek.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -33,8 +31,7 @@ const getList = async (noCache: boolean) => {
const rssData = await parseStringPromise(result.data); const rssData = await parseStringPromise(result.data);
const list = rssData.rss.channel[0].item; const list = rssData.rss.channel[0].item;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["nodeseek"]) => ({ data: list.map((v: RouterType["nodeseek"]) => ({
id: v.guid[0]._, id: v.guid[0]._,
title: v.title[0], title: v.title[0],

View File

@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "qq-news", name: "qq-news",
title: "腾讯新闻", title: "腾讯新闻",
type: "热点榜", type: "热点榜",
link: "https://news.qq.com/", link: "https://news.qq.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.idlist[0].newslist.slice(1); const list = result.data.idlist[0].newslist.slice(1);
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["qq-news"]) => ({ data: list.map((v: RouterType["qq-news"]) => ({
id: v.id, id: v.id,
title: v.title, title: v.title,

View File

@@ -64,7 +64,7 @@ const listType = {
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "1"; const type = c.req.query("type") || "1";
const { fromCache, data, updateTime } = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "sina-news", name: "sina-news",
title: "新浪新闻", title: "新浪新闻",
@@ -76,10 +76,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://sinanews.sina.cn/", link: "https://sinanews.sina.cn/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -122,8 +120,7 @@ const getList = async (options: Options, noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = parseData(result.data).data; const list = parseData(result.data).data;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["sina-news"]) => ({ data: list.map((v: RouterType["sina-news"]) => ({
id: v.id, id: v.id,
title: v.title, title: v.title,

View File

@@ -5,7 +5,7 @@ import { get } from "../utils/getData.js";
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "1"; const type = c.req.query("type") || "1";
const { fromCache, data, updateTime } = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "sina", name: "sina",
title: "新浪网", title: "新浪网",
@@ -28,10 +28,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://sinanews.sina.cn/", link: "https://sinanews.sina.cn/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -42,8 +40,7 @@ const getList = async (options: Options, noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data.hotList; const list = result.data.data.hotList;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["sina"]) => { data: list.map((v: RouterType["sina"]) => {
const base = v.base; const base = v.base;
const info = v.info; const info = v.info;

View File

@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "热门文章"; const type = c.req.query("type") || "热门文章";
const { fromCache, data, updateTime } = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "sspai", name: "sspai",
title: "少数派", title: "少数派",
@@ -17,10 +17,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://sspai.com/", link: "https://sspai.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -31,8 +29,7 @@ const getList = async (options: Options, noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data; const list = result.data.data;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["sspai"]) => ({ data: list.map((v: RouterType["sspai"]) => ({
id: v.id, id: v.id,
title: v.title, title: v.title,

View File

@@ -5,7 +5,7 @@ import { getTime } from "../utils/getTime.js";
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "1"; const type = c.req.query("type") || "1";
const { fromCache, data, updateTime } = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "starrail", name: "starrail",
title: "崩坏:星穹铁道", title: "崩坏:星穹铁道",
@@ -21,10 +21,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://www.miyoushe.com/sr/home/53", link: "https://www.miyoushe.com/sr/home/53",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -35,8 +33,7 @@ const getList = async (options: Options, noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data.list; const list = result.data.data.list;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["miyoushe"]) => { data: list.map((v: RouterType["miyoushe"]) => {
const data = v.post; const data = v.post;
return { return {

View File

@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "thepaper", name: "thepaper",
title: "澎湃新闻", title: "澎湃新闻",
type: "热榜", type: "热榜",
link: "https://www.thepaper.cn/", link: "https://www.thepaper.cn/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data.hotNews; const list = result.data.data.hotNews;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["thepaper"]) => ({ data: list.map((v: RouterType["thepaper"]) => ({
id: v.contId, id: v.contId,
title: v.name, title: v.name,

View File

@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "tieba", name: "tieba",
title: "百度贴吧", title: "百度贴吧",
type: "热议榜", type: "热议榜",
description: "全球领先的中文社区", description: "全球领先的中文社区",
link: "https://tieba.baidu.com/hottopic/browse/topicList", link: "https://tieba.baidu.com/hottopic/browse/topicList",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data.bang_topic.topic_list; const list = result.data.data.bang_topic.topic_list;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["tieba"]) => ({ data: list.map((v: RouterType["tieba"]) => ({
id: v.topic_id, id: v.topic_id,
title: v.topic_name, title: v.topic_name,

View File

@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "toutiao", name: "toutiao",
title: "今日头条", title: "今日头条",
type: "热榜", type: "热榜",
link: "https://www.toutiao.com/", link: "https://www.toutiao.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data; const list = result.data.data;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["toutiao"]) => ({ data: list.map((v: RouterType["toutiao"]) => ({
id: v.ClusterIdStr, id: v.ClusterIdStr,
title: v.Title, title: v.Title,

View File

@@ -4,7 +4,7 @@ import { get } from "../utils/getData.js";
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "hot"; const type = c.req.query("type") || "hot";
const { fromCache, data, updateTime } = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "v2ex", name: "v2ex",
title: "V2EX", title: "V2EX",
@@ -19,10 +19,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "https://www.v2ex.com/", link: "https://www.v2ex.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -33,8 +31,7 @@ const getList = async (options: Options, noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data; const list = result.data;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["v2ex"]) => ({ data: list.map((v: RouterType["v2ex"]) => ({
id: v.id, id: v.id,
title: v.title, title: v.title,

View File

@@ -5,11 +5,11 @@ import { getTime } from "../utils/getTime.js";
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const province = c.req.query("province") || ""; const province = c.req.query("province") || "";
const { fromCache, data, type, updateTime } = await getList({ province }, noCache); const listData = await getList({ province }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "weatheralarm", name: "weatheralarm",
title: "中央气象台", title: "中央气象台",
type: type || "全国气象预警", type: `${province || "全国"}气象预警`,
params: { params: {
province: { province: {
name: "预警区域", name: "预警区域",
@@ -17,10 +17,8 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
}, },
}, },
link: "http://nmc.cn/publish/alarm.html", link: "http://nmc.cn/publish/alarm.html",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -31,9 +29,7 @@ const getList = async (options: Options, noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data.page.list; const list = result.data.data.page.list;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
type: province + "气象预警",
data: list.map((v: RouterType["weatheralarm"]) => ({ data: list.map((v: RouterType["weatheralarm"]) => ({
id: v.alertid, id: v.alertid,
title: v.title, title: v.title,

View File

@@ -4,17 +4,15 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "weibo", name: "weibo",
title: "微博", title: "微博",
type: "热搜榜", type: "热搜榜",
description: "实时热点,每分钟更新一次", description: "实时热点,每分钟更新一次",
link: "https://s.weibo.com/top/summary/", link: "https://s.weibo.com/top/summary/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -24,8 +22,7 @@ const getList = async (noCache: boolean) => {
const result = await get({ url, noCache, ttl: 60 }); const result = await get({ url, noCache, ttl: 60 });
const list = result.data.data.realtime; const list = result.data.data.realtime;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["weibo"]) => { data: list.map((v: RouterType["weibo"]) => {
const key = v.word_scheme ? v.word_scheme : `#${v.word}`; const key = v.word_scheme ? v.word_scheme : `#${v.word}`;
return { return {

View File

@@ -5,16 +5,14 @@ import getWereadID from "../utils/getToken/weread.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "weread", name: "weread",
title: "微信读书", title: "微信读书",
type: "飙升榜", type: "飙升榜",
link: "https://weread.qq.com/", link: "https://weread.qq.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -31,8 +29,7 @@ const getList = async (noCache: boolean) => {
}); });
const list = result.data.books; const list = result.data.books;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["weread"]) => { data: list.map((v: RouterType["weread"]) => {
const data = v.bookInfo; const data = v.bookInfo;
return { return {

View File

@@ -3,17 +3,15 @@ import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js"; import { get } from "../utils/getData.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "zhihu-daily", name: "zhihu-daily",
title: "知乎日报", title: "知乎日报",
type: "推荐榜", type: "推荐榜",
description: "每天三次,每次七分钟", description: "每天三次,每次七分钟",
link: "https://daily.zhihu.com/", link: "https://daily.zhihu.com/",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -30,8 +28,7 @@ const getList = async (noCache: boolean) => {
}); });
const list = result.data.stories.filter((el: RouterType["zhihu-daily"]) => el.type === 0); const list = result.data.stories.filter((el: RouterType["zhihu-daily"]) => el.type === 0);
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["zhihu-daily"]) => ({ data: list.map((v: RouterType["zhihu-daily"]) => ({
id: v.id, id: v.id,
title: v.title, title: v.title,

View File

@@ -4,16 +4,14 @@ import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js"; import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => { export const handleRoute = async (_: undefined, noCache: boolean) => {
const { fromCache, data, updateTime } = await getList(noCache); const listData = await getList(noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "zhihu", name: "zhihu",
title: "知乎", title: "知乎",
type: "热榜", type: "热榜",
link: "https://www.zhihu.com/hot", link: "https://www.zhihu.com/hot",
total: data?.length || 0, total: listData.data?.length || 0,
updateTime, ...listData,
fromCache,
data,
}; };
return routeData; return routeData;
}; };
@@ -23,8 +21,7 @@ const getList = async (noCache: boolean) => {
const result = await get({ url, noCache }); const result = await get({ url, noCache });
const list = result.data.data; const list = result.data.data;
return { return {
fromCache: result.fromCache, ...result,
updateTime: result.updateTime,
data: list.map((v: RouterType["zhihu"]) => { data: list.map((v: RouterType["zhihu"]) => {
const data = v.target; const data = v.target;
return { return {

3
src/types.d.ts vendored
View File

@@ -18,9 +18,10 @@ export interface ListItem {
// 路由接口数据 // 路由接口数据
export interface RouterResType { export interface RouterResType {
updateTime: string; updateTime: string | number;
fromCache: boolean; fromCache: boolean;
data: ListItem[]; data: ListItem[];
message?: string;
} }
// 路由数据 // 路由数据

View File

@@ -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 { config } from "../config.js";
import { getCache, setCache, delCache } from "./cache.js"; import { getCache, setCache, delCache } from "./cache.js";
import { Cluster } from "puppeteer-cluster"; import { Cluster } from "puppeteer-cluster";
@@ -12,24 +13,50 @@ const request = axios.create({
withCredentials: true, withCredentials: true,
}); });
// puppeteer-cluster // Puppeteer Cluster
export const createCluster = async () => { let cluster: Cluster | null = null;
return await Cluster.launch({
concurrency: Cluster.CONCURRENCY_BROWSER, /**
maxConcurrency: 5, * 创建 Puppeteer Cluster
// puppeteer * @returns {Promise<Cluster|null>} Puppeteer Cluster
puppeteerOptions: { */
headless: true, export const createCluster = async (): Promise<Cluster | null> => {
args: ["--no-sandbox", "--disable-setuid-sandbox"], 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(); * 处理任务
* @param page 页面
// Cluster configuration * @param data 数据
cluster.task(async ({ page, data: { url, userAgent } }) => { * @returns
*/
const taskHandler = async ({
page,
data: { url, userAgent },
}: {
page: Page;
data: { url: string; userAgent?: string };
}): Promise<string> => {
// 用户代理 // 用户代理
if (userAgent) await page.setUserAgent(userAgent); 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 }); await page.goto(url, { waitUntil: "networkidle0", timeout: config.REQUEST_TIMEOUT });
const pageContent = await page.content(); // 返回页面内容
return pageContent; return page.content();
}); };
// 请求拦截 // 请求拦截
request.interceptors.request.use( request.interceptors.request.use(
@@ -137,12 +164,25 @@ export const post = async (options: Post) => {
} }
}; };
// puppeteer // WEB - Puppeteer
export const web = async (options: Web) => { export const web = async (options: Web) => {
const { url, noCache, ttl = config.CACHE_TTL, userAgent } = options; const { url, noCache, ttl = config.CACHE_TTL, userAgent } = options;
logger.info("使用 Puppeteer 发起页面请求", 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 { try {
if (!cluster) throw new Error("Cluster is not initialized");
// 检查缓存 // 检查缓存
if (noCache) { if (noCache) {
delCache(url); delCache(url);
@@ -155,7 +195,7 @@ export const web = async (options: Web) => {
} }
// 缓存不存在时使用 Puppeteer 请求页面 // 缓存不存在时使用 Puppeteer 请求页面
logger.info("启动浏览器请求页面", { url }); logger.info("启动浏览器请求页面", { url });
const pageContent = await cluster.execute({ url, userAgent }); const pageContent = await clusterInstance.execute({ url, userAgent }, taskHandler);
// 存储新获取的数据到缓存 // 存储新获取的数据到缓存
const updateTime = new Date().toISOString(); const updateTime = new Date().toISOString();
setCache(url, { data: pageContent, updateTime }, ttl); setCache(url, { data: pageContent, updateTime }, ttl);
@@ -167,3 +207,17 @@ export const web = async (options: Web) => {
throw error; throw error;
} }
}; };
/**
* 关闭 Cluster
*/
export const closeCluster = async () => {
if (cluster) {
try {
await cluster.close();
logger.info("Puppeteer Cluster 已成功关闭");
} catch (error) {
logger.error("关闭 Puppeteer Cluster 时出错", error);
}
}
};

View File

@@ -25,8 +25,8 @@ export const parseRSS = async (rssContent: string) => {
try { try {
new URL(url); new URL(url);
return true; return true;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) { } catch (error) {
console.error(error);
return false; return false;
} }
}; };