mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 21:24:55 +08:00
Compare commits
74 Commits
v2.0.0-rc.
...
v2.0.8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
755d4e22c1 | ||
|
|
72d6d970e1 | ||
|
|
150a3d9c1e | ||
|
|
259dd2c270 | ||
|
|
dad7e442da | ||
|
|
d5581815f4 | ||
|
|
c6a8c13772 | ||
|
|
46cb5ccec2 | ||
|
|
41aeba290a | ||
|
|
20a5b537f9 | ||
|
|
2ed851bdc2 | ||
|
|
dddcb27487 | ||
|
|
410d88860d | ||
|
|
22a14dd64e | ||
|
|
26f10d0c6a | ||
|
|
2a6f4db768 | ||
|
|
94ba2478d1 | ||
|
|
ec190229cc | ||
|
|
6ce0f7d8b0 | ||
|
|
2c9526b7c9 | ||
|
|
212b58ada9 | ||
|
|
16b9ad25d3 | ||
|
|
be9db7c625 | ||
|
|
e2bee69738 | ||
|
|
b033e7574c | ||
|
|
484b73c083 | ||
|
|
0fa3108b92 | ||
|
|
c1b21f1964 | ||
|
|
b31d4f59a2 | ||
|
|
38f3f38403 | ||
|
|
c9ee406372 | ||
|
|
bd507f9938 | ||
|
|
a05578f0f4 | ||
|
|
489723985b | ||
|
|
51f27af0d6 | ||
|
|
161b6b612b | ||
|
|
f38d264366 | ||
|
|
0cce0d6067 | ||
|
|
098b80865b | ||
|
|
afb7c7d515 | ||
|
|
7b610ef8cd | ||
|
|
d27ef0d116 | ||
|
|
d0dfba27dc | ||
|
|
293c4d623e | ||
|
|
097a1b3628 | ||
|
|
ec50d5ced1 | ||
|
|
c713d34ba1 | ||
|
|
c4772962f4 | ||
|
|
36802252c0 | ||
|
|
7f5449089d | ||
|
|
53c68a3d69 | ||
|
|
447e0c6153 | ||
|
|
55f4e22693 | ||
|
|
c791e29a59 | ||
|
|
91775a0763 | ||
|
|
a742f9df78 | ||
|
|
f213d9810b | ||
|
|
250a90cf2e | ||
|
|
a4a1055604 | ||
|
|
fd3d911b04 | ||
|
|
bf80a2e22c | ||
|
|
6988df58f1 | ||
|
|
bcff976a4d | ||
|
|
62a8880ae4 | ||
|
|
e6f89c4868 | ||
|
|
fa80a29772 | ||
|
|
b8f7c1ad23 | ||
|
|
d5217c3dff | ||
|
|
e1beb5b534 | ||
|
|
14bc5a1dce | ||
|
|
11addd20ca | ||
|
|
23375519ba | ||
|
|
2ba46c5e0e | ||
|
|
d4a52a6b24 |
20
.env
20
.env
@@ -1,20 +0,0 @@
|
|||||||
# 服务端口
|
|
||||||
PORT = 6688
|
|
||||||
|
|
||||||
# 允许的域名
|
|
||||||
ALLOWED_DOMAIN = "*"
|
|
||||||
|
|
||||||
# ROBOT
|
|
||||||
DISALLOW_ROBOT = true
|
|
||||||
|
|
||||||
# 缓存时长( 秒 )
|
|
||||||
CACHE_TTL = 3600
|
|
||||||
|
|
||||||
# 请求超时( 毫秒 )
|
|
||||||
REQUEST_TIMEOUT = 6000
|
|
||||||
|
|
||||||
# 是否输出日志
|
|
||||||
USE_LOG_FILE = true
|
|
||||||
|
|
||||||
# RSS Mode
|
|
||||||
RSS_MODE = false
|
|
||||||
29
.env.example
Normal file
29
.env.example
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# 服务端口
|
||||||
|
PORT=6688
|
||||||
|
|
||||||
|
# 允许的域名
|
||||||
|
ALLOWED_DOMAIN="*"
|
||||||
|
|
||||||
|
# 允许的主域名,填写格式为 imsyy.top
|
||||||
|
## 若填写该项,将忽略 ALLOWED_DOMAIN
|
||||||
|
ALLOWED_HOST=""
|
||||||
|
|
||||||
|
# ROBOT
|
||||||
|
DISALLOW_ROBOT=true
|
||||||
|
|
||||||
|
# Redis
|
||||||
|
REDIS_HOST="127.0.0.1"
|
||||||
|
REDIS_PORT=6379
|
||||||
|
REDIS_PASSWORD=""
|
||||||
|
|
||||||
|
# 缓存时长( 秒 )
|
||||||
|
CACHE_TTL=3600
|
||||||
|
|
||||||
|
# 请求超时( 毫秒 )
|
||||||
|
REQUEST_TIMEOUT=6000
|
||||||
|
|
||||||
|
# 是否输出日志
|
||||||
|
USE_LOG_FILE=true
|
||||||
|
|
||||||
|
# RSS Mode
|
||||||
|
RSS_MODE=false
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
.vscode
|
|
||||||
docker-compose.yml
|
|
||||||
dist
|
|
||||||
logs
|
|
||||||
!/.github
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"env": {
|
|
||||||
"browser": true,
|
|
||||||
"es2021": true
|
|
||||||
},
|
|
||||||
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
|
|
||||||
"parser": "@typescript-eslint/parser",
|
|
||||||
"parserOptions": {
|
|
||||||
"ecmaVersion": "latest",
|
|
||||||
"sourceType": "module"
|
|
||||||
},
|
|
||||||
"plugins": ["@typescript-eslint"],
|
|
||||||
"rules": {}
|
|
||||||
}
|
|
||||||
14
.github/workflows/docker.yml
vendored
14
.github/workflows/docker.yml
vendored
@@ -3,9 +3,10 @@ name: Publish Docker image
|
|||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [published]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
push_to_registry:
|
build-docker:
|
||||||
name: Push Docker image to multiple registries
|
name: Push Docker image to multiple registries
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
@@ -15,6 +16,12 @@ jobs:
|
|||||||
- name: Check out the repo
|
- name: Check out the repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Log in to Docker Hub
|
- name: Log in to Docker Hub
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
@@ -36,11 +43,14 @@ jobs:
|
|||||||
imsyy/dailyhot-api
|
imsyy/dailyhot-api
|
||||||
ghcr.io/${{ github.repository }}
|
ghcr.io/${{ github.repository }}
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push regular image
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
|
platforms: |
|
||||||
|
linux/amd64
|
||||||
|
linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|||||||
3
.github/workflows/npm.yml
vendored
3
.github/workflows/npm.yml
vendored
@@ -6,8 +6,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-npm:
|
publish-npm:
|
||||||
runs-on:
|
runs-on: ubuntu-latest
|
||||||
ubuntu-latest
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [20]
|
node-version: [20]
|
||||||
|
|||||||
8
.gitignore
vendored
8
.gitignore
vendored
@@ -11,6 +11,7 @@ node_modules
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
dist
|
dist
|
||||||
*.local
|
*.local
|
||||||
|
.env
|
||||||
|
|
||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
.vscode/*
|
.vscode/*
|
||||||
@@ -20,4 +21,9 @@ dist
|
|||||||
*.ntvs*
|
*.ntvs*
|
||||||
*.njsproj
|
*.njsproj
|
||||||
*.sln
|
*.sln
|
||||||
*.sw?
|
*.sw?
|
||||||
|
|
||||||
|
package-lock.json
|
||||||
|
# Sentry Config File
|
||||||
|
.env.sentry-build-plugin
|
||||||
|
.nvmrc
|
||||||
|
|||||||
13
.prettierrc.js
Normal file
13
.prettierrc.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
export default {
|
||||||
|
// see https://prettier.io/docs/en/options.html
|
||||||
|
// 优先使用单引号
|
||||||
|
singleQuote: false,
|
||||||
|
// 尾随逗号
|
||||||
|
trailingComma: "all",
|
||||||
|
// 缩进空格数
|
||||||
|
tabWidth: 2,
|
||||||
|
// 使用分号
|
||||||
|
semi: true,
|
||||||
|
// 换行符
|
||||||
|
printWidth: 100,
|
||||||
|
};
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://json.schemastore.org/prettierrc",
|
|
||||||
"singleQuote": false,
|
|
||||||
"trailingComma": "all",
|
|
||||||
"tabWidth": 2,
|
|
||||||
"semi": true,
|
|
||||||
"printWidth": 100
|
|
||||||
}
|
|
||||||
22
Dockerfile
22
Dockerfile
@@ -1,21 +1,30 @@
|
|||||||
FROM node:20-alpine AS base
|
FROM node:20-alpine AS base
|
||||||
|
|
||||||
|
ENV NODE_ENV=docker
|
||||||
|
|
||||||
|
# 清理缓存
|
||||||
|
RUN rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
|
# 构建阶段
|
||||||
FROM base AS builder
|
FROM base AS builder
|
||||||
|
|
||||||
RUN apk add --no-cache libc6-compat
|
|
||||||
RUN npm install -g pnpm
|
RUN npm install -g pnpm
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY package*json tsconfig.json pnpm-lock.yaml .env ./
|
COPY package*json tsconfig.json pnpm-lock.yaml .env.example ./
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
COPY public ./public
|
COPY public ./public
|
||||||
|
|
||||||
RUN pnpm install && \
|
# 复制环境变量
|
||||||
pnpm build && \
|
RUN [ ! -e ".env" ] && cp .env.example .env || true
|
||||||
pnpm prune --production
|
|
||||||
|
|
||||||
|
# 安装依赖
|
||||||
|
RUN pnpm install
|
||||||
|
RUN pnpm build
|
||||||
|
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
|
||||||
@@ -23,6 +32,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
|
||||||
|
|||||||
130
README.md
130
README.md
@@ -2,6 +2,12 @@
|
|||||||
<img alt="logo" height="120" src="./public/favicon.png" width="120"/>
|
<img alt="logo" height="120" src="./public/favicon.png" width="120"/>
|
||||||
<h2>今日热榜</h2>
|
<h2>今日热榜</h2>
|
||||||
<p>一个聚合热门数据的 API 接口</p>
|
<p>一个聚合热门数据的 API 接口</p>
|
||||||
|
<br />
|
||||||
|
<img src="https://img.shields.io/github/last-commit/imsyy/DailyHotApi" alt="last commit"/>
|
||||||
|
<img src="https://img.shields.io/github/languages/code-size/imsyy/DailyHotApi" alt="code size"/>
|
||||||
|
<img src="https://img.shields.io/docker/image-size/imsyy/dailyhot-api" alt="docker-image-size"/>
|
||||||
|
<img src="https://github.com/imsyy/DailyHotApi/actions/workflows/docker.yml/badge.svg" alt="Publish Docker image"/>
|
||||||
|
<img src="https://github.com/imsyy/DailyHotApi/actions/workflows/npm.yml/badge.svg" alt="Publish npm package"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
## 🚩 特性
|
## 🚩 特性
|
||||||
@@ -19,52 +25,69 @@
|
|||||||
|
|
||||||
- [今日热榜 - https://hot.imsyy.top/](https://hot.imsyy.top/)
|
- [今日热榜 - https://hot.imsyy.top/](https://hot.imsyy.top/)
|
||||||
|
|
||||||
## 🎉 总览
|
## 📊 接口总览
|
||||||
|
|
||||||
> 🟢 状态正常 / 🟠 可能失效 / ❌ 无法使用 / ⚠️ 需要科学上网
|
<details>
|
||||||
|
<summary>查看全部接口</summary>
|
||||||
|
|
||||||
| **站点** | **类别** | **调用名称** | **状态** |
|
> 示例站点运行于海外服务器,部分国内站点可能存在访问异常,请以实际情况为准
|
||||||
| ---------------- | ------------ | -------------- | -------- |
|
|
||||||
| 哔哩哔哩 | 热门榜 | bilibili | 🟢 |
|
| **站点** | **类别** | **调用名称** | **状态** |
|
||||||
| AcFun | 排行榜 | acfun | 🟢 |
|
| ---------------- | ------------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| 微博 | 热搜榜 | weibo | 🟢 |
|
| 哔哩哔哩 | 热门榜 | bilibili |  |
|
||||||
| 知乎 | 热榜 | zhihu | 🟢 |
|
| AcFun | 排行榜 | acfun |  |
|
||||||
| 知乎日报 | 推荐榜 | zhihu-daily | 🟢 |
|
| 微博 | 热搜榜 | weibo |  |
|
||||||
| 百度 | 热搜榜 | baidu | 🟢 |
|
| 知乎 | 热榜 | zhihu |  |
|
||||||
| 抖音 | 热点榜 | douyin | 🟢 |
|
| 知乎日报 | 推荐榜 | zhihu-daily |  |
|
||||||
| 豆瓣电影 | 新片榜 | douban-movie | 🟢 |
|
| 百度 | 热搜榜 | baidu |  |
|
||||||
| 豆瓣讨论小组 | 讨论精选 | douban-group | 🟢 |
|
| 抖音 | 热点榜 | douyin |  |
|
||||||
| 百度贴吧 | 热议榜 | tieba | 🟢 |
|
| 快手 | 热点榜 | kuaishou |  |
|
||||||
| 少数派 | 热榜 | sspai | 🟢 |
|
| 豆瓣电影 | 新片榜 | douban-movie |  |
|
||||||
| IT之家 | 热榜 | ithome | 🟠 |
|
| 豆瓣讨论小组 | 讨论精选 | douban-group |  |
|
||||||
| IT之家「喜加一」 | 最新动态 | ithome-xijiayi | 🟠 |
|
| 百度贴吧 | 热议榜 | tieba |  |
|
||||||
| 简书 | 热门推荐 | jianshu | 🟠 |
|
| 少数派 | 热榜 | sspai |  |
|
||||||
| 澎湃新闻 | 热榜 | thepaper | 🟢 |
|
| IT之家 | 热榜 | ithome |  |
|
||||||
| 今日头条 | 热榜 | toutiao | 🟢 |
|
| IT之家「喜加一」 | 最新动态 | ithome-xijiayi |  |
|
||||||
| 36 氪 | 热榜 | 36kr | 🟢 |
|
| 简书 | 热门推荐 | jianshu |  |
|
||||||
| 51CTO | 推荐榜 | 51cto | 🟢 |
|
| 果壳 | 热门文章 | guokr |  |
|
||||||
| 稀土掘金 | 热榜 | juejin | 🟢 |
|
| 澎湃新闻 | 热榜 | thepaper |  |
|
||||||
| 腾讯新闻 | 热点榜 | qq-news | 🟢 |
|
| 今日头条 | 热榜 | toutiao |  |
|
||||||
| 网易新闻 | 热点榜 | netease-news | 🟢 |
|
| 36 氪 | 热榜 | 36kr |  |
|
||||||
| 吾爱破解 | 榜单 | 52pojie | 🟢 |
|
| 51CTO | 推荐榜 | 51cto |  |
|
||||||
| 全球主机交流 | 榜单 | hostloc | 🟢 |
|
| CSDN | 排行榜 | csdn |  |
|
||||||
| 虎嗅 | 24小时 | huxiu | 🟢 |
|
| NodeSeek | 最新动态 | nodeseek |  |
|
||||||
| 爱范儿 | 快讯 | ifanr | 🟢 |
|
| 稀土掘金 | 热榜 | juejin |  |
|
||||||
| 英雄联盟 | 更新公告 | lol | 🟢 |
|
| 腾讯新闻 | 热点榜 | qq-news |  |
|
||||||
| 原神 | 最新消息 | genshin | 🟢 |
|
| 新浪网 | 热榜 | sina |  |
|
||||||
| 崩坏3 | 最新动态 | honkai | 🟢 |
|
| 新浪新闻 | 热点榜 | sina-news |  |
|
||||||
| 崩坏:星穹铁道 | 最新动态 | starrail | 🟢 |
|
| 网易新闻 | 热点榜 | netease-news |  |
|
||||||
| 微信读书 | 飙升榜 | weread | 🟢 |
|
| 吾爱破解 | 榜单 | 52pojie |  |
|
||||||
| NGA | 热帖 | ngabbs | 🟢 |
|
| 全球主机交流 | 榜单 | hostloc |  |
|
||||||
| V2EX | 主题榜 | v2ex | ⚠️ |
|
| 虎嗅 | 24小时 | huxiu |  |
|
||||||
| HelloGitHub | Trending | hellogithub | 🟢 |
|
| 酷安 | 热榜 | coolapk |  |
|
||||||
| 中央气象台 | 全国气象预警 | weatheralarm | 🟢 |
|
| 虎扑 | 步行街热帖 | hupu |  |
|
||||||
| 中国地震台 | 地震速报 | earthquake | 🟢 |
|
| 爱范儿 | 快讯 | ifanr |  |
|
||||||
|
| 英雄联盟 | 更新公告 | lol |  |
|
||||||
|
| 米游社 | 最新消息 | miyoushe |  |
|
||||||
|
| 原神 | 最新消息 | genshin |  |
|
||||||
|
| 崩坏3 | 最新动态 | honkai |  |
|
||||||
|
| 崩坏:星穹铁道 | 最新动态 | starrail |  |
|
||||||
|
| 微信读书 | 飙升榜 | weread |  |
|
||||||
|
| NGA | 热帖 | ngabbs |  |
|
||||||
|
| V2EX | 主题榜 | v2ex |  |
|
||||||
|
| HelloGitHub | Trending | hellogithub |  |
|
||||||
|
| 中央气象台 | 全国气象预警 | weatheralarm |  |
|
||||||
|
| 中国地震台 | 地震速报 | earthquake |  |
|
||||||
|
| 历史上的今天 | 月-日 | history |  |
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
## ⚙️ 使用
|
## ⚙️ 使用
|
||||||
|
|
||||||
本项目支持 `Node.js` 调用,可在安装完成后调用 `serveHotApi` 来开启服务器
|
本项目支持 `Node.js` 调用,可在安装完成后调用 `serveHotApi` 来开启服务器
|
||||||
|
|
||||||
|
> 该方式无法使用部分需要 Puppeteer 环境的接口
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm add dailyhot-api
|
pnpm add dailyhot-api
|
||||||
```
|
```
|
||||||
@@ -93,8 +116,9 @@ serveHotApi(3000);
|
|||||||
```bash
|
```bash
|
||||||
# 构建
|
# 构建
|
||||||
docker build -t dailyhot-api .
|
docker build -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
|
||||||
```
|
```
|
||||||
@@ -104,13 +128,14 @@ docker-compose up -d
|
|||||||
```bash
|
```bash
|
||||||
# 拉取
|
# 拉取
|
||||||
docker pull imsyy/dailyhot-api:latest
|
docker pull imsyy/dailyhot-api:latest
|
||||||
|
|
||||||
# 运行
|
# 运行
|
||||||
docker run -p 6688:6688 -d imsyy/dailyhot-api:latest
|
docker run --restart always -p 6688:6688 -d imsyy/dailyhot-api:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
### 手动部署
|
### 手动部署
|
||||||
|
|
||||||
最直接的方式,您可以按照以下步骤将 DailyHotApi 部署在您的电脑、服务器或者其他任何地方
|
最直接的方式,您可以按照以下步骤将 `DailyHotApi` 部署在您的电脑、服务器或者其他任何地方
|
||||||
|
|
||||||
#### 安装
|
#### 安装
|
||||||
|
|
||||||
@@ -125,6 +150,8 @@ cd DailyHotApi
|
|||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
复制 `/.env.example` 文件并重命名为 `/.env` 并修改配置
|
||||||
|
|
||||||
#### 开发
|
#### 开发
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -140,8 +167,21 @@ npm run build
|
|||||||
npm run start
|
npm run start
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### pm2 部署
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm i pm2 -g
|
||||||
|
sh ./deploy.sh
|
||||||
|
```
|
||||||
|
|
||||||
成功启动后程序会在控制台输出可访问的地址
|
成功启动后程序会在控制台输出可访问的地址
|
||||||
|
|
||||||
|
### Vercel 部署
|
||||||
|
|
||||||
|
本项目支持通过 `Vercel` 进行一键部署,点击下方按钮或前往 [项目仓库](https://github.com/imsyy/DailyHotApi-Vercel) 进行手动部署
|
||||||
|
|
||||||
|
[](https://vercel.com/new/imsyys-projects/clone?repository-url=https%3A%2F%2Fgithub.com%2Fimsyy%2FDailyHotApi-Vercel)
|
||||||
|
|
||||||
### Railway 部署
|
### Railway 部署
|
||||||
|
|
||||||
本项目支持使用 [Railway](https://railway.app/) 一键部署,请先将本项目 fork 到您的仓库中,即可使用一键部署。
|
本项目支持使用 [Railway](https://railway.app/) 一键部署,请先将本项目 fork 到您的仓库中,即可使用一键部署。
|
||||||
@@ -150,12 +190,6 @@ npm run start
|
|||||||
|
|
||||||
本项目支持使用 [Zeabur](https://zeabur.com/) 一键部署,请先将本项目 fork 到您的仓库中,即可使用一键部署。
|
本项目支持使用 [Zeabur](https://zeabur.com/) 一键部署,请先将本项目 fork 到您的仓库中,即可使用一键部署。
|
||||||
|
|
||||||
### Vercel 部署
|
|
||||||
|
|
||||||
> 🚧 Vercel 部署支持正在修复中
|
|
||||||
|
|
||||||
若您目前仅能通过 `Vercel` 进行部署,那么请暂时不要使用最新版本
|
|
||||||
|
|
||||||
## ⚠️ 须知
|
## ⚠️ 须知
|
||||||
|
|
||||||
- 本项目为了避免频繁请求官方数据,默认对数据做了缓存处理,默认为 `60` 分钟,如需更改,请自行修改配置
|
- 本项目为了避免频繁请求官方数据,默认对数据做了缓存处理,默认为 `60` 分钟,如需更改,请自行修改配置
|
||||||
|
|||||||
35
deploy.sh
Normal file
35
deploy.sh
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 日志文件
|
||||||
|
LOG_FILE="deploy.log"
|
||||||
|
|
||||||
|
# 输出时间戳的日志函数
|
||||||
|
log() {
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a $LOG_FILE
|
||||||
|
}
|
||||||
|
|
||||||
|
# 错误处理函数
|
||||||
|
handle_error() {
|
||||||
|
log "错误: $1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# 开始拉去代码
|
||||||
|
log "开始拉取代码..."
|
||||||
|
git pull
|
||||||
|
# 开始部署
|
||||||
|
log "开始部署..."
|
||||||
|
|
||||||
|
# 安装依赖
|
||||||
|
log "正在安装依赖..."
|
||||||
|
npm install || handle_error "npm install 失败"
|
||||||
|
|
||||||
|
# 构建项目
|
||||||
|
log "正在构建项目..."
|
||||||
|
npm run build || handle_error "构建失败"
|
||||||
|
|
||||||
|
# 使用 pm2 重启或启动项目
|
||||||
|
log "正在启动/重启服务..."
|
||||||
|
pm2 restart daily-news || pm2 start ecosystem.config.cjs || handle_error "PM2 启动失败"
|
||||||
|
|
||||||
|
log "部署完成!"
|
||||||
15
ecosystem.config.cjs
Normal file
15
ecosystem.config.cjs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
module.exports = {
|
||||||
|
apps: [{
|
||||||
|
name: 'daily-news',
|
||||||
|
script: 'npm',
|
||||||
|
args: 'start',
|
||||||
|
instances: 1,
|
||||||
|
autorestart: true,
|
||||||
|
watch: false,
|
||||||
|
max_memory_restart: '1G',
|
||||||
|
env: {
|
||||||
|
NODE_ENV: 'development',
|
||||||
|
PORT: 6688
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
14
eslint.config.js
Normal file
14
eslint.config.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import globals from "globals";
|
||||||
|
import pluginJs from "@eslint/js";
|
||||||
|
import tseslint from "typescript-eslint";
|
||||||
|
|
||||||
|
/** @type {import('eslint').Linter.Config[]} */
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
ignores: ["**/node_modules", "**/dist", "**/.gitignore", "**/logs", "**/docker-compose.yml"],
|
||||||
|
},
|
||||||
|
{ files: ["**/*.{js,mjs,cjs,ts}"] },
|
||||||
|
{ languageOptions: { globals: globals.node } },
|
||||||
|
pluginJs.configs.recommended,
|
||||||
|
...tseslint.configs.recommended,
|
||||||
|
];
|
||||||
62
package.json
62
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dailyhot-api",
|
"name": "dailyhot-api",
|
||||||
"version": "2.0.0-rc.4",
|
"version": "2.0.8",
|
||||||
"description": "An Api on Today's Hot list",
|
"description": "An Api on Today's Hot list",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"API",
|
"API",
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "imsyy",
|
"author": "imsyy",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/types.js",
|
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"declarationMap": true,
|
"declarationMap": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
@@ -25,43 +24,58 @@
|
|||||||
"LICENSE",
|
"LICENSE",
|
||||||
"README.md",
|
"README.md",
|
||||||
"dist/**/*",
|
"dist/**/*",
|
||||||
"src/types.d.ts",
|
|
||||||
"!dist/logs/**/*"
|
"!dist/logs/**/*"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts,.vue --fix",
|
"lint": "eslint .",
|
||||||
"dev": "tsx watch --no-cache src/index.ts",
|
"dev": "cross-env NODE_ENV=development tsx watch --no-cache src/index.ts",
|
||||||
"dev:cache": "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": "tsx src/index.ts"
|
"start": "cross-env NODE_ENV=development node dist/index.js"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hono/node-server": "^1.11.2",
|
"@hono/node-server": "^1.17.1",
|
||||||
"axios": "^1.7.2",
|
"axios": "^1.11.0",
|
||||||
"cheerio": "1.0.0-rc.12",
|
"chalk": "^5.4.1",
|
||||||
"dayjs": "^1.11.11",
|
"cheerio": "^1.1.2",
|
||||||
"dotenv": "^16.4.5",
|
"dayjs": "^1.11.13",
|
||||||
"feed": "^4.2.2",
|
"dotenv": "^17.2.1",
|
||||||
"hono": "^4.4.3",
|
"feed": "^5.1.0",
|
||||||
|
"flatted": "^3.3.3",
|
||||||
|
"hono": "^4.8.9",
|
||||||
|
"iconv-lite": "^0.6.3",
|
||||||
|
"ioredis": "^5.6.1",
|
||||||
"md5": "^2.3.0",
|
"md5": "^2.3.0",
|
||||||
"node-cache": "^5.1.2",
|
"node-cache": "^5.1.2",
|
||||||
"puppeteer": "^22.10.0",
|
"node-fetch": "^3.3.2",
|
||||||
"puppeteer-cluster": "^0.24.0",
|
|
||||||
"rss-parser": "^3.13.0",
|
"rss-parser": "^3.13.0",
|
||||||
"winston": "^3.13.0"
|
"user-agents": "^1.1.614",
|
||||||
|
"winston": "^3.17.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.14.1",
|
"@eslint/js": "^9.32.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.12.0",
|
"@types/md5": "^2.3.5",
|
||||||
"@typescript-eslint/parser": "^7.12.0",
|
"@types/node": "^22.16.5",
|
||||||
"eslint": "^8.57.0",
|
"@types/user-agents": "^1.0.4",
|
||||||
"prettier": "^3.3.0",
|
"@types/xml2js": "^0.4.14",
|
||||||
"tsx": "^3.14.0",
|
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
||||||
"typescript": "^5.4.5"
|
"@typescript-eslint/parser": "^8.38.0",
|
||||||
|
"cross-env": "^7.0.3",
|
||||||
|
"eslint": "^9.32.0",
|
||||||
|
"globals": "^16.3.0",
|
||||||
|
"prettier": "^3.6.2",
|
||||||
|
"tsx": "^4.20.3",
|
||||||
|
"typescript": "^5.8.3",
|
||||||
|
"typescript-eslint": "^8.38.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20"
|
"node": ">=20"
|
||||||
|
},
|
||||||
|
"pnpm": {
|
||||||
|
"onlyBuiltDependencies": [
|
||||||
|
"esbuild"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2359
pnpm-lock.yaml
generated
2359
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 5.2 KiB |
@@ -28,7 +28,11 @@ app.use(
|
|||||||
"*",
|
"*",
|
||||||
cors({
|
cors({
|
||||||
// 可写为数组
|
// 可写为数组
|
||||||
origin: config.ALLOWED_DOMAIN,
|
origin: (origin) => {
|
||||||
|
// 是否指定域名
|
||||||
|
const isSame = config.ALLOWED_HOST && origin.endsWith(config.ALLOWED_HOST);
|
||||||
|
return isSame ? origin : config.ALLOWED_DOMAIN;
|
||||||
|
},
|
||||||
allowMethods: ["POST", "GET", "OPTIONS"],
|
allowMethods: ["POST", "GET", "OPTIONS"],
|
||||||
allowHeaders: ["X-Custom-Header", "Upgrade-Insecure-Requests"],
|
allowHeaders: ["X-Custom-Header", "Upgrade-Insecure-Requests"],
|
||||||
credentials: true,
|
credentials: true,
|
||||||
@@ -55,7 +59,7 @@ app.get("/", (c) => c.html(<Home />));
|
|||||||
app.notFound((c) => c.html(<NotFound />, 404));
|
app.notFound((c) => c.html(<NotFound />, 404));
|
||||||
// error
|
// error
|
||||||
app.onError((err, c) => {
|
app.onError((err, c) => {
|
||||||
logger.error(`出现致命错误:${err}`);
|
logger.error(`❌ [ERROR] ${err?.message}`);
|
||||||
return c.html(<Error error={err?.message} />, 500);
|
return c.html(<Error error={err?.message} />, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -9,16 +9,19 @@ export type Config = {
|
|||||||
CACHE_TTL: number;
|
CACHE_TTL: number;
|
||||||
REQUEST_TIMEOUT: number;
|
REQUEST_TIMEOUT: number;
|
||||||
ALLOWED_DOMAIN: string;
|
ALLOWED_DOMAIN: string;
|
||||||
|
ALLOWED_HOST: string;
|
||||||
USE_LOG_FILE: boolean;
|
USE_LOG_FILE: boolean;
|
||||||
RSS_MODE: boolean;
|
RSS_MODE: boolean;
|
||||||
|
REDIS_HOST: string;
|
||||||
|
REDIS_PORT: number;
|
||||||
|
REDIS_PASSWORD: string;
|
||||||
|
ZHIHU_COOKIE: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 验证并提取环境变量
|
// 验证并提取环境变量
|
||||||
const getEnvVariable = (key: string): string | undefined => {
|
const getEnvVariable = (key: string): string | undefined => {
|
||||||
const value = process.env[key];
|
const value = process.env[key];
|
||||||
if (value === undefined) {
|
if (value === undefined) return undefined;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -26,9 +29,7 @@ const getEnvVariable = (key: string): string | undefined => {
|
|||||||
const getNumericEnvVariable = (key: string, defaultValue: number): number => {
|
const getNumericEnvVariable = (key: string, defaultValue: number): number => {
|
||||||
const value = getEnvVariable(key) ?? String(defaultValue);
|
const value = getEnvVariable(key) ?? String(defaultValue);
|
||||||
const parsedValue = parseInt(value, 10);
|
const parsedValue = parseInt(value, 10);
|
||||||
if (isNaN(parsedValue)) {
|
if (isNaN(parsedValue)) return defaultValue;
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
return parsedValue;
|
return parsedValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -43,8 +44,13 @@ export const config: Config = {
|
|||||||
PORT: getNumericEnvVariable("PORT", 6688),
|
PORT: getNumericEnvVariable("PORT", 6688),
|
||||||
DISALLOW_ROBOT: getBooleanEnvVariable("DISALLOW_ROBOT", true),
|
DISALLOW_ROBOT: getBooleanEnvVariable("DISALLOW_ROBOT", true),
|
||||||
CACHE_TTL: getNumericEnvVariable("CACHE_TTL", 3600),
|
CACHE_TTL: getNumericEnvVariable("CACHE_TTL", 3600),
|
||||||
REQUEST_TIMEOUT: getNumericEnvVariable("CACHE_TTL", 6000),
|
REQUEST_TIMEOUT: getNumericEnvVariable("REQUEST_TIMEOUT", 6000),
|
||||||
ALLOWED_DOMAIN: getEnvVariable("ALLOWED_DOMAIN") || "*",
|
ALLOWED_DOMAIN: getEnvVariable("ALLOWED_DOMAIN") || "*",
|
||||||
|
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),
|
||||||
|
REDIS_HOST: getEnvVariable("REDIS_HOST") || "127.0.0.1",
|
||||||
|
REDIS_PORT: getNumericEnvVariable("REDIS_PORT", 6379),
|
||||||
|
REDIS_PASSWORD: getEnvVariable("REDIS_PASSWORD") || "",
|
||||||
|
ZHIHU_COOKIE: getEnvVariable("ZHIHU_COOKIE") || "",
|
||||||
};
|
};
|
||||||
|
|||||||
10
src/index.ts
10
src/index.ts
@@ -4,20 +4,22 @@ import logger from "./utils/logger.js";
|
|||||||
import app from "./app.js";
|
import app from "./app.js";
|
||||||
|
|
||||||
// 启动服务器
|
// 启动服务器
|
||||||
const serveHotApi = (port: number = config.PORT) => {
|
const serveHotApi: (port?: number) => void = (port: number = config.PORT) => {
|
||||||
try {
|
try {
|
||||||
const apiServer = serve({
|
const apiServer = serve({
|
||||||
fetch: app.fetch,
|
fetch: app.fetch,
|
||||||
port,
|
port,
|
||||||
});
|
});
|
||||||
logger.info(`🔥 DailyHot API 成功在端口 ${config.PORT} 上运行`);
|
logger.info(`🔥 DailyHot API successfully runs on port ${port}`);
|
||||||
logger.info(`🔗 Local: 👉 http://localhost:${config.PORT}`);
|
logger.info(`🔗 Local: 👉 http://localhost:${port}`);
|
||||||
return apiServer;
|
return apiServer;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
serveHotApi();
|
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "docker") {
|
||||||
|
serveHotApi(config.PORT);
|
||||||
|
}
|
||||||
|
|
||||||
export default serveHotApi;
|
export default serveHotApi;
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|||||||
let allRoutePath: Array<string> = [];
|
let allRoutePath: Array<string> = [];
|
||||||
const routersDirName: string = "routes";
|
const routersDirName: string = "routes";
|
||||||
|
|
||||||
|
// 排除路由
|
||||||
|
const excludeRoutes: Array<string> = [];
|
||||||
|
|
||||||
// 建立完整目录路径
|
// 建立完整目录路径
|
||||||
const routersDirPath = path.join(__dirname, routersDirName);
|
const routersDirPath = path.join(__dirname, routersDirName);
|
||||||
|
|
||||||
@@ -29,7 +32,11 @@ const findTsFiles = (dirPath: string, allFiles: string[] = [], basePath: string
|
|||||||
if (stat.isDirectory()) {
|
if (stat.isDirectory()) {
|
||||||
// 如果是文件夹,递归查找
|
// 如果是文件夹,递归查找
|
||||||
findTsFiles(fullPath, allFiles, relativePath);
|
findTsFiles(fullPath, allFiles, relativePath);
|
||||||
} else if (stat.isFile() && (item.endsWith(".ts") || item.endsWith(".js"))) {
|
} else if (
|
||||||
|
stat.isFile() &&
|
||||||
|
(item.endsWith(".ts") || item.endsWith(".js")) &&
|
||||||
|
!item.endsWith(".d.ts")
|
||||||
|
) {
|
||||||
// 符合条件
|
// 符合条件
|
||||||
allFiles.push(relativePath.replace(/\.(ts|js)$/, ""));
|
allFiles.push(relativePath.replace(/\.(ts|js)$/, ""));
|
||||||
}
|
}
|
||||||
@@ -41,12 +48,16 @@ const findTsFiles = (dirPath: string, allFiles: string[] = [], basePath: string
|
|||||||
if (fs.existsSync(routersDirPath) && fs.statSync(routersDirPath).isDirectory()) {
|
if (fs.existsSync(routersDirPath) && fs.statSync(routersDirPath).isDirectory()) {
|
||||||
allRoutePath = findTsFiles(routersDirPath);
|
allRoutePath = findTsFiles(routersDirPath);
|
||||||
} else {
|
} else {
|
||||||
console.error(`目录 ${routersDirPath} 不存在或不是目录`);
|
console.error(`📂 The directory ${routersDirPath} does not exist or is not a directory`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注册全部路由
|
// 注册全部路由
|
||||||
for (let index = 0; index < allRoutePath.length; index++) {
|
for (let index = 0; index < allRoutePath.length; index++) {
|
||||||
const router = allRoutePath[index];
|
const router = allRoutePath[index];
|
||||||
|
// 是否处于排除名单
|
||||||
|
if (excludeRoutes.includes(router)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const listApp = app.basePath(`/${router}`);
|
const listApp = app.basePath(`/${router}`);
|
||||||
// 返回榜单
|
// 返回榜单
|
||||||
listApp.get("/", async (c) => {
|
listApp.get("/", async (c) => {
|
||||||
@@ -71,20 +82,13 @@ for (let index = 0; index < allRoutePath.length; index++) {
|
|||||||
c.header("Content-Type", "application/xml; charset=utf-8");
|
c.header("Content-Type", "application/xml; charset=utf-8");
|
||||||
return c.body(rss);
|
return c.body(rss);
|
||||||
} else {
|
} else {
|
||||||
return c.json(
|
return c.json({ code: 500, message: "RSS generation failed" }, 500);
|
||||||
{
|
|
||||||
code: 500,
|
|
||||||
message: "RSS 生成失败",
|
|
||||||
},
|
|
||||||
500,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c.json({
|
return c.json({ code: 200, ...listData });
|
||||||
code: 200,
|
|
||||||
...listData,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
// 请求方式错误
|
||||||
|
listApp.all("*", (c) => c.json({ code: 405, message: "Method Not Allowed" }, 405));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取全部路由
|
// 获取全部路由
|
||||||
@@ -93,10 +97,17 @@ app.get("/all", (c) =>
|
|||||||
{
|
{
|
||||||
code: 200,
|
code: 200,
|
||||||
count: allRoutePath.length,
|
count: allRoutePath.length,
|
||||||
routes: allRoutePath.map((path) => ({
|
routes: allRoutePath.map((path) => {
|
||||||
name: path,
|
// 是否处于排除名单
|
||||||
path: `/${path}`,
|
if (excludeRoutes.includes(path)) {
|
||||||
})),
|
return {
|
||||||
|
name: path,
|
||||||
|
path: undefined,
|
||||||
|
message: "This interface is temporarily offline",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { name: path, path: `/${path}` };
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
200,
|
200,
|
||||||
),
|
),
|
||||||
|
|||||||
191
src/router.types.d.ts
vendored
191
src/router.types.d.ts
vendored
@@ -82,11 +82,14 @@ export type RouterType = {
|
|||||||
};
|
};
|
||||||
weibo: {
|
weibo: {
|
||||||
mid: string;
|
mid: string;
|
||||||
|
itemid: string;
|
||||||
|
desc: string;
|
||||||
|
scheme: string;
|
||||||
word: string;
|
word: string;
|
||||||
word_scheme: string;
|
word_scheme: string;
|
||||||
note: string;
|
note: string;
|
||||||
category: string;
|
flag_desc: string;
|
||||||
raw_hot: number;
|
num: number;
|
||||||
onboard_time: number;
|
onboard_time: number;
|
||||||
};
|
};
|
||||||
zhihu: {
|
zhihu: {
|
||||||
@@ -95,6 +98,7 @@ export type RouterType = {
|
|||||||
title: string;
|
title: string;
|
||||||
excerpt: string;
|
excerpt: string;
|
||||||
created: number;
|
created: number;
|
||||||
|
url: string;
|
||||||
};
|
};
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
@@ -126,9 +130,8 @@ export type RouterType = {
|
|||||||
content: string;
|
content: string;
|
||||||
cover: string;
|
cover: string;
|
||||||
created_at: number;
|
created_at: number;
|
||||||
};
|
view_status: number;
|
||||||
stat: {
|
images: string[];
|
||||||
view_num: number;
|
|
||||||
};
|
};
|
||||||
user: {
|
user: {
|
||||||
nickname: string;
|
nickname: string;
|
||||||
@@ -260,4 +263,182 @@ export type RouterType = {
|
|||||||
comment_count: number;
|
comment_count: number;
|
||||||
created_at: number;
|
created_at: number;
|
||||||
};
|
};
|
||||||
|
csdn: {
|
||||||
|
nickName: string;
|
||||||
|
articleTitle: string;
|
||||||
|
articleDetailUrl: string;
|
||||||
|
picList: [string];
|
||||||
|
hotRankScore: string;
|
||||||
|
period: string;
|
||||||
|
productId: string;
|
||||||
|
};
|
||||||
|
history: {
|
||||||
|
year: string;
|
||||||
|
title: string;
|
||||||
|
link: string;
|
||||||
|
desc: string;
|
||||||
|
cover: string;
|
||||||
|
pic_share: string;
|
||||||
|
};
|
||||||
|
hupu: {
|
||||||
|
tid: number;
|
||||||
|
title: string;
|
||||||
|
replies: number;
|
||||||
|
username: string;
|
||||||
|
time: string;
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
|
sina: {
|
||||||
|
base: {
|
||||||
|
base: {
|
||||||
|
uniqueId: string;
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
info: {
|
||||||
|
hotValue: string;
|
||||||
|
title: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
"sina-news": {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
media: string;
|
||||||
|
url: string;
|
||||||
|
create_date: string;
|
||||||
|
create_time: string;
|
||||||
|
top_num: string;
|
||||||
|
time: string;
|
||||||
|
};
|
||||||
|
coolapk: {
|
||||||
|
id: number;
|
||||||
|
ttitle: string;
|
||||||
|
shareUrl: string;
|
||||||
|
username: string;
|
||||||
|
tpic: string;
|
||||||
|
message: string;
|
||||||
|
replynum: number;
|
||||||
|
};
|
||||||
|
guokr: {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
summary: string;
|
||||||
|
author: {
|
||||||
|
nickname: string;
|
||||||
|
};
|
||||||
|
date_modified: string;
|
||||||
|
small_image: string;
|
||||||
|
};
|
||||||
|
kuaishou: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
hotValue: string;
|
||||||
|
iconUrl: string;
|
||||||
|
poster: string;
|
||||||
|
photoIds: {
|
||||||
|
json: string[];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
smzdm: {
|
||||||
|
content: string;
|
||||||
|
title: string;
|
||||||
|
article_id: string;
|
||||||
|
nickname: string;
|
||||||
|
jump_link: string;
|
||||||
|
pic_url: string;
|
||||||
|
collection_count: string;
|
||||||
|
time_sort: string;
|
||||||
|
};
|
||||||
|
yystv: {
|
||||||
|
id: string;
|
||||||
|
cover: string;
|
||||||
|
title: string;
|
||||||
|
preface: string;
|
||||||
|
author: string;
|
||||||
|
createtime: string;
|
||||||
|
};
|
||||||
|
dgtle: {
|
||||||
|
id: number;
|
||||||
|
content: string;
|
||||||
|
cover: string;
|
||||||
|
from: string;
|
||||||
|
title: string;
|
||||||
|
membernum: number;
|
||||||
|
created_at: number;
|
||||||
|
type: number;
|
||||||
|
};
|
||||||
|
geekpark: {
|
||||||
|
post: {
|
||||||
|
id: number;
|
||||||
|
nickname: string;
|
||||||
|
title: string;
|
||||||
|
abstract: string;
|
||||||
|
cover_url: string;
|
||||||
|
views: number;
|
||||||
|
published_timestamp: number;
|
||||||
|
authors: {
|
||||||
|
nickname: string;
|
||||||
|
}[];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
linuxdo: {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
url: string;
|
||||||
|
author: string;
|
||||||
|
desc: string;
|
||||||
|
timestamp: string;
|
||||||
|
};
|
||||||
|
hackernews: {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
hot: number | undefined;
|
||||||
|
timestamp: number | undefined;
|
||||||
|
url: string;
|
||||||
|
mobileUrl: string;
|
||||||
|
};
|
||||||
|
github: {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
desc?: string;
|
||||||
|
hot: number | undefined;
|
||||||
|
timestamp: number | undefined;
|
||||||
|
url: string;
|
||||||
|
mobileUrl: string;
|
||||||
|
};
|
||||||
|
producthunt: {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
hot: number | undefined;
|
||||||
|
timestamp: number | undefined;
|
||||||
|
url: string;
|
||||||
|
mobileUrl: string;
|
||||||
|
};
|
||||||
|
newsmth: {
|
||||||
|
firstArticleId: string;
|
||||||
|
subject: string;
|
||||||
|
article: {
|
||||||
|
topicId: string;
|
||||||
|
postTime: number;
|
||||||
|
subject: string;
|
||||||
|
body: string;
|
||||||
|
account: {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
board: {
|
||||||
|
title: string;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
gameres: {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
hot: number | undefined;
|
||||||
|
desc: string;
|
||||||
|
cover: string;
|
||||||
|
timestamp: number | undefined;
|
||||||
|
url: string;
|
||||||
|
mobileUrl: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,36 +1,36 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options, RouterResType } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { post } from "../utils/getData.js";
|
import { post } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
|
const typeMap: Record<string, string> = {
|
||||||
|
hot: "人气榜",
|
||||||
|
video: "视频榜",
|
||||||
|
comment: "热议榜",
|
||||||
|
collect: "收藏榜",
|
||||||
|
};
|
||||||
|
|
||||||
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氪",
|
||||||
type: "热榜",
|
type: typeMap[type],
|
||||||
parameData: {
|
params: {
|
||||||
type: {
|
type: {
|
||||||
name: "热榜分类",
|
name: "热榜分类",
|
||||||
type: {
|
type: typeMap,
|
||||||
hot: "人气榜",
|
|
||||||
video: "视频榜",
|
|
||||||
comment: "热议榜",
|
|
||||||
collect: "收藏榜",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (options: Options, noCache: boolean) => {
|
const getList = async (options: Options, noCache: boolean): Promise<RouterResType> => {
|
||||||
const { type } = options;
|
const { type } = options;
|
||||||
const url = `https://gateway.36kr.com/api/mis/nav/home/nav/rank/${type}`;
|
const url = `https://gateway.36kr.com/api/mis/nav/home/nav/rank/${type}`;
|
||||||
const result = await post({
|
const result = await post({
|
||||||
@@ -57,8 +57,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
|||||||
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 {
|
||||||
@@ -67,7 +66,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
|||||||
cover: item.widgetImage,
|
cover: item.widgetImage,
|
||||||
author: item.authorName,
|
author: item.authorName,
|
||||||
timestamp: getTime(v.publishTime),
|
timestamp: getTime(v.publishTime),
|
||||||
hot: item.statCollect,
|
hot: item.statCollect || undefined,
|
||||||
url: `https://www.36kr.com/p/${v.itemId}`,
|
url: `https://www.36kr.com/p/${v.itemId}`,
|
||||||
mobileUrl: `https://m.36kr.com/p/${v.itemId}`,
|
mobileUrl: `https://m.36kr.com/p/${v.itemId}`,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData, RouterResType } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { getToken, sign } from "../utils/getToken/51cto.js";
|
import { getToken, sign } from "../utils/getToken/51cto.js";
|
||||||
import { get } from "../utils/getData.js";
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (noCache: boolean) => {
|
const getList = async (noCache: boolean): Promise<RouterResType> => {
|
||||||
const url = `https://api-media.51cto.com/index/index/recommend`;
|
const url = `https://api-media.51cto.com/index/index/recommend`;
|
||||||
const params = {
|
const params = {
|
||||||
page: 1,
|
page: 1,
|
||||||
@@ -41,14 +39,14 @@ const getList = async (noCache: boolean) => {
|
|||||||
});
|
});
|
||||||
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,
|
||||||
cover: v.cover,
|
cover: v.cover,
|
||||||
desc: v.abstract,
|
desc: v.abstract,
|
||||||
timestamp: getTime(v.pubdate),
|
timestamp: getTime(v.pubdate),
|
||||||
|
hot: undefined,
|
||||||
url: v.url,
|
url: v.url,
|
||||||
mobileUrl: v.url,
|
mobileUrl: v.url,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -1,66 +1,63 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options, RouterResType } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import { get } from "../utils/getData.js";
|
||||||
import { web } from "../utils/getData.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
import { extractRss, parseRSS } from "../utils/parseRSS.js";
|
import { parseRSS } from "../utils/parseRSS.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import iconv from "iconv-lite";
|
||||||
|
|
||||||
|
const typeMap: Record<string, string> = {
|
||||||
|
digest: "最新精华",
|
||||||
|
hot: "最新热门",
|
||||||
|
new: "最新回复",
|
||||||
|
newthread: "最新发表",
|
||||||
|
};
|
||||||
|
|
||||||
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") || "digest";
|
||||||
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: "吾爱破解",
|
||||||
type: "榜单",
|
type: typeMap[type],
|
||||||
parameData: {
|
params: {
|
||||||
type: {
|
type: {
|
||||||
name: "榜单分类",
|
name: "榜单分类",
|
||||||
type: {
|
type: typeMap,
|
||||||
tech: "新鲜出炉",
|
|
||||||
newthread: "技术分享",
|
|
||||||
hot: "人气热门",
|
|
||||||
digest: "精华采撷",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (options: Options, noCache: boolean) => {
|
const getList = async (options: Options, noCache: boolean): Promise<RouterResType> => {
|
||||||
const { type } = options;
|
const { type } = options;
|
||||||
const url = `https://www.52pojie.cn/forum.php?mod=guide&view=${type}&rss=1`;
|
const url = `https://www.52pojie.cn/forum.php?mod=guide&view=${type}&rss=1`;
|
||||||
const result = await web({
|
const result = await get({
|
||||||
url,
|
url,
|
||||||
noCache,
|
noCache,
|
||||||
userAgent:
|
responseType: "arraybuffer",
|
||||||
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36",
|
headers: {
|
||||||
|
userAgent:
|
||||||
|
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const parseData = async () => {
|
|
||||||
if (typeof result?.data === "string") {
|
// 转码
|
||||||
const rssContent = extractRss(result.data);
|
const utf8Data = iconv.decode(result.data, "gbk");
|
||||||
return await parseRSS(rssContent);
|
const list = await parseRSS(utf8Data);
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const list = await parseData();
|
|
||||||
return {
|
return {
|
||||||
fromCache: result.fromCache,
|
...result,
|
||||||
updateTime: result.updateTime,
|
data: list.map((v, i) => ({
|
||||||
data: list.map((v: RouterType["discuz"]) => ({
|
id: v.guid || i,
|
||||||
id: v.guid,
|
title: v.title || "",
|
||||||
title: v.title,
|
desc: v.content?.trim() || "",
|
||||||
desc: v.content,
|
|
||||||
author: v.author,
|
author: v.author,
|
||||||
timestamp: getTime(v.pubDate),
|
timestamp: getTime(v.pubDate || 0),
|
||||||
hot: null,
|
hot: undefined,
|
||||||
url: v.link,
|
url: v.link || "",
|
||||||
mobileUrl: v.link,
|
mobileUrl: v.link || "",
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,54 +1,56 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options, RouterResType } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
|
const typeMap: Record<string, string> = {
|
||||||
|
"-1": "综合",
|
||||||
|
"155": "番剧",
|
||||||
|
"1": "动画",
|
||||||
|
"60": "娱乐",
|
||||||
|
"201": "生活",
|
||||||
|
"58": "音乐",
|
||||||
|
"123": "舞蹈·偶像",
|
||||||
|
"59": "游戏",
|
||||||
|
"70": "科技",
|
||||||
|
"68": "影视",
|
||||||
|
"69": "体育",
|
||||||
|
"125": "鱼塘",
|
||||||
|
};
|
||||||
|
|
||||||
|
const rangeMap: Record<string, string> = {
|
||||||
|
DAY: "今日",
|
||||||
|
THREE_DAYS: "三日",
|
||||||
|
WEEK: "本周",
|
||||||
|
};
|
||||||
|
|
||||||
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",
|
||||||
type: "排行榜",
|
type: `排行榜 · ${typeMap[type]}`,
|
||||||
description: "AcFun是一家弹幕视频网站,致力于为每一个人带来欢乐。",
|
description: "AcFun是一家弹幕视频网站,致力于为每一个人带来欢乐。",
|
||||||
parameData: {
|
params: {
|
||||||
type: {
|
type: {
|
||||||
name: "频道",
|
name: "频道",
|
||||||
type: {
|
type: typeMap,
|
||||||
"-1": "全站综合",
|
|
||||||
"155": "番剧",
|
|
||||||
"1": "动画",
|
|
||||||
"60": "娱乐",
|
|
||||||
"201": "生活",
|
|
||||||
"58": "音乐",
|
|
||||||
"123": "舞蹈·偶像",
|
|
||||||
"59": "游戏",
|
|
||||||
"70": "科技",
|
|
||||||
"68": "影视",
|
|
||||||
"69": "体育",
|
|
||||||
"125": "鱼塘",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
range: {
|
range: {
|
||||||
name: "时间",
|
name: "时间",
|
||||||
type: {
|
type: rangeMap,
|
||||||
DAY: "今日",
|
|
||||||
THREE_DAYS: "三日",
|
|
||||||
WEEK: "本周",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (options: Options, noCache: boolean) => {
|
const getList = async (options: Options, noCache: boolean): Promise<RouterResType> => {
|
||||||
const { type, range } = options;
|
const { type, range } = options;
|
||||||
const url = `https://www.acfun.cn/rest/pc-direct/rank/channel?channelId=${type === "-1" ? "" : type}&rankLimit=30&rankPeriod=${range}`;
|
const url = `https://www.acfun.cn/rest/pc-direct/rank/channel?channelId=${type === "-1" ? "" : type}&rankLimit=30&rankPeriod=${range}`;
|
||||||
const result = await get({
|
const result = await get({
|
||||||
@@ -60,8 +62,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
|||||||
});
|
});
|
||||||
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,
|
||||||
|
|||||||
@@ -1,37 +1,37 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options, RouterResType } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
|
|
||||||
|
const typeMap: Record<string, string> = {
|
||||||
|
realtime: "热搜",
|
||||||
|
novel: "小说",
|
||||||
|
movie: "电影",
|
||||||
|
teleplay: "电视剧",
|
||||||
|
car: "汽车",
|
||||||
|
game: "游戏",
|
||||||
|
};
|
||||||
|
|
||||||
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: "百度",
|
||||||
type: "热搜榜",
|
type: typeMap[type],
|
||||||
parameData: {
|
params: {
|
||||||
type: {
|
type: {
|
||||||
name: "热搜类别",
|
name: "热搜类别",
|
||||||
type: {
|
type: typeMap,
|
||||||
realtime: "热搜",
|
|
||||||
novel: "小说",
|
|
||||||
movie: "电影",
|
|
||||||
teleplay: "电视剧",
|
|
||||||
car: "汽车",
|
|
||||||
game: "游戏",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (options: Options, noCache: boolean) => {
|
const getList = async (options: Options, noCache: boolean): Promise<RouterResType> => {
|
||||||
const { type } = options;
|
const { type } = options;
|
||||||
const url = `https://top.baidu.com/board?tab=${type}`;
|
const url = `https://top.baidu.com/board?tab=${type}`;
|
||||||
const result = await get({
|
const result = await get({
|
||||||
@@ -47,16 +47,15 @@ const getList = async (options: Options, noCache: boolean) => {
|
|||||||
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,
|
||||||
desc: v.desc,
|
desc: v.desc,
|
||||||
cover: v.img,
|
cover: v.img,
|
||||||
author: v.show?.length ? v.show : "",
|
author: v.show?.length ? v.show : "",
|
||||||
timestamp: null,
|
timestamp: 0,
|
||||||
hot: Number(v.hotScore),
|
hot: Number(v.hotScore || 0),
|
||||||
url: `https://www.baidu.com/s?wd=${encodeURIComponent(v.query)}`,
|
url: `https://www.baidu.com/s?wd=${encodeURIComponent(v.query)}`,
|
||||||
mobileUrl: v.rawUrl,
|
mobileUrl: v.rawUrl,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -1,61 +1,72 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options, RouterResType } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import getBiliWbi from "../utils/getToken/bilibili.js";
|
import getBiliWbi from "../utils/getToken/bilibili.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
import logger from "../utils/logger.js";
|
||||||
|
const typeMap: Record<string, string> = {
|
||||||
|
"0": "全站",
|
||||||
|
"1": "动画",
|
||||||
|
"3": "音乐",
|
||||||
|
"4": "游戏",
|
||||||
|
"5": "娱乐",
|
||||||
|
"188": "科技",
|
||||||
|
"119": "鬼畜",
|
||||||
|
"129": "舞蹈",
|
||||||
|
"155": "时尚",
|
||||||
|
"160": "生活",
|
||||||
|
"168": "国创相关",
|
||||||
|
"181": "影视",
|
||||||
|
};
|
||||||
|
|
||||||
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: "哔哩哔哩",
|
||||||
type: "热门榜",
|
type: `热榜 · ${typeMap[type]}`,
|
||||||
description: "你所热爱的,就是你的生活",
|
description: "你所热爱的,就是你的生活",
|
||||||
parameData: {
|
params: {
|
||||||
type: {
|
type: {
|
||||||
name: "排行榜分区",
|
name: "排行榜分区",
|
||||||
type: {
|
type: typeMap,
|
||||||
0: "全站",
|
|
||||||
1: "动画",
|
|
||||||
3: "音乐",
|
|
||||||
4: "游戏",
|
|
||||||
5: "娱乐",
|
|
||||||
36: "科技",
|
|
||||||
119: "鬼畜",
|
|
||||||
129: "舞蹈",
|
|
||||||
155: "时尚",
|
|
||||||
160: "生活",
|
|
||||||
168: "国创相关",
|
|
||||||
188: "数码",
|
|
||||||
181: "影视",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (options: Options, noCache: boolean) => {
|
const getList = async (options: Options, noCache: boolean): Promise<RouterResType> => {
|
||||||
const { type } = options;
|
const { type } = options;
|
||||||
const wbiData = await getBiliWbi();
|
const wbiData = await getBiliWbi();
|
||||||
const url = `https://api.bilibili.com/x/web-interface/ranking/v2?tid=${type}&type=all&${wbiData}`;
|
const url = `https://api.bilibili.com/x/web-interface/ranking/v2?rid=${type}&type=all&${wbiData}`;
|
||||||
const result = await get({
|
const result = await get({
|
||||||
url,
|
url,
|
||||||
headers: {
|
headers: {
|
||||||
Referer: `https://www.bilibili.com/ranking/all`,
|
'Referer': 'https://www.bilibili.com/ranking/all',
|
||||||
"User-Agent":
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
|
||||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||||
|
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
||||||
|
'Accept-Encoding': 'gzip, deflate, br',
|
||||||
|
'Sec-Ch-Ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"',
|
||||||
|
'Sec-Ch-Ua-Mobile': '?0',
|
||||||
|
'Sec-Ch-Ua-Platform': '"Windows"',
|
||||||
|
'Sec-Fetch-Dest': 'document',
|
||||||
|
'Sec-Fetch-Mode': 'navigate',
|
||||||
|
'Sec-Fetch-Site': 'same-origin',
|
||||||
|
'Sec-Fetch-User': '?1',
|
||||||
|
'Upgrade-Insecure-Requests': '1',
|
||||||
},
|
},
|
||||||
noCache,
|
noCache: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 是否触发风控
|
// 是否触发风控
|
||||||
if (result.data?.data?.list?.length > 0) {
|
if (result.data?.data?.list?.length > 0) {
|
||||||
|
logger.info('bilibili 新接口')
|
||||||
const list = result.data.data.list;
|
const list = result.data.data.list;
|
||||||
return {
|
return {
|
||||||
fromCache: result.fromCache,
|
fromCache: result.fromCache,
|
||||||
@@ -64,10 +75,10 @@ const getList = async (options: Options, noCache: boolean) => {
|
|||||||
id: v.bvid,
|
id: v.bvid,
|
||||||
title: v.title,
|
title: v.title,
|
||||||
desc: v.desc || "该视频暂无简介",
|
desc: v.desc || "该视频暂无简介",
|
||||||
cover: v.pic.replace(/http:/, "https:"),
|
cover: v.pic?.replace(/http:/, "https:"),
|
||||||
author: v.owner.name,
|
author: v.owner?.name,
|
||||||
timestamp: getTime(v.pubdate),
|
timestamp: getTime(v.pubdate),
|
||||||
hot: v.stat.view,
|
hot: v.stat?.view || 0,
|
||||||
url: v.short_link_v2 || `https://www.bilibili.com/video/${v.bvid}`,
|
url: v.short_link_v2 || `https://www.bilibili.com/video/${v.bvid}`,
|
||||||
mobileUrl: `https://m.bilibili.com/video/${v.bvid}`,
|
mobileUrl: `https://m.bilibili.com/video/${v.bvid}`,
|
||||||
})),
|
})),
|
||||||
@@ -75,7 +86,8 @@ const getList = async (options: Options, noCache: boolean) => {
|
|||||||
}
|
}
|
||||||
// 采用备用接口
|
// 采用备用接口
|
||||||
else {
|
else {
|
||||||
const url = `https://api.bilibili.com/x/web-interface/ranking?jsonp=jsonp?rid=${type}&type=1&callback=__jp0`;
|
logger.info('bilibili 备用接口')
|
||||||
|
const url = `https://api.bilibili.com/x/web-interface/ranking?jsonp=jsonp?rid=${type}&type=all&callback=__jp0`;
|
||||||
const result = await get({
|
const result = await get({
|
||||||
url,
|
url,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -87,15 +99,14 @@ const getList = async (options: Options, noCache: boolean) => {
|
|||||||
});
|
});
|
||||||
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,
|
||||||
desc: v.desc || "该视频暂无简介",
|
desc: v.desc || "该视频暂无简介",
|
||||||
cover: v.pic.replace(/http:/, "https:"),
|
cover: v.pic?.replace(/http:/, "https:"),
|
||||||
author: v.author,
|
author: v.author,
|
||||||
timestamp: null,
|
timestamp: undefined,
|
||||||
hot: v.video_review,
|
hot: v.video_review,
|
||||||
url: `https://www.bilibili.com/video/${v.bvid}`,
|
url: `https://www.bilibili.com/video/${v.bvid}`,
|
||||||
mobileUrl: `https://m.bilibili.com/video/${v.bvid}`,
|
mobileUrl: `https://m.bilibili.com/video/${v.bvid}`,
|
||||||
|
|||||||
41
src/routes/coolapk.ts
Normal file
41
src/routes/coolapk.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import type { RouterData } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { genHeaders } from "../utils/getToken/coolapk.js";
|
||||||
|
|
||||||
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
|
const listData = await getList(noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "coolapk",
|
||||||
|
title: "酷安",
|
||||||
|
type: "热榜",
|
||||||
|
link: "https://www.coolapk.com/",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (noCache: boolean) => {
|
||||||
|
const url = `https://api.coolapk.com/v6/page/dataList?url=/feed/statList?cacheExpires=300&statType=day&sortField=detailnum&title=今日热门&title=今日热门&subTitle=&page=1`;
|
||||||
|
const result = await get({
|
||||||
|
url,
|
||||||
|
noCache,
|
||||||
|
headers: genHeaders(),
|
||||||
|
});
|
||||||
|
const list = result.data.data;
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v: RouterType["coolapk"]) => ({
|
||||||
|
id: v.id,
|
||||||
|
title: v.message,
|
||||||
|
cover: v.tpic,
|
||||||
|
author: v.username,
|
||||||
|
desc: v.ttitle,
|
||||||
|
timestamp: undefined,
|
||||||
|
hot: undefined,
|
||||||
|
url: v.shareUrl,
|
||||||
|
mobileUrl: v.shareUrl,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
38
src/routes/csdn.ts
Normal file
38
src/routes/csdn.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import type { RouterData, RouterResType } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
|
const listData = await getList(noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "csdn",
|
||||||
|
title: "CSDN",
|
||||||
|
type: "排行榜",
|
||||||
|
description: "专业开发者社区",
|
||||||
|
link: "https://www.csdn.net/",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (noCache: boolean): Promise<RouterResType> => {
|
||||||
|
const url = "https://blog.csdn.net/phoenix/web/blog/hot-rank?page=0&pageSize=30";
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
const list = result.data.data;
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v: RouterType["csdn"]) => ({
|
||||||
|
id: v.productId,
|
||||||
|
title: v.articleTitle,
|
||||||
|
cover: v.picList?.[0] || undefined,
|
||||||
|
desc: undefined,
|
||||||
|
author: v.nickName,
|
||||||
|
timestamp: getTime(v.period),
|
||||||
|
hot: Number(v.hotRankScore),
|
||||||
|
url: v.articleDetailUrl,
|
||||||
|
mobileUrl: v.articleDetailUrl,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
39
src/routes/dgtle.ts
Normal file
39
src/routes/dgtle.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import type { RouterData } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
|
const listData = await getList(noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "dgtle",
|
||||||
|
title: "数字尾巴",
|
||||||
|
type: "热门文章",
|
||||||
|
description:
|
||||||
|
"致力于分享美好数字生活体验,囊括你闻所未闻的最丰富数码资讯,触所未触最抢鲜产品评测,随时随地感受尾巴们各式数字生活精彩图文、摄影感悟、旅行游记、爱物分享。",
|
||||||
|
link: "https://www.dgtle.com/",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (noCache: boolean) => {
|
||||||
|
const url = `https://opser.api.dgtle.com/v2/news/index`;
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
const list = result.data?.items;
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v: RouterType["dgtle"]) => ({
|
||||||
|
id: v.id,
|
||||||
|
title: v.title || v.content,
|
||||||
|
desc: v.content,
|
||||||
|
cover: v.cover,
|
||||||
|
author: v.from,
|
||||||
|
hot: v.membernum,
|
||||||
|
timestamp: getTime(v.created_at),
|
||||||
|
url: `https://www.dgtle.com/news-${v.id}-${v.type}.html`,
|
||||||
|
mobileUrl: `https://m.dgtle.com/news-details/${v.id}`,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,18 +1,17 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import { load } from "cheerio";
|
import { load } from "cheerio";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.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;
|
||||||
};
|
};
|
||||||
@@ -42,15 +41,14 @@ const getList = async (noCache: boolean) => {
|
|||||||
title: dom.find("h3 a").text().trim(),
|
title: dom.find("h3 a").text().trim(),
|
||||||
cover: dom.find(".pic-wrap img").attr("src"),
|
cover: dom.find(".pic-wrap img").attr("src"),
|
||||||
desc: dom.find(".block p").text().trim(),
|
desc: dom.find(".block p").text().trim(),
|
||||||
timestamp: dom.find("span.pubtime").text().trim(),
|
timestamp: getTime(dom.find("span.pubtime").text().trim()),
|
||||||
hot: null,
|
hot: 0,
|
||||||
url,
|
url: url || `https://www.douban.com/group/topic/${getNumbers(url)}`,
|
||||||
mobileUrl: `https://m.douban.com/group/topic/${getNumbers(url)}/`,
|
mobileUrl: `https://m.douban.com/group/topic/${getNumbers(url)}/`,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
fromCache: result.fromCache,
|
...result,
|
||||||
updateTime: result.updateTime,
|
|
||||||
data: listData,
|
data: listData,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,29 +3,27 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 数据处理
|
// 数据处理
|
||||||
const getNumbers = (text: string | undefined) => {
|
const getNumbers = (text: string | undefined): number => {
|
||||||
if (!text) return 10000000;
|
if (!text) return 0;
|
||||||
const regex = /\d+/;
|
const regex = /\d+/;
|
||||||
const match = text.match(regex);
|
const match = text.match(regex);
|
||||||
if (match) {
|
if (match) {
|
||||||
return Number(match[0]);
|
return Number(match[0]);
|
||||||
} else {
|
} else {
|
||||||
return 10000000;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -44,21 +42,21 @@ const getList = async (noCache: boolean) => {
|
|||||||
const listData = listDom.toArray().map((item) => {
|
const listData = listDom.toArray().map((item) => {
|
||||||
const dom = $(item);
|
const dom = $(item);
|
||||||
const url = dom.find("a").attr("href") || undefined;
|
const url = dom.find("a").attr("href") || undefined;
|
||||||
const score = dom.find(".rating_nums").text() ?? "0.0";
|
const scoreDom = dom.find(".rating_nums");
|
||||||
|
const score = scoreDom.length > 0 ? scoreDom.text() : "0.0";
|
||||||
return {
|
return {
|
||||||
id: getNumbers(url),
|
id: getNumbers(url),
|
||||||
title: `【${score}】${dom.find("a").attr("title")}`,
|
title: `【${score}】${dom.find("a").attr("title")}`,
|
||||||
cover: dom.find("img").attr("src"),
|
cover: dom.find("img").attr("src"),
|
||||||
desc: dom.find("p.pl").text(),
|
desc: dom.find("p.pl").text(),
|
||||||
timestamp: null,
|
timestamp: undefined,
|
||||||
hot: getNumbers(dom.find("span.pl").text()),
|
hot: getNumbers(dom.find("span.pl").text()),
|
||||||
url,
|
url: url || `https://movie.douban.com/subject/${getNumbers(url)}/`,
|
||||||
mobileUrl: `https://m.douban.com/movie/subject/${getNumbers(url)}/`,
|
mobileUrl: `https://m.douban.com/movie/subject/${getNumbers(url)}/`,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
fromCache: result.fromCache,
|
...result,
|
||||||
updateTime: result.updateTime,
|
|
||||||
data: listData,
|
data: listData,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
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;
|
||||||
};
|
};
|
||||||
@@ -30,7 +28,7 @@ const getDyCookies = async () => {
|
|||||||
return cookieData;
|
return cookieData;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("获取抖音 Cookie 出错" + error);
|
console.error("获取抖音 Cookie 出错" + error);
|
||||||
return null;
|
return undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,15 +45,14 @@ 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,
|
||||||
timestamp: getTime(v.event_time),
|
timestamp: getTime(v.event_time),
|
||||||
hot: v.hot_value,
|
hot: v.hot_value,
|
||||||
url: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
|
url: `https://www.douyin.com/hot/${v.sentence_id}`,
|
||||||
mobileUrl: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
|
mobileUrl: `https://www.douyin.com/hot/${v.sentence_id}`,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
const mappings = {
|
const mappings: Record<string, string> = {
|
||||||
O_TIME: "发震时刻(UTC+8)",
|
O_TIME: "发震时刻(UTC+8)",
|
||||||
LOCATION_C: "参考位置",
|
LOCATION_C: "参考位置",
|
||||||
M: "震级(M)",
|
M: "震级(M)",
|
||||||
@@ -13,64 +13,41 @@ const mappings = {
|
|||||||
SAVE_TIME: "录入时间",
|
SAVE_TIME: "录入时间",
|
||||||
};
|
};
|
||||||
|
|
||||||
const typeMappings = {
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
1: "最近24小时地震信息",
|
const listData = await getList(noCache);
|
||||||
2: "最近48小时地震信息",
|
|
||||||
3: "最近7天地震信息",
|
|
||||||
4: "最近30天地震信息",
|
|
||||||
5: "最近一年3.0级以上地震信息",
|
|
||||||
6: "最近一年地震信息",
|
|
||||||
7: "最近一年3.0级以下地震",
|
|
||||||
8: "最近一年4.0级以上地震信息",
|
|
||||||
9: "最近一年5.0级以上地震信息",
|
|
||||||
0: "最近一年6.0级以上地震信息",
|
|
||||||
};
|
|
||||||
|
|
||||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|
||||||
const type = c.req.query("type") || "5";
|
|
||||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
|
||||||
const routeData: RouterData = {
|
const routeData: RouterData = {
|
||||||
name: "earthquake",
|
name: "earthquake",
|
||||||
title: "中国地震台",
|
title: "中国地震台",
|
||||||
type: "地震速报",
|
type: "地震速报",
|
||||||
parameData: {
|
|
||||||
type: {
|
|
||||||
name: "速报分类",
|
|
||||||
type: {
|
|
||||||
...typeMappings,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (options: Options, noCache: boolean) => {
|
const getList = async (noCache: boolean) => {
|
||||||
const { type } = options;
|
const url = `https://news.ceic.ac.cn/speedsearch.html`;
|
||||||
const url = `http://www.ceic.ac.cn/ajax/speedsearch?num=${type}`;
|
|
||||||
const result = await get({ url, noCache });
|
const result = await get({ url, noCache });
|
||||||
const data = result.data.replace(/,"page":"(.*?)","num":/, ',"num":');
|
const regex = /const newdata = (\[.*?\]);/s;
|
||||||
const list = JSON.parse(data.substring(1, data.length - 1)).shuju;
|
const match = result.data.match(regex);
|
||||||
|
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;
|
||||||
for (const mappingsKey in mappings) {
|
for (const mappingsKey in mappings) {
|
||||||
contentBuilder.push(`${mappings[mappingsKey]}:${v[mappingsKey]}`);
|
contentBuilder.push(
|
||||||
|
`${mappings[mappingsKey as keyof typeof mappings]}:${v[mappingsKey as keyof typeof v]}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
id: NEW_DID,
|
id: NEW_DID,
|
||||||
title: `${LOCATION_C}发生${M}级地震`,
|
title: `${LOCATION_C}发生${M}级地震`,
|
||||||
desc: contentBuilder.join("\n"),
|
desc: contentBuilder.join("\n"),
|
||||||
timestamp: getTime(v["O_TIME"]),
|
timestamp: getTime(v["O_TIME" as keyof typeof v]),
|
||||||
hot: null,
|
hot: undefined,
|
||||||
url: `https://news.ceic.ac.cn/${NEW_DID}.html`,
|
url: `https://news.ceic.ac.cn/${NEW_DID}.html`,
|
||||||
mobileUrl: `https://news.ceic.ac.cn/${NEW_DID}.html`,
|
mobileUrl: `https://news.ceic.ac.cn/${NEW_DID}.html`,
|
||||||
};
|
};
|
||||||
|
|||||||
66
src/routes/gameres.ts
Normal file
66
src/routes/gameres.ts
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import type { RouterData } from "../types.js";
|
||||||
|
import { load } from "cheerio";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
import { RouterType } from "../router.types.js";
|
||||||
|
|
||||||
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
|
const listData = await getList(noCache);
|
||||||
|
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "gameres",
|
||||||
|
title: "GameRes 游资网",
|
||||||
|
type: "最新资讯",
|
||||||
|
description:
|
||||||
|
"面向游戏从业者的游戏开发资讯,旨在为游戏制作人提供游戏研发类的程序技术、策划设计、艺术设计、原创设计等资讯内容。",
|
||||||
|
link: "https://www.gameres.com",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (noCache: boolean) => {
|
||||||
|
const url = `https://www.gameres.com`;
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
const $ = load(result.data);
|
||||||
|
|
||||||
|
const container = $('div[data-news-pane-id="100000"]');
|
||||||
|
const listDom = container.find("article.feed-item");
|
||||||
|
|
||||||
|
const listData = Array.from(listDom).map((el) => {
|
||||||
|
const dom = $(el);
|
||||||
|
|
||||||
|
const titleEl = dom.find(".feed-item-title-a").first();
|
||||||
|
const title = titleEl.text().trim();
|
||||||
|
|
||||||
|
const href = titleEl.attr("href");
|
||||||
|
const url = href?.startsWith("http") ? href : `https://www.gameres.com${href ?? ""}`;
|
||||||
|
|
||||||
|
const cover = dom.find(".thumb").attr("data-original") || "";
|
||||||
|
const desc = dom.find(".feed-item-right > p").first().text().trim();
|
||||||
|
|
||||||
|
const dateTime = dom.find(".mark-info").contents().first().text().trim();
|
||||||
|
const timestamp = getTime(dateTime);
|
||||||
|
|
||||||
|
// 热度(列表暂无评论数)
|
||||||
|
const hot = undefined;
|
||||||
|
|
||||||
|
return {
|
||||||
|
title,
|
||||||
|
desc,
|
||||||
|
cover,
|
||||||
|
timestamp,
|
||||||
|
hot,
|
||||||
|
url,
|
||||||
|
id: url,
|
||||||
|
mobileUrl: url,
|
||||||
|
} as RouterType["gameres"];
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: listData,
|
||||||
|
};
|
||||||
|
};
|
||||||
41
src/routes/geekpark.ts
Normal file
41
src/routes/geekpark.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import type { RouterData } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
|
const listData = await getList(noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "geekpark",
|
||||||
|
title: "极客公园",
|
||||||
|
type: "热门文章",
|
||||||
|
description: "极客公园聚焦互联网领域,跟踪新鲜的科技新闻动态,关注极具创新精神的科技产品。",
|
||||||
|
link: "https://www.geekpark.net/",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (noCache: boolean) => {
|
||||||
|
const url = `https://mainssl.geekpark.net/api/v2`;
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
const list = result.data?.homepage_posts;
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v: RouterType["geekpark"]) => {
|
||||||
|
const post = v.post;
|
||||||
|
return {
|
||||||
|
id: post.id,
|
||||||
|
title: post.title,
|
||||||
|
desc: post.abstract,
|
||||||
|
cover: post.cover_url,
|
||||||
|
author: post?.authors?.[0]?.nickname,
|
||||||
|
hot: post.views,
|
||||||
|
timestamp: getTime(post.published_timestamp),
|
||||||
|
url: `https://www.geekpark.net/news/${post.id}`,
|
||||||
|
mobileUrl: `https://www.geekpark.net/news/${post.id}`,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
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: "原神",
|
||||||
type: "最新动态",
|
type: "最新动态",
|
||||||
parameData: {
|
params: {
|
||||||
type: {
|
type: {
|
||||||
name: "榜单分类",
|
name: "榜单分类",
|
||||||
type: {
|
type: {
|
||||||
@@ -21,32 +21,29 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (options: Options, noCache: boolean) => {
|
const getList = async (options: Options, noCache: boolean) => {
|
||||||
const { type } = options;
|
const { type } = options;
|
||||||
const url = `https://bbs-api.miyoushe.com/post/wapi/getNewsList?gids=2&page_size=20&type=${type}`;
|
const url = `https://bbs-api-static.miyoushe.com/painter/wapi/getNewsList?client_type=4&gids=2&last_id=&page_size=20&type=${type}`;
|
||||||
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 {
|
||||||
id: data.post_id,
|
id: data.post_id,
|
||||||
title: data.subject,
|
title: data.subject,
|
||||||
desc: data.content,
|
desc: data.content,
|
||||||
cover: data.cover,
|
cover: data.cover || data?.images?.[0],
|
||||||
author: v.user.nickname,
|
author: v.user?.nickname || undefined,
|
||||||
timestamp: getTime(data.created_at),
|
timestamp: getTime(data.created_at),
|
||||||
hot: v.stat.view_num,
|
hot: data.view_status,
|
||||||
url: `https://www.miyoushe.com/ys/article/${data.post_id}`,
|
url: `https://www.miyoushe.com/ys/article/${data.post_id}`,
|
||||||
mobileUrl: `https://m.miyoushe.com/ys/#/article/${data.post_id}`,
|
mobileUrl: `https://m.miyoushe.com/ys/#/article/${data.post_id}`,
|
||||||
};
|
};
|
||||||
|
|||||||
206
src/routes/github.ts
Normal file
206
src/routes/github.ts
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
// getTrending.ts
|
||||||
|
import fetch from "node-fetch";
|
||||||
|
import * as cheerio from "cheerio";
|
||||||
|
import { ListContext } from "../types";
|
||||||
|
import logger from "../utils/logger.js";
|
||||||
|
import { getCache, setCache } from "../utils/cache.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义 Trending 仓库信息的类型
|
||||||
|
*/
|
||||||
|
type RepoInfo = {
|
||||||
|
owner: string; // 仓库所属者
|
||||||
|
repo: string; // 仓库名称
|
||||||
|
url: string; // 仓库链接
|
||||||
|
description: string; // 仓库描述
|
||||||
|
language: string; // 编程语言
|
||||||
|
stars: string; // Stars (由于可能包含逗号或者其他符号,这里先用 string 存;实际可自行转 number)
|
||||||
|
forks: string; // Forks
|
||||||
|
todayStars?: string | number; // 今日 Star
|
||||||
|
};
|
||||||
|
|
||||||
|
type TrendingRepoInfo = {
|
||||||
|
data: RepoInfo[];
|
||||||
|
updateTime: string;
|
||||||
|
fromCache: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type TrendingType = "daily" | "weekly" | "monthly";
|
||||||
|
|
||||||
|
const typeMap: Record<TrendingType, string> = {
|
||||||
|
daily: "日榜",
|
||||||
|
weekly: "周榜",
|
||||||
|
monthly: "月榜",
|
||||||
|
};
|
||||||
|
|
||||||
|
function isTrendingType(value: string): value is TrendingType {
|
||||||
|
return ["daily", "weekly", "monthly"].includes(value as TrendingType);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handleRoute = async (c: ListContext) => {
|
||||||
|
const typeParam = c.req.query("type") || "daily";
|
||||||
|
const type = isTrendingType(typeParam) ? typeParam : "daily";
|
||||||
|
|
||||||
|
const listData = await getTrendingRepos(type);
|
||||||
|
|
||||||
|
const routeData = {
|
||||||
|
name: "github",
|
||||||
|
title: "github 趋势",
|
||||||
|
type: typeMap[type],
|
||||||
|
params: {
|
||||||
|
type: {
|
||||||
|
name: '排行榜分区',
|
||||||
|
type: typeMap,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
link: `https://github.com/trending?since=${type}`,
|
||||||
|
total: listData?.data?.length || 0,
|
||||||
|
...{
|
||||||
|
...listData,
|
||||||
|
data: listData?.data?.map((v, index)=>{
|
||||||
|
return {
|
||||||
|
id:index,
|
||||||
|
title: v.repo,
|
||||||
|
desc: v.description,
|
||||||
|
hot: v.stars,
|
||||||
|
...v
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 爬取 GitHub Trending 列表
|
||||||
|
* @param since 可选参数: 'daily' | 'weekly' | 'monthly',默认值为 'daily'
|
||||||
|
* @returns Promise<RepoInfo[]> 返回包含热门项目信息的数组
|
||||||
|
*/
|
||||||
|
export async function getTrendingRepos(
|
||||||
|
type: TrendingType | string = "daily",
|
||||||
|
ttl = 60 * 60 * 24,
|
||||||
|
): Promise<TrendingRepoInfo> {
|
||||||
|
const url = `https://github.com/trending?since=${type}`;
|
||||||
|
// 先从缓存中取
|
||||||
|
const cachedData = await getCache(url);
|
||||||
|
if (cachedData) {
|
||||||
|
logger.info("💾 [CHCHE] The request is cached");
|
||||||
|
return {
|
||||||
|
fromCache: true,
|
||||||
|
updateTime: cachedData.updateTime,
|
||||||
|
data: (cachedData?.data as RepoInfo[]) || [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
logger.info(`🌐 [GET] ${url}`);
|
||||||
|
|
||||||
|
// 更新请求头
|
||||||
|
const headers = {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
|
||||||
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
||||||
|
'Accept-Language': 'en-US,en;q=0.5',
|
||||||
|
'Accept-Encoding': 'gzip, deflate, br',
|
||||||
|
'Connection': 'keep-alive',
|
||||||
|
'Upgrade-Insecure-Requests': '1',
|
||||||
|
'Sec-Fetch-Dest': 'document',
|
||||||
|
'Sec-Fetch-Mode': 'navigate',
|
||||||
|
'Sec-Fetch-Site': 'none',
|
||||||
|
'Sec-Fetch-User': '?1',
|
||||||
|
'Cache-Control': 'max-age=0',
|
||||||
|
};
|
||||||
|
|
||||||
|
// 添加重试逻辑
|
||||||
|
const maxRetries = 3;
|
||||||
|
let lastError;
|
||||||
|
|
||||||
|
for (let i = 0; i < maxRetries; i++) {
|
||||||
|
try {
|
||||||
|
// 设置超时时间为 20 秒
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timeout = setTimeout(() => controller.abort(), 20000);
|
||||||
|
|
||||||
|
const response = await fetch(url, {
|
||||||
|
headers,
|
||||||
|
signal: controller.signal
|
||||||
|
});
|
||||||
|
clearTimeout(timeout);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const html = await response.text();
|
||||||
|
// 1. 加载 HTML
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
// 2. 存储结果的数组
|
||||||
|
const results: RepoInfo[] = [];
|
||||||
|
// 3. 遍历每个 article.Box-row
|
||||||
|
$("article.Box-row").each((_, el) => {
|
||||||
|
const $el = $(el);
|
||||||
|
// 仓库标题和链接 (在 <h2> > <a> 里)
|
||||||
|
const $repoAnchor = $el.find("h2 a");
|
||||||
|
// 可能出现 "owner / repo" 这种文本
|
||||||
|
// eg: "owner / repo"
|
||||||
|
const fullNameText = $repoAnchor
|
||||||
|
.text()
|
||||||
|
.trim()
|
||||||
|
// 可能有多余空格,可以再做一次 split
|
||||||
|
// "owner / repo" => ["owner", "repo"]
|
||||||
|
.replace(/\r?\n/g, "") // 去掉换行
|
||||||
|
.replace(/\s+/g, " ") // 多空格处理
|
||||||
|
.split("/")
|
||||||
|
.map((s) => s.trim());
|
||||||
|
|
||||||
|
const owner = fullNameText[0] || "";
|
||||||
|
const repoName = fullNameText[1] || "";
|
||||||
|
|
||||||
|
// href 即仓库链接
|
||||||
|
const repoUrl = "https://github.com" + $repoAnchor.attr("href");
|
||||||
|
|
||||||
|
// 仓库描述 (<p class="col-9 color-fg-muted ...">)
|
||||||
|
const description = $el.find("p.col-9.color-fg-muted").text().trim();
|
||||||
|
|
||||||
|
// 语言 (<span itemprop="programmingLanguage">)
|
||||||
|
const language = $el.find('[itemprop="programmingLanguage"]').text().trim();
|
||||||
|
|
||||||
|
const starsText = $el.find('a[href$="/stargazers"]').text().trim();
|
||||||
|
|
||||||
|
const forksText = $el.find(`a[href$="/forks"]`).text().trim();
|
||||||
|
|
||||||
|
// 整合
|
||||||
|
results.push({
|
||||||
|
owner,
|
||||||
|
repo: repoName,
|
||||||
|
url: repoUrl || "",
|
||||||
|
description,
|
||||||
|
language,
|
||||||
|
stars: starsText,
|
||||||
|
forks: forksText,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const updateTime = new Date().toISOString();
|
||||||
|
const data = results;
|
||||||
|
|
||||||
|
await setCache(url, { data, updateTime }, ttl);
|
||||||
|
// 返回数据
|
||||||
|
logger.info(`✅ [${response?.status}] 请求成功!`);
|
||||||
|
return { fromCache: false, updateTime, data };
|
||||||
|
} catch (error: Error | unknown) {
|
||||||
|
lastError = error;
|
||||||
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||||
|
logger.error(`❌ [ERROR] 第 ${i + 1} 请求失败: ${errorMessage}`);
|
||||||
|
|
||||||
|
// 如果是最后一次重试,则抛出错误
|
||||||
|
if (i === maxRetries - 1) {
|
||||||
|
logger.error("❌ [ERROR] 所有尝试请求失败!");
|
||||||
|
throw lastError;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 等待一段时间后重试 (1秒、2秒、4秒...)
|
||||||
|
await new Promise(resolve => setTimeout(resolve, Math.pow(2, i) * 1000));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error("请求失败!");
|
||||||
|
}
|
||||||
45
src/routes/guokr.ts
Normal file
45
src/routes/guokr.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import type { RouterData } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
|
const listData = await getList(noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "guokr",
|
||||||
|
title: "果壳",
|
||||||
|
type: "热门文章",
|
||||||
|
description: "科技有意思",
|
||||||
|
link: "https://www.guokr.com/",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (noCache: boolean) => {
|
||||||
|
const url = `https://www.guokr.com/beta/proxy/science_api/articles?limit=30`;
|
||||||
|
const result = await get({
|
||||||
|
url,
|
||||||
|
noCache,
|
||||||
|
headers: {
|
||||||
|
"User-Agent":
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const list = result.data;
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v: RouterType["guokr"]) => ({
|
||||||
|
id: v.id,
|
||||||
|
title: v.title,
|
||||||
|
desc: v.summary,
|
||||||
|
cover: v.small_image,
|
||||||
|
author: v.author?.nickname,
|
||||||
|
hot: undefined,
|
||||||
|
timestamp: getTime(v.date_modified),
|
||||||
|
url: `https://www.guokr.com/article/${v.id}`,
|
||||||
|
mobileUrl: `https://m.guokr.com/article/${v.id}`,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
63
src/routes/hackernews.ts
Normal file
63
src/routes/hackernews.ts
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import type { RouterData } from "../types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { load } from "cheerio";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
|
||||||
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
|
const listData = await getList(noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "hackernews",
|
||||||
|
title: "Hacker News",
|
||||||
|
type: "Popular",
|
||||||
|
description: "News about hacking and startups",
|
||||||
|
link: "https://news.ycombinator.com/",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (noCache: boolean) => {
|
||||||
|
const baseUrl = "https://news.ycombinator.com";
|
||||||
|
const result = await get({
|
||||||
|
url: baseUrl,
|
||||||
|
noCache,
|
||||||
|
headers: {
|
||||||
|
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const $ = load(result.data);
|
||||||
|
const stories: RouterType["hackernews"][] = [];
|
||||||
|
|
||||||
|
$(".athing").each((_, el) => {
|
||||||
|
const item = $(el);
|
||||||
|
const id = item.attr("id") || "";
|
||||||
|
const title = item.find(".titleline a").first().text().trim();
|
||||||
|
const url = item.find(".titleline a").first().attr("href");
|
||||||
|
|
||||||
|
// 获取分数并转换为数字
|
||||||
|
const scoreText = $(`#score_${id}`).text().match(/\d+/)?.[0];
|
||||||
|
const hot = scoreText ? parseInt(scoreText, 10) : undefined;
|
||||||
|
|
||||||
|
if (id && title) {
|
||||||
|
stories.push({
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
hot,
|
||||||
|
timestamp: undefined,
|
||||||
|
url: url || `${baseUrl}/item?id=${id}`,
|
||||||
|
mobileUrl: url || `${baseUrl}/item?id=${id}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: stories,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(`Failed to parse HackerNews HTML: ${error}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,30 +1,28 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
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") || "hot";
|
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",
|
||||||
type: "热门仓库",
|
type: "热门仓库",
|
||||||
description: "分享 GitHub 上有趣、入门级的开源项目",
|
description: "分享 GitHub 上有趣、入门级的开源项目",
|
||||||
parameData: {
|
params: {
|
||||||
sort: {
|
sort: {
|
||||||
name: "排行榜分区",
|
name: "排行榜分区",
|
||||||
type: {
|
type: {
|
||||||
hot: "热门",
|
featured: "精选",
|
||||||
last: "最新",
|
all: "全部",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
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,
|
||||||
|
|||||||
53
src/routes/history.ts
Normal file
53
src/routes/history.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import { load } from "cheerio";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getCurrentDateTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
|
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 listData = await getList({ month, day }, noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "history",
|
||||||
|
title: "历史上的今天",
|
||||||
|
type: `${month}-${day}`,
|
||||||
|
params: {
|
||||||
|
month: "月份",
|
||||||
|
day: "日期",
|
||||||
|
},
|
||||||
|
link: "https://baike.baidu.com/calendar",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
const getList = async (options: Options, noCache: boolean) => {
|
||||||
|
const { month, day } = options;
|
||||||
|
const monthStr = month?.toString().padStart(2, "0");
|
||||||
|
const dayStr = day?.toString().padStart(2, "0");
|
||||||
|
const url = `https://baike.baidu.com/cms/home/eventsOnHistory/${monthStr}.json`;
|
||||||
|
const result = await get({
|
||||||
|
url,
|
||||||
|
noCache,
|
||||||
|
params: {
|
||||||
|
_: new Date().getTime(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const list = monthStr ? result.data[monthStr][monthStr + dayStr] : [];
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v: RouterType["history"], index: number) => ({
|
||||||
|
id: index,
|
||||||
|
title: load(v.title).text().trim(),
|
||||||
|
cover: v.cover ? v.pic_share : undefined,
|
||||||
|
desc: load(v.desc).text().trim(),
|
||||||
|
year: v.year,
|
||||||
|
timestamp: undefined,
|
||||||
|
hot: undefined,
|
||||||
|
url: v.link,
|
||||||
|
mobileUrl: v.link,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
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",
|
||||||
type: "最新动态",
|
type: "最新动态",
|
||||||
parameData: {
|
params: {
|
||||||
type: {
|
type: {
|
||||||
name: "榜单分类",
|
name: "榜单分类",
|
||||||
type: {
|
type: {
|
||||||
@@ -21,32 +21,29 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (options: Options, noCache: boolean) => {
|
const getList = async (options: Options, noCache: boolean) => {
|
||||||
const { type } = options;
|
const { type } = options;
|
||||||
const url = `https://bbs-api.miyoushe.com/post/wapi/getNewsList?gids=1&page_size=20&type=${type}`;
|
const url = `https://bbs-api-static.miyoushe.com/painter/wapi/getNewsList?client_type=4&gids=1&last_id=&page_size=20&type=${type}`;
|
||||||
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 {
|
||||||
id: data.post_id,
|
id: data.post_id,
|
||||||
title: data.subject,
|
title: data.subject,
|
||||||
desc: data.content,
|
desc: data.content,
|
||||||
cover: data.cover || v.image_list[0].url,
|
cover: data.cover || data?.images?.[0],
|
||||||
author: v.user.nickname,
|
author: v.user?.nickname || undefined,
|
||||||
timestamp: getTime(data.created_at),
|
timestamp: getTime(data.created_at),
|
||||||
hot: v.stat.view_num,
|
hot: data.view_status,
|
||||||
url: `https://www.miyoushe.com/bh3/article/${data.post_id}`,
|
url: `https://www.miyoushe.com/bh3/article/${data.post_id}`,
|
||||||
mobileUrl: `https://m.miyoushe.com/bh3/#/article/${data.post_id}`,
|
mobileUrl: `https://m.miyoushe.com/bh3/#/article/${data.post_id}`,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,32 +1,31 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import { get } from "../utils/getData.js";
|
||||||
import { web } from "../utils/getData.js";
|
import { parseRSS } from "../utils/parseRSS.js";
|
||||||
import { extractRss, parseRSS } from "../utils/parseRSS.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
import getTime from "../utils/getTime.js";
|
|
||||||
|
const typeMap: Record<string, string> = {
|
||||||
|
hot: "最新热门",
|
||||||
|
digest: "最新精华",
|
||||||
|
new: "最新回复",
|
||||||
|
newthread: "最新发表",
|
||||||
|
};
|
||||||
|
|
||||||
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: "全球主机交流",
|
||||||
type: "榜单",
|
type: typeMap[type],
|
||||||
parameData: {
|
params: {
|
||||||
type: {
|
type: {
|
||||||
name: "榜单分类",
|
name: "榜单分类",
|
||||||
type: {
|
type: typeMap,
|
||||||
hot: "最新热门",
|
|
||||||
digest: "最新精华",
|
|
||||||
new: "最新回复",
|
|
||||||
newthread: "最新发表",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
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;
|
||||||
};
|
};
|
||||||
@@ -34,33 +33,26 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
const getList = async (options: Options, noCache: boolean) => {
|
const getList = async (options: Options, noCache: boolean) => {
|
||||||
const { type } = options;
|
const { type } = options;
|
||||||
const url = `https://hostloc.com/forum.php?mod=guide&view=${type}&rss=1`;
|
const url = `https://hostloc.com/forum.php?mod=guide&view=${type}&rss=1`;
|
||||||
const result = await web({
|
const result = await get({
|
||||||
url,
|
url,
|
||||||
noCache,
|
noCache,
|
||||||
userAgent:
|
headers: {
|
||||||
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36",
|
userAgent:
|
||||||
|
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const parseData = async () => {
|
const list = await parseRSS(result.data);
|
||||||
if (typeof result?.data === "string") {
|
|
||||||
const rssContent = extractRss(result.data);
|
|
||||||
return await parseRSS(rssContent);
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const list = await parseData();
|
|
||||||
return {
|
return {
|
||||||
fromCache: result.fromCache,
|
...result,
|
||||||
updateTime: result.updateTime,
|
data: list.map((v, i) => ({
|
||||||
data: list.map((v: RouterType["discuz"]) => ({
|
id: v.guid || i,
|
||||||
id: v.guid,
|
title: v.title || "",
|
||||||
title: v.title,
|
desc: v.content || "",
|
||||||
desc: v.content,
|
author: v.author || "",
|
||||||
author: v.author,
|
timestamp: getTime(v.pubDate || 0),
|
||||||
timestamp: getTime(v.pubDate),
|
hot: undefined,
|
||||||
hot: null,
|
url: v.link || "",
|
||||||
url: v.link,
|
mobileUrl: v.link || "",
|
||||||
mobileUrl: v.link,
|
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
48
src/routes/hupu.ts
Normal file
48
src/routes/hupu.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
|
||||||
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
|
const type = c.req.query("type") || "1";
|
||||||
|
const listData = await getList({ type }, noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "hupu",
|
||||||
|
title: "虎扑",
|
||||||
|
type: "步行街热帖",
|
||||||
|
params: {
|
||||||
|
type: {
|
||||||
|
name: "榜单分类",
|
||||||
|
type: {
|
||||||
|
1: "主干道",
|
||||||
|
6: "恋爱区",
|
||||||
|
11: "校园区",
|
||||||
|
12: "历史区",
|
||||||
|
612: "摄影区",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
link: "https://bbs.hupu.com/all-gambia",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (options: Options, noCache: boolean) => {
|
||||||
|
const { type } = options;
|
||||||
|
const url = `https://m.hupu.com/api/v2/bbs/topicThreads?topicId=${type}&page=1`;
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
const list = result.data.data.topicThreads;
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v: RouterType["hupu"]) => ({
|
||||||
|
id: v.tid,
|
||||||
|
title: v.title,
|
||||||
|
author: v.username,
|
||||||
|
hot: v.replies,
|
||||||
|
timestamp: undefined,
|
||||||
|
url: `https://bbs.hupu.com/${v.tid}.html`,
|
||||||
|
mobileUrl: v.url,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,19 +1,17 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
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;
|
||||||
};
|
};
|
||||||
@@ -21,7 +19,7 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
|
|||||||
// 标题处理
|
// 标题处理
|
||||||
const titleProcessing = (text: string) => {
|
const titleProcessing = (text: string) => {
|
||||||
const paragraphs = text.split("<br><br>");
|
const paragraphs = text.split("<br><br>");
|
||||||
const title = paragraphs.shift().replace(/。$/, "");
|
const title = paragraphs.shift()?.replace(/。$/, "");
|
||||||
const intro = paragraphs.join("<br><br>");
|
const intro = paragraphs.join("<br><br>");
|
||||||
return { title, intro };
|
return { title, intro };
|
||||||
};
|
};
|
||||||
@@ -38,17 +36,16 @@ 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,
|
||||||
desc: titleProcessing(v.content).intro,
|
desc: titleProcessing(v.content).intro,
|
||||||
author: v.user_info.username,
|
author: v.user_info.username,
|
||||||
timestamp: getTime(v.publish_time),
|
timestamp: getTime(v.publish_time),
|
||||||
hot: null,
|
hot: undefined,
|
||||||
url: v.url || "https://www.huxiu.com/moment/",
|
url: v.url || `https://www.huxiu.com/moment/${v.object_id}.html`,
|
||||||
mobileUrl: v.url || "https://m.huxiu.com/moment/",
|
mobileUrl: v.url || `https://m.huxiu.com/moment/${v.object_id}.html`,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
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,16 +22,15 @@ 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,
|
||||||
desc: v.post_content,
|
desc: v.post_content,
|
||||||
timestamp: getTime(v.created_at),
|
timestamp: getTime(v.created_at),
|
||||||
hot: v.like_count || v.comment_count,
|
hot: v.like_count || v.comment_count,
|
||||||
url: `https://www.ifanr.com/${v.id}` || v.buzz_original_url,
|
url: v.buzz_original_url || `https://www.ifanr.com/${v.post_id}`,
|
||||||
mobileUrl: `https://www.ifanr.com/digest/${v.id}` || v.buzz_original_url,
|
mobileUrl: v.buzz_original_url || `https://www.ifanr.com/digest/${v.post_id}`,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import { load } from "cheerio";
|
import { load } from "cheerio";
|
||||||
import { get } from "../utils/getData.js";
|
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;
|
||||||
};
|
};
|
||||||
@@ -38,21 +36,20 @@ const getList = async (noCache: boolean) => {
|
|||||||
const href = dom.find("a").attr("href");
|
const href = dom.find("a").attr("href");
|
||||||
const time = dom.find("span.time").text().trim();
|
const time = dom.find("span.time").text().trim();
|
||||||
const match = time.match(/'([^']+)'/);
|
const match = time.match(/'([^']+)'/);
|
||||||
const dateTime = match ? match[1] : null;
|
const dateTime = match ? match[1] : undefined;
|
||||||
return {
|
return {
|
||||||
id: href ? Number(replaceLink(href, true)) : 100000,
|
id: href ? Number(replaceLink(href, true)) : 100000,
|
||||||
title: dom.find(".newsbody h2").text().trim(),
|
title: dom.find(".newsbody h2").text().trim(),
|
||||||
desc: dom.find(".newsbody p").text().trim(),
|
desc: dom.find(".newsbody p").text().trim(),
|
||||||
cover: dom.find("img").attr("data-original"),
|
cover: dom.find("img").attr("data-original"),
|
||||||
timestamp: getTime(dateTime),
|
timestamp: getTime(dateTime || 0),
|
||||||
hot: Number(dom.find(".comment").text().replace(/\D/g, "")),
|
hot: Number(dom.find(".comment").text().replace(/\D/g, "")),
|
||||||
url: href || undefined,
|
url: href || "",
|
||||||
mobileUrl: href ? replaceLink(href) : undefined,
|
mobileUrl: href ? replaceLink(href) : "",
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
fromCache: result.fromCache,
|
...result,
|
||||||
updateTime: result.updateTime,
|
|
||||||
data: listData,
|
data: listData,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import { load } from "cheerio";
|
import { load } from "cheerio";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.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;
|
||||||
};
|
};
|
||||||
@@ -43,15 +42,14 @@ const getList = async (noCache: boolean) => {
|
|||||||
id: href ? Number(replaceLink(href, true)) : 100000,
|
id: href ? Number(replaceLink(href, true)) : 100000,
|
||||||
title: dom.find(".plc-title").text().trim(),
|
title: dom.find(".plc-title").text().trim(),
|
||||||
cover: dom.find("img").attr("data-original"),
|
cover: dom.find("img").attr("data-original"),
|
||||||
timestamp: dom.find("span.post-time").text().trim(),
|
timestamp: getTime(dom.find("span.post-time").text().trim()),
|
||||||
hot: Number(dom.find(".review-num").text().replace(/\D/g, "")),
|
hot: Number(dom.find(".review-num").text().replace(/\D/g, "")),
|
||||||
url: href ? replaceLink(href) : undefined,
|
url: href ? replaceLink(href) : "",
|
||||||
mobileUrl: href || undefined,
|
mobileUrl: href ? replaceLink(href) : "",
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
fromCache: result.fromCache,
|
...result,
|
||||||
updateTime: result.updateTime,
|
|
||||||
data: listData,
|
data: listData,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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;
|
||||||
};
|
};
|
||||||
@@ -45,15 +43,14 @@ const getList = async (noCache: boolean) => {
|
|||||||
cover: dom.find("img").attr("src"),
|
cover: dom.find("img").attr("src"),
|
||||||
desc: dom.find("p.abstract").text()?.trim(),
|
desc: dom.find("p.abstract").text()?.trim(),
|
||||||
author: dom.find("a.nickname").text()?.trim(),
|
author: dom.find("a.nickname").text()?.trim(),
|
||||||
hot: null,
|
hot: undefined,
|
||||||
timestamp: null,
|
timestamp: undefined,
|
||||||
url: `https://www.jianshu.com${href}`,
|
url: `https://www.jianshu.com${href}`,
|
||||||
mobileUrl: `https://www.jianshu.com${href}`,
|
mobileUrl: `https://www.jianshu.com${href}`,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
fromCache: result.fromCache,
|
...result,
|
||||||
updateTime: result.updateTime,
|
|
||||||
data: listData,
|
data: listData,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,35 +1,74 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { ListContext, RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
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) => {
|
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
const headers = {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
|
||||||
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||||
|
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
||||||
|
'Accept-Encoding': 'gzip, deflate, br',
|
||||||
|
'Cache-Control': 'no-cache',
|
||||||
|
'Connection': 'keep-alive',
|
||||||
|
'Sec-Ch-Ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"',
|
||||||
|
'Sec-Ch-Ua-Mobile': '?0',
|
||||||
|
'Sec-Ch-Ua-Platform': '"Windows"',
|
||||||
|
'Sec-Fetch-Dest': 'document',
|
||||||
|
'Sec-Fetch-Mode': 'navigate',
|
||||||
|
'Sec-Fetch-Site': 'same-origin',
|
||||||
|
'Sec-Fetch-User': '?1',
|
||||||
|
'Upgrade-Insecure-Requests': '1',
|
||||||
|
}
|
||||||
|
|
||||||
|
const category_url = 'https://api.juejin.cn/tag_api/v1/query_category_briefs'
|
||||||
|
const getCategory = async()=>{
|
||||||
|
const res = await get({
|
||||||
|
url: category_url,
|
||||||
|
headers
|
||||||
|
})
|
||||||
|
const data = res?.data?.data || []
|
||||||
|
const typeObj: Record<string, string> = {}
|
||||||
|
typeObj['1'] = '综合'
|
||||||
|
data.forEach((c: { category_id: string; category_name: string }) => {
|
||||||
|
typeObj[c.category_id] = c.category_name
|
||||||
|
})
|
||||||
|
|
||||||
|
return typeObj
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
|
const type = c.req.query("type") || 1;
|
||||||
|
const listData = await getList(noCache, type);
|
||||||
|
const typeMaps = await getCategory()
|
||||||
const routeData: RouterData = {
|
const routeData: RouterData = {
|
||||||
name: "juejin",
|
name: "juejin",
|
||||||
title: "稀土掘金",
|
title: "稀土掘金",
|
||||||
type: "文章榜",
|
type: "文章榜",
|
||||||
|
params: {
|
||||||
|
type: {
|
||||||
|
name: "排行榜分区",
|
||||||
|
type: typeMaps,
|
||||||
|
},
|
||||||
|
},
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (noCache: boolean) => {
|
const getList = async (noCache: boolean, type: number | string = 1) => {
|
||||||
const url = `https://api.juejin.cn/content_api/v1/content/article_rank?category_id=1&type=hot`;
|
const url = `https://api.juejin.cn/content_api/v1/content/article_rank?category_id=${type}&type=hot`;
|
||||||
const result = await get({ url, noCache });
|
const result = await get({ url, noCache, headers });
|
||||||
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,
|
||||||
author: v.author.name,
|
author: v.author.name,
|
||||||
hot: v.content_counter.hot_rank,
|
hot: v.content_counter.hot_rank,
|
||||||
timestamp: null,
|
timestamp: undefined,
|
||||||
url: `https://juejin.cn/post/${v.content.content_id}`,
|
url: `https://juejin.cn/post/${v.content.content_id}`,
|
||||||
mobileUrl: `https://juejin.cn/post/${v.content.content_id}`,
|
mobileUrl: `https://juejin.cn/post/${v.content.content_id}`,
|
||||||
})),
|
})),
|
||||||
|
|||||||
59
src/routes/kuaishou.ts
Normal file
59
src/routes/kuaishou.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import type { ListItem, RouterData } from "../types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { parseChineseNumber } from "../utils/getNum.js";
|
||||||
|
import UserAgent from "user-agents";
|
||||||
|
|
||||||
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
|
const listData = await getList(noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "kuaishou",
|
||||||
|
title: "快手",
|
||||||
|
type: "热榜",
|
||||||
|
description: "快手,拥抱每一种生活",
|
||||||
|
link: "https://www.kuaishou.com/",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (noCache: boolean) => {
|
||||||
|
const url = `https://www.kuaishou.com/?isHome=1`;
|
||||||
|
const userAgent = new UserAgent({
|
||||||
|
deviceCategory: "desktop",
|
||||||
|
});
|
||||||
|
const result = await get({
|
||||||
|
url,
|
||||||
|
noCache,
|
||||||
|
headers: {
|
||||||
|
"User-Agent": userAgent.toString(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const listData: ListItem[] = [];
|
||||||
|
// 获取主要内容
|
||||||
|
const pattern = /window.__APOLLO_STATE__=(.*);\(function\(\)/s;
|
||||||
|
const matchResult = result.data?.match(pattern);
|
||||||
|
const jsonObject = JSON.parse(matchResult[1])["defaultClient"];
|
||||||
|
// 获取所有分类
|
||||||
|
const allItems = jsonObject['$ROOT_QUERY.visionHotRank({"page":"home"})']["items"];
|
||||||
|
// 获取全部热榜
|
||||||
|
allItems?.forEach((item: { id: string }) => {
|
||||||
|
// 基础数据
|
||||||
|
const hotItem: RouterType["kuaishou"] = jsonObject[item.id];
|
||||||
|
const id = hotItem.photoIds?.json?.[0];
|
||||||
|
listData.push({
|
||||||
|
id: hotItem.id,
|
||||||
|
title: hotItem.name,
|
||||||
|
cover: decodeURIComponent(hotItem.poster),
|
||||||
|
hot: parseChineseNumber(hotItem.hotValue),
|
||||||
|
timestamp: undefined,
|
||||||
|
url: `https://www.kuaishou.com/short-video/${id}`,
|
||||||
|
mobileUrl: `https://www.kuaishou.com/short-video/${id}`,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: listData,
|
||||||
|
};
|
||||||
|
};
|
||||||
57
src/routes/linuxdo.ts
Normal file
57
src/routes/linuxdo.ts
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import type { RouterData } from "../types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
|
interface Topic {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
excerpt: string;
|
||||||
|
last_poster_username: string;
|
||||||
|
created_at: string;
|
||||||
|
views: number;
|
||||||
|
like_count: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
|
const listData = await getList(noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "linuxdo",
|
||||||
|
title: "Linux.do",
|
||||||
|
type: "热门文章",
|
||||||
|
description: "Linux 技术社区热搜",
|
||||||
|
link: "https://linux.do/hot",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (noCache: boolean) => {
|
||||||
|
const url = "https://linux.do/top/weekly.json";
|
||||||
|
const result = await get({
|
||||||
|
url,
|
||||||
|
noCache,
|
||||||
|
headers: {
|
||||||
|
"Accept": "application/json",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const topics = result.data.topic_list.topics as Topic[];
|
||||||
|
const list = topics.map((topic) => {
|
||||||
|
return {
|
||||||
|
id: topic.id,
|
||||||
|
title: topic.title,
|
||||||
|
desc: topic.excerpt,
|
||||||
|
author: topic.last_poster_username,
|
||||||
|
timestamp: getTime(topic.created_at),
|
||||||
|
url: `https://linux.do/t/${topic.id}`,
|
||||||
|
mobileUrl: `https://linux.do/t/${topic.id}`,
|
||||||
|
hot: topic.views || topic.like_count
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,19 +1,17 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
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,
|
||||||
|
|||||||
72
src/routes/miyoushe.ts
Normal file
72
src/routes/miyoushe.ts
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import type { RouterData, ListContext, Options, RouterResType } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
|
// 游戏分类
|
||||||
|
const gameMap: Record<string, string> = {
|
||||||
|
"1": "崩坏3",
|
||||||
|
"2": "原神",
|
||||||
|
"3": "崩坏学园2",
|
||||||
|
"4": "未定事件簿",
|
||||||
|
"5": "大别野",
|
||||||
|
"6": "崩坏:星穹铁道",
|
||||||
|
"7": "暂无",
|
||||||
|
"8": "绝区零",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 榜单分类
|
||||||
|
const typeMap: Record<string, string> = {
|
||||||
|
"1": "公告",
|
||||||
|
"2": "活动",
|
||||||
|
"3": "资讯",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
|
const game = c.req.query("game") || "1";
|
||||||
|
const type = c.req.query("type") || "1";
|
||||||
|
const listData = await getList({ game, type }, noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "miyoushe",
|
||||||
|
title: `米游社 · ${gameMap[game]}`,
|
||||||
|
type: `最新${typeMap[type]}`,
|
||||||
|
params: {
|
||||||
|
game: {
|
||||||
|
name: "游戏分类",
|
||||||
|
type: gameMap,
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
name: "榜单分类",
|
||||||
|
type: typeMap,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
link: "https://www.miyoushe.com/",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (options: Options, noCache: boolean): Promise<RouterResType> => {
|
||||||
|
const { game, type } = options;
|
||||||
|
const url = `https://bbs-api-static.miyoushe.com/painter/wapi/getNewsList?client_type=4&gids=${game}&last_id=&page_size=30&type=${type}`;
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
const list = result.data.data.list;
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v: RouterType["miyoushe"]) => {
|
||||||
|
const data = v.post;
|
||||||
|
return {
|
||||||
|
id: data.post_id,
|
||||||
|
title: data.subject,
|
||||||
|
desc: data.content,
|
||||||
|
cover: data.cover || data?.images?.[0],
|
||||||
|
author: v.user?.nickname || undefined,
|
||||||
|
timestamp: getTime(data.created_at),
|
||||||
|
hot: data.view_status || 0,
|
||||||
|
url: `https://www.miyoushe.com/ys/article/${data.post_id}`,
|
||||||
|
mobileUrl: `https://m.miyoushe.com/ys/#/article/${data.post_id}`,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,19 +1,17 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
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,14 +21,13 @@ 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,
|
||||||
cover: v.imgsrc,
|
cover: v.imgsrc,
|
||||||
author: v.source,
|
author: v.source,
|
||||||
hot: null,
|
hot: undefined,
|
||||||
timestamp: getTime(v.ptime),
|
timestamp: getTime(v.ptime),
|
||||||
url: `https://www.163.com/dy/article/${v.docid}.html`,
|
url: `https://www.163.com/dy/article/${v.docid}.html`,
|
||||||
mobileUrl: `https://m.163.com/dy/article/${v.docid}.html`,
|
mobileUrl: `https://m.163.com/dy/article/${v.docid}.html`,
|
||||||
|
|||||||
42
src/routes/newsmth.ts
Normal file
42
src/routes/newsmth.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import type { RouterData } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
|
const listData = await getList(noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "newsmth",
|
||||||
|
title: "水木社区",
|
||||||
|
type: "热门话题",
|
||||||
|
description: "水木社区是一个源于清华的高知社群。",
|
||||||
|
link: "https://www.newsmth.net/",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (noCache: boolean) => {
|
||||||
|
const url = `https://wap.newsmth.net/wap/api/hot/global`;
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
const list = result.data?.data?.topics;
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v: RouterType["newsmth"]) => {
|
||||||
|
const post = v.article;
|
||||||
|
const url = `https://wap.newsmth.net/article/${post.topicId}?title=${v.board?.title}&from=home`;
|
||||||
|
return {
|
||||||
|
id: v.firstArticleId,
|
||||||
|
title: post.subject,
|
||||||
|
desc: post.body,
|
||||||
|
cover: undefined,
|
||||||
|
author: post?.account?.name,
|
||||||
|
hot: undefined,
|
||||||
|
timestamp: getTime(post.postTime),
|
||||||
|
url,
|
||||||
|
mobileUrl: url,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,20 +1,18 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { post } from "../utils/getData.js";
|
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,
|
||||||
|
|||||||
44
src/routes/nodeseek.ts
Normal file
44
src/routes/nodeseek.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import type { RouterData } from "../types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
import { parseRSS } from "../utils/parseRSS.js";
|
||||||
|
|
||||||
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
|
const listData = await getList(noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "nodeseek",
|
||||||
|
title: "NodeSeek",
|
||||||
|
type: "最新",
|
||||||
|
params: {
|
||||||
|
type: {
|
||||||
|
name: "分类",
|
||||||
|
type: {
|
||||||
|
all: "所有",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
link: "https://www.nodeseek.com/",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (noCache: boolean) => {
|
||||||
|
const url = `https://rss.nodeseek.com/`;
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
const list = await parseRSS(result.data);
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v, i) => ({
|
||||||
|
id: v.guid || i,
|
||||||
|
title: v.title || "",
|
||||||
|
desc: v.content?.trim() || "",
|
||||||
|
author: v.author,
|
||||||
|
timestamp: getTime(v.pubDate || 0),
|
||||||
|
hot: undefined,
|
||||||
|
url: v.link || "",
|
||||||
|
mobileUrl: v.link || "",
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
59
src/routes/nytimes.ts
Normal file
59
src/routes/nytimes.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import type { RouterData, ListContext, Options, RouterResType } from "../types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
import { parseRSS } from "../utils/parseRSS.js";
|
||||||
|
|
||||||
|
const areaMap: Record<string, string> = {
|
||||||
|
china: "中文网",
|
||||||
|
global: "全球版",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
|
const area = c.req.query("type") || "china";
|
||||||
|
const listData = await getList({ area }, noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "nytimes",
|
||||||
|
title: "纽约时报",
|
||||||
|
type: areaMap[area],
|
||||||
|
params: {
|
||||||
|
area: {
|
||||||
|
name: "地区分类",
|
||||||
|
type: areaMap,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
link: "https://www.nytimes.com/",
|
||||||
|
total: listData?.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (options: Options, noCache: boolean): Promise<RouterResType> => {
|
||||||
|
const { area } = options;
|
||||||
|
const url =
|
||||||
|
area === "china"
|
||||||
|
? "https://cn.nytimes.com/rss/"
|
||||||
|
: "https://rss.nytimes.com/services/xml/rss/nyt/World.xml";
|
||||||
|
const result = await get({
|
||||||
|
url,
|
||||||
|
noCache,
|
||||||
|
headers: {
|
||||||
|
userAgent:
|
||||||
|
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const list = await parseRSS(result.data);
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v, i) => ({
|
||||||
|
id: v.guid || i,
|
||||||
|
title: v.title || "",
|
||||||
|
desc: v.content?.trim() || "",
|
||||||
|
author: v.author,
|
||||||
|
timestamp: getTime(v.pubDate || 0),
|
||||||
|
hot: undefined,
|
||||||
|
url: v.link || "",
|
||||||
|
mobileUrl: v.link || "",
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
60
src/routes/producthunt.ts
Normal file
60
src/routes/producthunt.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import type { RouterData } from "../types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { load } from "cheerio";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
|
||||||
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
|
const listData = await getList(noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "producthunt",
|
||||||
|
title: "Product Hunt",
|
||||||
|
type: "Today",
|
||||||
|
description: "The best new products, every day",
|
||||||
|
link: "https://www.producthunt.com/",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (noCache: boolean) => {
|
||||||
|
const baseUrl = "https://www.producthunt.com";
|
||||||
|
const result = await get({
|
||||||
|
url: baseUrl,
|
||||||
|
noCache,
|
||||||
|
headers: {
|
||||||
|
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const $ = load(result.data);
|
||||||
|
const stories: RouterType["producthunt"][] = [];
|
||||||
|
|
||||||
|
$("[data-test=homepage-section-0] [data-test^=post-item]").each((_, el) => {
|
||||||
|
const a = $(el).find("a").first();
|
||||||
|
const path = a.attr("href");
|
||||||
|
const title = $(el).find("a[data-test^=post-name]").text().trim();
|
||||||
|
const id = $(el).attr("data-test")?.replace("post-item-", "");
|
||||||
|
const vote = $(el).find("[data-test=vote-button]").text().trim();
|
||||||
|
|
||||||
|
if (path && id && title) {
|
||||||
|
stories.push({
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
hot: parseInt(vote) || undefined,
|
||||||
|
timestamp: undefined,
|
||||||
|
url: `${baseUrl}${path}`,
|
||||||
|
mobileUrl: `${baseUrl}${path}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: stories,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(`Failed to parse Product Hunt HTML: ${error}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,19 +1,17 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
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,
|
||||||
|
|||||||
134
src/routes/sina-news.ts
Normal file
134
src/routes/sina-news.ts
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import { getTime, getCurrentDateTime } from "../utils/getTime.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
|
||||||
|
// 榜单类别
|
||||||
|
const listType = {
|
||||||
|
"1": {
|
||||||
|
name: "总排行",
|
||||||
|
www: "news",
|
||||||
|
params: "www_www_all_suda_suda",
|
||||||
|
},
|
||||||
|
"2": {
|
||||||
|
name: "视频排行",
|
||||||
|
www: "news",
|
||||||
|
params: "video_news_all_by_vv",
|
||||||
|
},
|
||||||
|
"3": {
|
||||||
|
name: "图片排行",
|
||||||
|
www: "news",
|
||||||
|
params: "total_slide_suda",
|
||||||
|
},
|
||||||
|
"4": {
|
||||||
|
name: "国内新闻",
|
||||||
|
www: "news",
|
||||||
|
params: "news_china_suda",
|
||||||
|
},
|
||||||
|
"5": {
|
||||||
|
name: "国际新闻",
|
||||||
|
www: "news",
|
||||||
|
params: "news_world_suda",
|
||||||
|
},
|
||||||
|
"6": {
|
||||||
|
name: "社会新闻",
|
||||||
|
www: "news",
|
||||||
|
params: "news_society_suda",
|
||||||
|
},
|
||||||
|
"7": {
|
||||||
|
name: "体育新闻",
|
||||||
|
www: "sports",
|
||||||
|
params: "sports_suda",
|
||||||
|
},
|
||||||
|
"8": {
|
||||||
|
name: "财经新闻",
|
||||||
|
www: "finance",
|
||||||
|
params: "finance_0_suda",
|
||||||
|
},
|
||||||
|
"9": {
|
||||||
|
name: "娱乐新闻",
|
||||||
|
www: "ent",
|
||||||
|
params: "ent_suda",
|
||||||
|
},
|
||||||
|
"10": {
|
||||||
|
name: "科技新闻",
|
||||||
|
www: "tech",
|
||||||
|
params: "tech_news_suda",
|
||||||
|
},
|
||||||
|
"11": {
|
||||||
|
name: "军事新闻",
|
||||||
|
www: "news",
|
||||||
|
params: "news_mil_suda",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
|
const type = c.req.query("type") || "1";
|
||||||
|
const listData = await getList({ type }, noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "sina-news",
|
||||||
|
title: "新浪新闻",
|
||||||
|
type: listType[type as keyof typeof listType].name,
|
||||||
|
params: {
|
||||||
|
type: {
|
||||||
|
name: "榜单分类",
|
||||||
|
type: Object.fromEntries(Object.entries(listType).map(([key, value]) => [key, value.name])),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
link: "https://sinanews.sina.cn/",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
// JSONP 处理
|
||||||
|
const parseData = (data: string) => {
|
||||||
|
// 移除前后多余空白
|
||||||
|
if (!data) throw new Error("Input data is empty or invalid");
|
||||||
|
// 提取 JSON 字符串部分
|
||||||
|
const prefix = "var data = ";
|
||||||
|
if (!data.startsWith(prefix))
|
||||||
|
throw new Error("Input data does not start with the expected prefix");
|
||||||
|
let jsonString = data.slice(prefix.length).trim();
|
||||||
|
// 确保字符串以 ';' 结尾并移除它
|
||||||
|
if (jsonString.endsWith(";")) {
|
||||||
|
jsonString = jsonString.slice(0, -1).trim();
|
||||||
|
} else {
|
||||||
|
throw new Error("Input data does not end with a semicolon");
|
||||||
|
}
|
||||||
|
// 格式是否正确
|
||||||
|
if (jsonString.startsWith("{") && jsonString.endsWith("}")) {
|
||||||
|
// 解析为 JSON 对象
|
||||||
|
try {
|
||||||
|
const jsonData = JSON.parse(jsonString);
|
||||||
|
return jsonData;
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error("Failed to parse JSON: " + error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error("Invalid JSON format");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (options: Options, noCache: boolean) => {
|
||||||
|
const { type } = options;
|
||||||
|
// 必要数据
|
||||||
|
const { params, www } = listType[type as keyof typeof listType];
|
||||||
|
const { year, month, day } = getCurrentDateTime(true);
|
||||||
|
const url = `https://top.${www}.sina.com.cn/ws/GetTopDataList.php?top_type=day&top_cat=${params}&top_time=${year + month + day}&top_show_num=50`;
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
const list = parseData(result.data).data;
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v: RouterType["sina-news"]) => ({
|
||||||
|
id: v.id,
|
||||||
|
title: v.title,
|
||||||
|
author: v.media || undefined,
|
||||||
|
hot: parseFloat(v.top_num.replace(/,/g, "")),
|
||||||
|
timestamp: getTime(v.create_date + " " + v.create_time),
|
||||||
|
url: v.url,
|
||||||
|
mobileUrl: v.url,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
62
src/routes/sina.ts
Normal file
62
src/routes/sina.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import { parseChineseNumber } from "../utils/getNum.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
|
||||||
|
const typeMap: Record<string, string> = {
|
||||||
|
all: "新浪热榜",
|
||||||
|
hotcmnt: "热议榜",
|
||||||
|
minivideo: "视频热榜",
|
||||||
|
ent: "娱乐热榜",
|
||||||
|
ai: "AI热榜",
|
||||||
|
auto: "汽车热榜",
|
||||||
|
mother: "育儿热榜",
|
||||||
|
fashion: "时尚热榜",
|
||||||
|
travel: "旅游热榜",
|
||||||
|
esg: "ESG热榜",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
|
const type = c.req.query("type") || "all";
|
||||||
|
const listData = await getList({ type }, noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "sina",
|
||||||
|
title: "新浪网",
|
||||||
|
type: typeMap[type],
|
||||||
|
description: "热榜太多,一个就够",
|
||||||
|
params: {
|
||||||
|
type: {
|
||||||
|
name: "榜单分类",
|
||||||
|
type: typeMap,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
link: "https://sinanews.sina.cn/",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (options: Options, noCache: boolean) => {
|
||||||
|
const { type } = options;
|
||||||
|
const url = `https://newsapp.sina.cn/api/hotlist?newsId=HB-1-snhs%2Ftop_news_list-${type}`;
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
const list = result.data.data.hotList;
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v: RouterType["sina"]) => {
|
||||||
|
const base = v.base;
|
||||||
|
const info = v.info;
|
||||||
|
return {
|
||||||
|
id: base.base.uniqueId,
|
||||||
|
title: info.title,
|
||||||
|
desc: undefined,
|
||||||
|
author: undefined,
|
||||||
|
timestamp: undefined,
|
||||||
|
hot: parseChineseNumber(info.hotValue),
|
||||||
|
url: base.base.url,
|
||||||
|
mobileUrl: base.base.url,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
};
|
||||||
53
src/routes/smzdm.ts
Normal file
53
src/routes/smzdm.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import type { ListContext, Options, RouterData } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
|
const typeMap: Record<string, string> = {
|
||||||
|
"1": "今日热门",
|
||||||
|
"7": "周热门",
|
||||||
|
"30": "月热门",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
|
const type = c.req.query("type") || "1";
|
||||||
|
const listData = await getList({ type }, noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "smzdm",
|
||||||
|
title: "什么值得买",
|
||||||
|
type: typeMap[type],
|
||||||
|
description:
|
||||||
|
"什么值得买是一个中立的、致力于帮助广大网友买到更有性价比网购产品的最热门推荐网站。",
|
||||||
|
link: "https://www.smzdm.com/top/",
|
||||||
|
params: {
|
||||||
|
type: {
|
||||||
|
name: "文章分类",
|
||||||
|
type: typeMap,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (options: Options, noCache: boolean) => {
|
||||||
|
const { type } = options;
|
||||||
|
const url = `https://post.smzdm.com/rank/json_more/?unit=${type}`;
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
const list = result.data.data;
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v: RouterType["smzdm"]) => ({
|
||||||
|
id: v.article_id,
|
||||||
|
title: v.title,
|
||||||
|
desc: v.content,
|
||||||
|
cover: v.pic_url,
|
||||||
|
author: v.nickname,
|
||||||
|
hot: Number(v.collection_count),
|
||||||
|
timestamp: getTime(v.time_sort),
|
||||||
|
url: v.jump_link,
|
||||||
|
mobileUrl: v.jump_link,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,26 +1,24 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
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: "少数派",
|
||||||
type: "热榜",
|
type: "热榜",
|
||||||
parameData: {
|
params: {
|
||||||
type: {
|
type: {
|
||||||
name: "分类",
|
name: "分类",
|
||||||
type: ["热门文章", "应用推荐", "生活方式", "效率技巧", "少数派播客"],
|
type: ["热门文章", "应用推荐", "生活方式", "效率技巧", "少数派播客"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
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,
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
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: "崩坏:星穹铁道",
|
||||||
type: "最新动态",
|
type: "最新动态",
|
||||||
parameData: {
|
params: {
|
||||||
type: {
|
type: {
|
||||||
name: "榜单分类",
|
name: "榜单分类",
|
||||||
type: {
|
type: {
|
||||||
@@ -21,32 +21,29 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (options: Options, noCache: boolean) => {
|
const getList = async (options: Options, noCache: boolean) => {
|
||||||
const { type } = options;
|
const { type } = options;
|
||||||
const url = `https://bbs-api.miyoushe.com/post/wapi/getNewsList?gids=6&page_size=20&type=${type}`;
|
const url = `https://bbs-api-static.miyoushe.com/painter/wapi/getNewsList?client_type=4&gids=6&page_size=20&type=${type}`;
|
||||||
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 {
|
||||||
id: data.post_id,
|
id: data.post_id,
|
||||||
title: data.subject,
|
title: data.subject,
|
||||||
desc: data.content,
|
desc: data.content,
|
||||||
cover: data.cover,
|
cover: data.cover || data?.images?.[0],
|
||||||
author: v.user.nickname,
|
author: v.user?.nickname || undefined,
|
||||||
timestamp: getTime(data.created_at),
|
timestamp: getTime(data.created_at),
|
||||||
hot: v.stat.view_num,
|
hot: data.view_status,
|
||||||
url: `https://www.miyoushe.com/sr/article/${data.post_id}`,
|
url: `https://www.miyoushe.com/sr/article/${data.post_id}`,
|
||||||
mobileUrl: `https://m.miyoushe.com/sr/#/article/${data.post_id}`,
|
mobileUrl: `https://m.miyoushe.com/sr/#/article/${data.post_id}`,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
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,
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
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,
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
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,
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ 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",
|
||||||
type: "主题榜",
|
type: "主题榜",
|
||||||
parameData: {
|
params: {
|
||||||
type: {
|
type: {
|
||||||
name: "榜单分类",
|
name: "榜单分类",
|
||||||
type: {
|
type: {
|
||||||
@@ -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;
|
||||||
};
|
};
|
||||||
@@ -31,16 +29,15 @@ const getList = async (options: Options, noCache: boolean) => {
|
|||||||
const { type } = options;
|
const { type } = options;
|
||||||
const url = `https://www.v2ex.com/api/topics/${type}.json`;
|
const url = `https://www.v2ex.com/api/topics/${type}.json`;
|
||||||
const result = await get({ url, noCache });
|
const result = await get({ url, noCache });
|
||||||
const list = result.data.data.list;
|
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,
|
||||||
desc: v.content,
|
desc: v.content,
|
||||||
author: v.member.username,
|
author: v.member.username,
|
||||||
timestamp: null,
|
timestamp: undefined,
|
||||||
hot: v.replies,
|
hot: v.replies,
|
||||||
url: v.url,
|
url: v.url,
|
||||||
mobileUrl: v.url,
|
mobileUrl: v.url,
|
||||||
|
|||||||
@@ -1,48 +1,42 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
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 || "全国"}气象预警`,
|
||||||
parameData: {
|
params: {
|
||||||
province: {
|
province: {
|
||||||
name: "预警区域",
|
name: "预警区域",
|
||||||
value: "省份名称( 例如:广东省 )",
|
value: "省份名称( 例如:广东省 )",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (options: Options, noCache: boolean) => {
|
const getList = async (options: Options, noCache: boolean) => {
|
||||||
const { province } = options;
|
const { province } = options;
|
||||||
const url = `http://www.nmc.cn/rest/findAlarm?pageNo=1&pageSize=20&signaltype=&signallevel=&province=${encodeURIComponent(province)}`;
|
const url = `http://www.nmc.cn/rest/findAlarm?pageNo=1&pageSize=20&signaltype=&signallevel=&province=${encodeURIComponent(province || "")}`;
|
||||||
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;
|
||||||
console.log(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,
|
||||||
desc: v.issuetime + " " + v.title,
|
desc: v.issuetime + " " + v.title,
|
||||||
cover: v.pic,
|
cover: v.pic,
|
||||||
timestamp: getTime(v.issuetime),
|
timestamp: getTime(v.issuetime),
|
||||||
hot: null,
|
hot: undefined,
|
||||||
url: `http://nmc.cn${v.url}`,
|
url: `http://nmc.cn${v.url}`,
|
||||||
mobileUrl: `http://nmc.cn${v.url}`,
|
mobileUrl: `http://nmc.cn${v.url}`,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -1,44 +1,52 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (noCache: boolean) => {
|
const getList = async (noCache: boolean) => {
|
||||||
const url = `https://weibo.com/ajax/side/hotSearch`;
|
const url =
|
||||||
const result = await get({ url, noCache, ttl: 60 });
|
"https://m.weibo.cn/api/container/getIndex?containerid=106003type%3D25%26t%3D3%26disable_hot%3D1%26filter_type%3Drealtimehot&title=%E5%BE%AE%E5%8D%9A%E7%83%AD%E6%90%9C&extparam=filter_type%3Drealtimehot%26mi_cid%3D100103%26pos%3D0_0%26c_type%3D30%26display_time%3D1540538388&luicode=10000011&lfid=231583";
|
||||||
const list = result.data.data.realtime;
|
|
||||||
|
const result = await get({
|
||||||
|
url,
|
||||||
|
noCache,
|
||||||
|
ttl: 60,
|
||||||
|
headers: {
|
||||||
|
Referer: "https://s.weibo.com/top/summary?cate=realtimehot",
|
||||||
|
"MWeibo-Pwa": "1",
|
||||||
|
"X-Requested-With": "XMLHttpRequest",
|
||||||
|
"User-Agent":
|
||||||
|
"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const list = result.data.data.cards?.[0]?.card_group;
|
||||||
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.desc}`;
|
||||||
return {
|
return {
|
||||||
id: v.mid,
|
id: v.itemid,
|
||||||
title: v.word,
|
title: v.desc,
|
||||||
desc: v.note || key,
|
desc: key,
|
||||||
author: v.category,
|
// author: v.flag_desc,
|
||||||
timestamp: getTime(v.onboard_time),
|
timestamp: getTime(v.onboard_time),
|
||||||
hot: v.raw_hot,
|
// hot: v.num,
|
||||||
url: `https://s.weibo.com/weibo?q=${encodeURIComponent(key)}&t=31&band_rank=1&Refer=top`,
|
url: `https://s.weibo.com/weibo?q=${encodeURIComponent(key)}&t=31&band_rank=1&Refer=top`,
|
||||||
mobileUrl: `https://s.weibo.com/weibo?q=${encodeURIComponent(
|
mobileUrl: v?.scheme,
|
||||||
key,
|
|
||||||
)}&t=31&band_rank=1&Refer=top`,
|
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,26 +1,39 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { ListContext, RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import getWereadID from "../utils/getToken/weread.js";
|
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) => {
|
const typeMap: Record<string, string> = {
|
||||||
const { fromCache, data, updateTime } = await getList(noCache);
|
rising: "飙升榜",
|
||||||
|
hot_search: "热搜榜",
|
||||||
|
newbook: "新书榜",
|
||||||
|
general_novel_rising: "小说榜",
|
||||||
|
all: "总榜",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||||
|
const type = c.req.query("type") || "rising";
|
||||||
|
const listData = await getList(noCache, type);
|
||||||
const routeData: RouterData = {
|
const routeData: RouterData = {
|
||||||
name: "weread",
|
name: "weread",
|
||||||
title: "微信读书",
|
title: "微信读书",
|
||||||
type: "飙升榜",
|
type: `${typeMap[type]}`,
|
||||||
|
params: {
|
||||||
|
type: {
|
||||||
|
name: "排行榜分区",
|
||||||
|
type: typeMap,
|
||||||
|
},
|
||||||
|
},
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (noCache: boolean) => {
|
const getList = async (noCache: boolean, type='rising') => {
|
||||||
const url = `https://weread.qq.com/web/bookListInCategory/rising?rank=1`;
|
const url = `https://weread.qq.com/web/bookListInCategory/${type}?rank=1`;
|
||||||
const result = await get({
|
const result = await get({
|
||||||
url,
|
url,
|
||||||
noCache,
|
noCache,
|
||||||
@@ -31,8 +44,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 {
|
||||||
|
|||||||
38
src/routes/yystv.ts
Normal file
38
src/routes/yystv.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import type { RouterData } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
|
import { get } from "../utils/getData.js";
|
||||||
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
|
||||||
|
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||||
|
const listData = await getList(noCache);
|
||||||
|
const routeData: RouterData = {
|
||||||
|
name: "yystv",
|
||||||
|
title: "游研社",
|
||||||
|
type: "全部文章",
|
||||||
|
description:
|
||||||
|
"游研社是以游戏内容为主的新媒体,出品内容包括大量游戏、动漫有关的研究文章和社长聊街机、社长说、游研剧场、老四强等系列视频内容。",
|
||||||
|
link: "https://www.yystv.cn/docs",
|
||||||
|
total: listData.data?.length || 0,
|
||||||
|
...listData,
|
||||||
|
};
|
||||||
|
return routeData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async (noCache: boolean) => {
|
||||||
|
const url = "https://www.yystv.cn/home/get_home_docs_by_page";
|
||||||
|
const result = await get({ url, noCache });
|
||||||
|
const list = result.data.data;
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: list.map((v: RouterType["yystv"]) => ({
|
||||||
|
id: v.id,
|
||||||
|
title: v.title,
|
||||||
|
cover: v.cover,
|
||||||
|
author: v.author,
|
||||||
|
hot: undefined,
|
||||||
|
timestamp: getTime(v.createtime),
|
||||||
|
url: `https://www.yystv.cn/p/${v.id}`,
|
||||||
|
mobileUrl: `https://www.yystv.cn/p/${v.id}`,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -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,15 +28,14 @@ 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,
|
||||||
cover: v.images[0],
|
cover: v.images?.[0] ?? undefined,
|
||||||
author: v.hint,
|
author: v.hint,
|
||||||
hot: null,
|
hot: undefined,
|
||||||
timestamp: null,
|
timestamp: undefined,
|
||||||
url: v.url,
|
url: v.url,
|
||||||
mobileUrl: v.url,
|
mobileUrl: v.url,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -1,41 +1,48 @@
|
|||||||
import type { RouterData } from "../types.js";
|
import type { RouterData } from "../types.js";
|
||||||
import type { RouterType } from "../router.types.js";
|
import type { RouterType } from "../router.types.js";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import getTime from "../utils/getTime.js";
|
import { getTime } from "../utils/getTime.js";
|
||||||
|
import { config } from "../config.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;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getList = async (noCache: boolean) => {
|
const getList = async (noCache: boolean) => {
|
||||||
const url = `https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=50&desktop=true`;
|
const url = `https://api.zhihu.com/topstory/hot-lists/total?limit=50`;
|
||||||
const result = await get({ url, noCache });
|
const result = await get({
|
||||||
|
url,
|
||||||
|
noCache,
|
||||||
|
...(config.ZHIHU_COOKIE && {
|
||||||
|
headers: {
|
||||||
|
Cookie: config.ZHIHU_COOKIE
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
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;
|
||||||
|
const questionId = data.url.split("/").pop();
|
||||||
return {
|
return {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
title: data.title,
|
title: data.title,
|
||||||
desc: data.excerpt,
|
desc: data.excerpt,
|
||||||
cover: v.children[0].thumbnail,
|
cover: v.children[0].thumbnail,
|
||||||
timestamp: getTime(data.created),
|
timestamp: getTime(data.created),
|
||||||
hot: parseInt(v.detail_text.replace(/[^\d]/g, "")) * 10000,
|
hot: parseFloat(v.detail_text.split(" ")[0]) * 10000,
|
||||||
url: `https://www.zhihu.com/question/${data.id}`,
|
url: `https://www.zhihu.com/question/${questionId}`,
|
||||||
mobileUrl: `https://www.zhihu.com/question/${data.id}`,
|
mobileUrl: `https://www.zhihu.com/question/${questionId}`,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
56
src/types.d.ts
vendored
56
src/types.d.ts
vendored
@@ -1,37 +1,43 @@
|
|||||||
import type { Context } from "hono";
|
import type { Context } from "hono";
|
||||||
|
import type { ResponseType } from "axios";
|
||||||
|
|
||||||
// Context
|
// Context
|
||||||
export type ListContext = Context;
|
export type ListContext = Context;
|
||||||
|
|
||||||
// 榜单数据
|
// 榜单数据
|
||||||
export type ListItem = {
|
export interface ListItem {
|
||||||
id: number | string;
|
id: number | string;
|
||||||
title: string;
|
title: string;
|
||||||
cover?: string;
|
cover?: string;
|
||||||
author?: string;
|
author?: string;
|
||||||
desc?: string;
|
desc?: string;
|
||||||
hot: number | null;
|
hot: number | undefined;
|
||||||
timestamp: number | string | null;
|
timestamp: number | undefined;
|
||||||
url: string | undefined;
|
url: string;
|
||||||
mobileUrl: string | undefined;
|
mobileUrl: string;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
// 路由接口数据
|
||||||
|
export interface RouterResType {
|
||||||
|
updateTime: string | number;
|
||||||
|
fromCache: boolean;
|
||||||
|
data: ListItem[];
|
||||||
|
message?: string;
|
||||||
|
}
|
||||||
|
|
||||||
// 路由数据
|
// 路由数据
|
||||||
export type RouterData = {
|
export interface RouterData extends RouterResType {
|
||||||
name: string;
|
name: string;
|
||||||
title: string;
|
title: string;
|
||||||
type: string;
|
type: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
parameData?: Record<string, string | object>;
|
params?: Record<string, string | object>;
|
||||||
total: number;
|
total: number;
|
||||||
link?: string;
|
link?: string;
|
||||||
updateTime: string;
|
}
|
||||||
fromCache: boolean;
|
|
||||||
data: ListItem[];
|
|
||||||
};
|
|
||||||
|
|
||||||
// 请求类型
|
// 请求类型
|
||||||
export type Get = {
|
export interface Get {
|
||||||
url: string;
|
url: string;
|
||||||
headers?: Record<string, string | string[]>;
|
headers?: Record<string, string | string[]>;
|
||||||
params?: Record<string, string | number>;
|
params?: Record<string, string | number>;
|
||||||
@@ -39,9 +45,10 @@ export type Get = {
|
|||||||
noCache?: boolean;
|
noCache?: boolean;
|
||||||
ttl?: number;
|
ttl?: number;
|
||||||
originaInfo?: boolean;
|
originaInfo?: boolean;
|
||||||
};
|
responseType?: ResponseType;
|
||||||
|
}
|
||||||
|
|
||||||
export type Post = {
|
export interface Post {
|
||||||
url: string;
|
url: string;
|
||||||
headers?: Record<string, string | string[]>;
|
headers?: Record<string, string | string[]>;
|
||||||
body?: string | object | Buffer | undefined;
|
body?: string | object | Buffer | undefined;
|
||||||
@@ -49,20 +56,9 @@ export type Post = {
|
|||||||
noCache?: boolean;
|
noCache?: boolean;
|
||||||
ttl?: number;
|
ttl?: number;
|
||||||
originaInfo?: boolean;
|
originaInfo?: boolean;
|
||||||
};
|
}
|
||||||
|
|
||||||
export type Web = {
|
|
||||||
url: string;
|
|
||||||
timeout?: number;
|
|
||||||
noCache?: boolean;
|
|
||||||
ttl?: number;
|
|
||||||
userAgent?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 参数类型
|
// 参数类型
|
||||||
export type Options = {
|
export interface Options {
|
||||||
[key: string]: string | undefined;
|
[key: string]: string | number | undefined;
|
||||||
};
|
}
|
||||||
|
|
||||||
// serveHotApi
|
|
||||||
export default function serveHotApi(port?: number): unknown;
|
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
import { config } from "../config.js";
|
import { config } from "../config.js";
|
||||||
import NodeCache from "node-cache";
|
import { stringify, parse } from "flatted";
|
||||||
import logger from "./logger.js";
|
import logger from "./logger.js";
|
||||||
|
import NodeCache from "node-cache";
|
||||||
|
import Redis from "ioredis";
|
||||||
|
|
||||||
// init
|
interface CacheData {
|
||||||
|
updateTime: string;
|
||||||
|
data: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
// init NodeCache
|
||||||
const cache = new NodeCache({
|
const cache = new NodeCache({
|
||||||
// 缓存过期时间( 秒 )
|
// 缓存过期时间( 秒 )
|
||||||
stdTTL: config.CACHE_TTL,
|
stdTTL: config.CACHE_TTL,
|
||||||
@@ -14,24 +21,125 @@ const cache = new NodeCache({
|
|||||||
maxKeys: 100,
|
maxKeys: 100,
|
||||||
});
|
});
|
||||||
|
|
||||||
interface GetCache<T> {
|
// init Redis client
|
||||||
updateTime: string;
|
const redis = new Redis({
|
||||||
data: T;
|
host: config.REDIS_HOST,
|
||||||
}
|
port: config.REDIS_PORT,
|
||||||
|
password: config.REDIS_PASSWORD,
|
||||||
|
maxRetriesPerRequest: 5,
|
||||||
|
// 重试策略:最小延迟 50ms,最大延迟 2s
|
||||||
|
retryStrategy: (times) => Math.min(times * 50, 2000),
|
||||||
|
// 仅在第一次建立连接
|
||||||
|
lazyConnect: true,
|
||||||
|
});
|
||||||
|
|
||||||
// 从缓存中获取数据
|
// Redis 是否可用
|
||||||
export const getCache = <T>(key: string): GetCache<T> | undefined => {
|
let isRedisAvailable: boolean = false;
|
||||||
|
let isRedisTried: boolean = false;
|
||||||
|
|
||||||
|
// Redis 连接状态
|
||||||
|
const ensureRedisConnection = async () => {
|
||||||
|
if (isRedisTried) return;
|
||||||
|
try {
|
||||||
|
if (redis.status !== "ready" && redis.status !== "connecting") await redis.connect();
|
||||||
|
isRedisAvailable = true;
|
||||||
|
isRedisTried = true;
|
||||||
|
logger.info("📦 [Redis] connected successfully.");
|
||||||
|
} catch (error) {
|
||||||
|
isRedisAvailable = false;
|
||||||
|
isRedisTried = true;
|
||||||
|
logger.error(
|
||||||
|
`📦 [Redis] connection failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Redis 事件监听
|
||||||
|
redis.on("error", (err) => {
|
||||||
|
if (!isRedisTried) {
|
||||||
|
isRedisAvailable = false;
|
||||||
|
isRedisTried = true;
|
||||||
|
logger.error(
|
||||||
|
`📦 [Redis] connection failed: ${err instanceof Error ? err.message : "Unknown error"}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// NodeCache 事件监听
|
||||||
|
cache.on("expired", (key) => {
|
||||||
|
logger.info(`⏳ [NodeCache] Key "${key}" has expired.`);
|
||||||
|
});
|
||||||
|
|
||||||
|
cache.on("del", (key) => {
|
||||||
|
logger.info(`🗑️ [NodeCache] Key "${key}" has been deleted.`);
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从缓存中获取数据
|
||||||
|
* @param key 缓存键
|
||||||
|
* @returns 缓存数据
|
||||||
|
*/
|
||||||
|
export const getCache = async (key: string): Promise<CacheData | undefined> => {
|
||||||
|
await ensureRedisConnection();
|
||||||
|
if (isRedisAvailable) {
|
||||||
|
try {
|
||||||
|
const redisResult = await redis.get(key);
|
||||||
|
if (redisResult) return parse(redisResult);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(
|
||||||
|
`📦 [Redis] get error: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
return cache.get(key);
|
return cache.get(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 将数据写入缓存
|
/**
|
||||||
export const setCache = <T>(key: string, value: T, ttl: number = config.CACHE_TTL) => {
|
* 将数据写入缓存
|
||||||
|
* @param key 缓存键
|
||||||
|
* @param value 缓存值
|
||||||
|
* @param ttl 缓存过期时间( 秒 )
|
||||||
|
* @returns 是否写入成功
|
||||||
|
*/
|
||||||
|
export const setCache = async (
|
||||||
|
key: string,
|
||||||
|
value: CacheData,
|
||||||
|
ttl: number = config.CACHE_TTL,
|
||||||
|
): Promise<boolean> => {
|
||||||
|
// 尝试写入 Redis
|
||||||
|
if (isRedisAvailable && !Buffer.isBuffer(value?.data)) {
|
||||||
|
try {
|
||||||
|
await redis.set(key, stringify(value), "EX", ttl);
|
||||||
|
if (logger) logger.info(`💾 [REDIS] ${key} has been cached`);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(
|
||||||
|
`📦 [Redis] set error: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
const success = cache.set(key, value, ttl);
|
const success = cache.set(key, value, ttl);
|
||||||
if (logger) logger.info("数据缓存成功", { url: key });
|
if (logger) logger.info(`💾 [NodeCache] ${key} has been cached`);
|
||||||
return success;
|
return success;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 从缓存中删除数据
|
/**
|
||||||
export const delCache = (key: string) => {
|
* 从缓存中删除数据
|
||||||
return cache.del(key);
|
* @param key 缓存键
|
||||||
|
* @returns 是否删除成功
|
||||||
|
*/
|
||||||
|
export const delCache = async (key: string): Promise<boolean> => {
|
||||||
|
let redisSuccess = true;
|
||||||
|
try {
|
||||||
|
await redis.del(key);
|
||||||
|
logger.info(`🗑️ [REDIS] ${key} has been deleted from Redis`);
|
||||||
|
} catch (error) {
|
||||||
|
redisSuccess = false;
|
||||||
|
logger.error(
|
||||||
|
`📦 [Redis] del error: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// 尝试删除 NodeCache
|
||||||
|
const nodeCacheSuccess = cache.del(key) > 0;
|
||||||
|
if (logger) logger.info(`🗑️ [CACHE] ${key} has been deleted from NodeCache`);
|
||||||
|
return redisSuccess && nodeCacheSuccess;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import type { Get, Post, Web } from "../types.ts";
|
import type { Get, Post } from "../types.js";
|
||||||
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 logger from "./logger.js";
|
import logger from "./logger.js";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
@@ -12,27 +11,6 @@ const request = axios.create({
|
|||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// puppeteer-cluster
|
|
||||||
export const createCluster = async () => {
|
|
||||||
return await Cluster.launch({
|
|
||||||
concurrency: Cluster.CONCURRENCY_BROWSER,
|
|
||||||
maxConcurrency: 5,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Cluster
|
|
||||||
const cluster = await createCluster();
|
|
||||||
|
|
||||||
// Cluster configuration
|
|
||||||
cluster.task(async ({ page, data: { url, userAgent } }) => {
|
|
||||||
if (userAgent) {
|
|
||||||
await page.setUserAgent(userAgent);
|
|
||||||
}
|
|
||||||
await page.goto(url, { waitUntil: 'networkidle0' });
|
|
||||||
const pageContent = await page.content();
|
|
||||||
return pageContent;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 请求拦截
|
// 请求拦截
|
||||||
request.interceptors.request.use(
|
request.interceptors.request.use(
|
||||||
(request) => {
|
(request) => {
|
||||||
@@ -41,7 +19,7 @@ request.interceptors.request.use(
|
|||||||
return request;
|
return request;
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
logger.error("请求失败,请稍后重试");
|
logger.error("❌ [ERROR] request failed");
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -59,31 +37,42 @@ request.interceptors.response.use(
|
|||||||
|
|
||||||
// GET
|
// GET
|
||||||
export const get = async (options: Get) => {
|
export const get = async (options: Get) => {
|
||||||
const { url, headers, params, noCache, ttl = config.CACHE_TTL, originaInfo = false } = options;
|
const {
|
||||||
logger.info("发起 GET 请求", options);
|
url,
|
||||||
|
headers,
|
||||||
|
params,
|
||||||
|
noCache,
|
||||||
|
ttl = config.CACHE_TTL,
|
||||||
|
originaInfo = false,
|
||||||
|
responseType = "json",
|
||||||
|
} = options;
|
||||||
|
logger.info(`🌐 [GET] ${url}`);
|
||||||
try {
|
try {
|
||||||
// 检查缓存
|
// 检查缓存
|
||||||
if (noCache) delCache(url);
|
if (noCache) await delCache(url);
|
||||||
else {
|
else {
|
||||||
const cachedData = getCache(url);
|
const cachedData = await getCache(url);
|
||||||
if (cachedData) {
|
if (cachedData) {
|
||||||
logger.info("采用缓存", { url });
|
logger.info("💾 [CHCHE] The request is cached");
|
||||||
return { fromCache: true, data: cachedData.data, updateTime: cachedData.updateTime };
|
return {
|
||||||
|
fromCache: true,
|
||||||
|
updateTime: cachedData.updateTime,
|
||||||
|
data: cachedData.data,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 缓存不存在时请求接口
|
// 缓存不存在时请求接口
|
||||||
logger.info("请求接口", { url });
|
const response = await request.get(url, { headers, params, responseType });
|
||||||
const response = await request.get(url, { headers, params });
|
|
||||||
const responseData = response?.data || response;
|
const responseData = response?.data || response;
|
||||||
// 存储新获取的数据到缓存
|
// 存储新获取的数据到缓存
|
||||||
const updateTime = new Date().toISOString();
|
const updateTime = new Date().toISOString();
|
||||||
const data = originaInfo ? response : responseData;
|
const data = originaInfo ? response : responseData;
|
||||||
setCache(url, { data, updateTime }, ttl);
|
await setCache(url, { data, updateTime }, ttl);
|
||||||
// 返回数据
|
// 返回数据
|
||||||
logger.info("接口调用成功", { status: response?.statusText });
|
logger.info(`✅ [${response?.status}] request was successful`);
|
||||||
return { fromCache: false, data, updateTime };
|
return { fromCache: false, updateTime, data };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("GET 请求出错", error);
|
logger.error("❌ [ERROR] request failed");
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -91,62 +80,31 @@ export const get = async (options: Get) => {
|
|||||||
// POST
|
// POST
|
||||||
export const post = async (options: Post) => {
|
export const post = async (options: Post) => {
|
||||||
const { url, headers, body, noCache, ttl = config.CACHE_TTL, originaInfo = false } = options;
|
const { url, headers, body, noCache, ttl = config.CACHE_TTL, originaInfo = false } = options;
|
||||||
logger.info("发起 POST 请求", options);
|
logger.info(`🌐 [POST] ${url}`);
|
||||||
try {
|
try {
|
||||||
// 检查缓存
|
// 检查缓存
|
||||||
if (noCache) delCache(url);
|
if (noCache) await delCache(url);
|
||||||
else {
|
else {
|
||||||
const cachedData = getCache(url);
|
const cachedData = await getCache(url);
|
||||||
if (cachedData) {
|
if (cachedData) {
|
||||||
logger.info("采用缓存", { url });
|
logger.info("💾 [CHCHE] The request is cached");
|
||||||
return { fromCache: true, data: cachedData.data, updateTime: cachedData.updateTime };
|
return { fromCache: true, updateTime: cachedData.updateTime, data: cachedData.data };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 缓存不存在时请求接口
|
// 缓存不存在时请求接口
|
||||||
logger.info("请求接口", { url });
|
|
||||||
const response = await request.post(url, body, { headers });
|
const response = await request.post(url, body, { headers });
|
||||||
const responseData = response?.data || response;
|
const responseData = response?.data || response;
|
||||||
// 存储新获取的数据到缓存
|
// 存储新获取的数据到缓存
|
||||||
const updateTime = new Date().toISOString();
|
const updateTime = new Date().toISOString();
|
||||||
const data = originaInfo ? response : responseData;
|
const data = originaInfo ? response : responseData;
|
||||||
if (!noCache) {
|
if (!noCache) {
|
||||||
setCache(url, { data, updateTime }, ttl);
|
await setCache(url, { data, updateTime }, ttl);
|
||||||
}
|
}
|
||||||
// 返回数据
|
// 返回数据
|
||||||
logger.info("接口调用成功", { status: response?.statusText });
|
logger.info(`✅ [${response?.status}] request was successful`);
|
||||||
return { fromCache: false, data, updateTime };
|
return { fromCache: false, updateTime, data };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("POST 请求出错", error);
|
logger.error("❌ [ERROR] request failed");
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// puppeteer
|
|
||||||
export const web = async (options: Web) => {
|
|
||||||
const { url, noCache, ttl = config.CACHE_TTL, userAgent } = options;
|
|
||||||
logger.info("使用 Puppeteer 发起页面请求", options);
|
|
||||||
try {
|
|
||||||
// 检查缓存
|
|
||||||
if (noCache) {
|
|
||||||
delCache(url);
|
|
||||||
} else {
|
|
||||||
const cachedData = getCache(url);
|
|
||||||
if (cachedData) {
|
|
||||||
logger.info("采用缓存", { url });
|
|
||||||
return { fromCache: true, data: cachedData.data, updateTime: cachedData.updateTime };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 缓存不存在时使用 Puppeteer 请求页面
|
|
||||||
logger.info("启动浏览器请求页面", { url });
|
|
||||||
const pageContent = await cluster.execute({ url, userAgent });
|
|
||||||
// 存储新获取的数据到缓存
|
|
||||||
const updateTime = new Date().toISOString();
|
|
||||||
setCache(url, { data: pageContent, updateTime }, ttl);
|
|
||||||
// 返回数据
|
|
||||||
logger.info("页面内容获取成功");
|
|
||||||
return { fromCache: false, data: pageContent, updateTime };
|
|
||||||
} catch (error) {
|
|
||||||
logger.error("Puppeteer 请求出错", error);
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
20
src/utils/getNum.ts
Normal file
20
src/utils/getNum.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
export const parseChineseNumber = (chineseNumber: string): number => {
|
||||||
|
// 单位对照表
|
||||||
|
const units: { [key: string]: number } = {
|
||||||
|
亿: 1e8,
|
||||||
|
万: 1e4,
|
||||||
|
千: 1e3,
|
||||||
|
百: 1e2,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 遍历单位对照表
|
||||||
|
for (const unit in units) {
|
||||||
|
if (chineseNumber.includes(unit)) {
|
||||||
|
// 转换为数字
|
||||||
|
const numberPart = parseFloat(chineseNumber.replace(unit, ""));
|
||||||
|
return numberPart * units[unit];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseFloat(chineseNumber);
|
||||||
|
};
|
||||||
@@ -30,12 +30,32 @@ const getRSS = (data: RouterData) => {
|
|||||||
name: item.author,
|
name: item.author,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
extensions: [
|
||||||
|
{
|
||||||
|
name: "media:content",
|
||||||
|
objects: {
|
||||||
|
_attributes: {
|
||||||
|
"xmlns:media": "http://search.yahoo.com/mrss/",
|
||||||
|
url: item.cover,
|
||||||
|
},
|
||||||
|
"media:thumbnail": {
|
||||||
|
_attributes: {
|
||||||
|
url: item.cover,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"media:description": item.desc ? {
|
||||||
|
_cdata: item.desc
|
||||||
|
} : "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const rssData = feed.rss2();
|
const rssData = feed.rss2();
|
||||||
return rssData;
|
return rssData;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("RSS 生成失败:", error);
|
logger.error("❌ [ERROR] getRSS failed");
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,170 @@
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
const getTime = (timeInput: string | number): number => {
|
interface CurrentDateTime {
|
||||||
|
year: string;
|
||||||
|
month: string;
|
||||||
|
day: string;
|
||||||
|
hour: string;
|
||||||
|
minute: string;
|
||||||
|
second: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将时间字符串或数字转换为时间戳
|
||||||
|
* @param timeInput 时间字符串或数字
|
||||||
|
* @returns 时间戳
|
||||||
|
*/
|
||||||
|
export const getTime = (timeInput: string | number): number | undefined => {
|
||||||
try {
|
try {
|
||||||
let num: number | string;
|
let num: number;
|
||||||
// 尝试将输入转换为数字
|
|
||||||
|
// 处理字符串的情况
|
||||||
if (typeof timeInput === "string") {
|
if (typeof timeInput === "string") {
|
||||||
|
// 尝试将字符串直接转换为数字
|
||||||
num = Number(timeInput);
|
num = Number(timeInput);
|
||||||
// 检查转换结果是否为有效数字
|
|
||||||
if (isNaN(num)) {
|
if (isNaN(num)) {
|
||||||
// 处理为字符串的日期时间
|
const now = dayjs();
|
||||||
return dayjs(timeInput).valueOf();
|
|
||||||
|
// 处理 "00:00"
|
||||||
|
if (/^\d{2}:\d{2}$/.test(timeInput)) {
|
||||||
|
const [hour, minute] = timeInput.split(":").map(Number);
|
||||||
|
return now.set("hour", hour).set("minute", minute).set("second", 0).valueOf();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理 昨天的时间
|
||||||
|
if (/^昨日\s+\d{2}:\d{2}$/.test(timeInput)) {
|
||||||
|
const timeStr = timeInput.replace("昨日", "").trim();
|
||||||
|
const [hour, minute] = timeStr.split(":").map(Number);
|
||||||
|
return now
|
||||||
|
.subtract(1, "day")
|
||||||
|
.set("hour", hour)
|
||||||
|
.set("minute", minute)
|
||||||
|
.set("second", 0)
|
||||||
|
.valueOf();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理 今年的日期
|
||||||
|
if (/^\d{1,2}月\d{1,2}日$/.test(timeInput)) {
|
||||||
|
const [month, day] = timeInput
|
||||||
|
.replace("月", "-")
|
||||||
|
.replace("日", "")
|
||||||
|
.split("-")
|
||||||
|
.map(Number);
|
||||||
|
return now
|
||||||
|
.set("month", month - 1)
|
||||||
|
.set("date", day)
|
||||||
|
.startOf("day")
|
||||||
|
.valueOf();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理 今年的日期+时间
|
||||||
|
if (/^\d{1,2}月\d{1,2}日\s+\d{2}:\d{2}$/.test(timeInput)) {
|
||||||
|
const [datePart, timePart] = timeInput.split(" ");
|
||||||
|
const [month, day] = datePart.replace("月", "-").replace("日", "").split("-").map(Number);
|
||||||
|
const [hour, minute] = timePart.split(":").map(Number);
|
||||||
|
return now
|
||||||
|
.set("month", month - 1)
|
||||||
|
.set("date", day)
|
||||||
|
.set("hour", hour)
|
||||||
|
.set("minute", minute)
|
||||||
|
.set("second", 0)
|
||||||
|
.valueOf();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理相对时间
|
||||||
|
if (/今天/.test(timeInput)) {
|
||||||
|
const timeStr = timeInput.replace("今天", "").trim();
|
||||||
|
return dayjs()
|
||||||
|
.set("hour", parseInt(timeStr.split(":")[0]))
|
||||||
|
.set("minute", parseInt(timeStr.split(":")[1]))
|
||||||
|
.valueOf();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/昨天/.test(timeInput)) {
|
||||||
|
const timeStr = timeInput.replace("昨天", "").trim();
|
||||||
|
return dayjs()
|
||||||
|
.subtract(1, "day")
|
||||||
|
.set("hour", parseInt(timeStr.split(":")[0]))
|
||||||
|
.set("minute", parseInt(timeStr.split(":")[1]))
|
||||||
|
.valueOf();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理 `N 小时前` 的时间格式
|
||||||
|
if (/小时前/.test(timeInput)) {
|
||||||
|
const hoursAgo = parseInt(timeInput.replace("小时前", ""));
|
||||||
|
return dayjs().subtract(hoursAgo, "hour").valueOf();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/分钟前/.test(timeInput)) {
|
||||||
|
const minutesAgo = parseInt(timeInput.replace("分钟前", ""));
|
||||||
|
return dayjs().subtract(minutesAgo, "minute").valueOf();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理为标准格式
|
||||||
|
let standardizedInput = timeInput
|
||||||
|
.replace(/(\d{4})-(\d{2})-(\d{2})-(\d{2})/, "$1-$2-$3 $4") // "YYYY-MM-DD-HH" -> "YYYY-MM-DD HH"
|
||||||
|
.replace(/(\d{4})-(\d{2})-(\d{2})[T\s](\d{2}):?(\d{2})?:?(\d{2})?/, "$1-$2-$3 $4:$5:$6") // "YYYY-MM-DDTHH:mm:ss" -> "YYYY-MM-DD HH:mm:ss"
|
||||||
|
.replace(/(\d{4})[-/](\d{2})[-/](\d{2})/, "$1-$2-$3"); // "YYYY/MM/DD" or "YYYY-MM-DD" -> "YYYY-MM-DD"
|
||||||
|
|
||||||
|
// 减少解析过程中可能的多余空格
|
||||||
|
standardizedInput = standardizedInput.replace(/\s+/, " ").trim();
|
||||||
|
|
||||||
|
// 处理标准化后的日期时间字符串
|
||||||
|
const formatPatterns = [
|
||||||
|
"YYYY-MM-DD HH:mm:ss",
|
||||||
|
"YYYY-MM-DD HH:mm",
|
||||||
|
"YYYY-MM-DD HH",
|
||||||
|
"YYYY-MM-DD",
|
||||||
|
];
|
||||||
|
|
||||||
|
let parsedDate: dayjs.Dayjs | undefined = undefined;
|
||||||
|
for (const pattern of formatPatterns) {
|
||||||
|
parsedDate = dayjs(standardizedInput, pattern, true);
|
||||||
|
if (parsedDate.isValid()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsedDate && parsedDate.isValid()) {
|
||||||
|
return parsedDate.valueOf();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
num = timeInput;
|
num = timeInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 是否为毫秒级时间戳
|
// 是否为毫秒级时间戳
|
||||||
if (num > 946684800000) {
|
if (num > 946684800000) {
|
||||||
|
// 以2000年作为毫秒时间戳参考点
|
||||||
return num;
|
return num;
|
||||||
} else {
|
} else {
|
||||||
return num * 1000;
|
return num * 1000;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return null;
|
console.error(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default getTime;
|
/**
|
||||||
|
* 获取当前日期时间
|
||||||
|
* @param padZero 是否补零
|
||||||
|
* @returns 当前日期时间
|
||||||
|
*/
|
||||||
|
export const getCurrentDateTime = (padZero: boolean = false): CurrentDateTime => {
|
||||||
|
const now = dayjs();
|
||||||
|
|
||||||
|
// 补零
|
||||||
|
const pad = (num: number): string => (num < 10 ? `0${num}` : `${num}`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
year: now.year().toString(),
|
||||||
|
month: padZero ? pad(now.month() + 1) : (now.month() + 1).toString(),
|
||||||
|
day: padZero ? pad(now.date()) : now.date().toString(),
|
||||||
|
hour: padZero ? pad(now.hour()) : now.hour().toString(),
|
||||||
|
minute: padZero ? pad(now.minute()) : now.minute().toString(),
|
||||||
|
second: padZero ? pad(now.second()) : now.second().toString(),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -3,16 +3,13 @@ import { get } from "../getData.js";
|
|||||||
import md5 from "md5";
|
import md5 from "md5";
|
||||||
|
|
||||||
export const getToken = async () => {
|
export const getToken = async () => {
|
||||||
const cachedData = getCache("51cto-token");
|
const cachedData = await getCache("51cto-token");
|
||||||
if (cachedData && typeof cachedData === "object" && "token" in cachedData) {
|
if (cachedData?.data) return cachedData.data;
|
||||||
const { token } = cachedData as { token: string };
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
const result = await get({
|
const result = await get({
|
||||||
url: "https://api-media.51cto.com/api/token-get",
|
url: "https://api-media.51cto.com/api/token-get",
|
||||||
});
|
});
|
||||||
const token = result.data.data.data.token;
|
const token = result.data.data.data.token;
|
||||||
setCache("51cto-token", { token });
|
await setCache("51cto-token", { data: token, updateTime: new Date().toISOString() });
|
||||||
return token;
|
return token;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -67,18 +67,17 @@ const getWbiKeys = async (): Promise<EncodedKeys> => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getBiliWbi = async (): Promise<string> => {
|
const getBiliWbi = async (): Promise<string> => {
|
||||||
const cachedData = getCache("bilibili-wbi");
|
const cachedData = await getCache("bilibili-wbi");
|
||||||
console.log(cachedData);
|
if (cachedData?.data) return cachedData.data as string;
|
||||||
if (cachedData && typeof cachedData === "object" && "wbi" in cachedData) {
|
|
||||||
const { wbi } = cachedData as { wbi: string };
|
|
||||||
return wbi;
|
|
||||||
}
|
|
||||||
const web_keys = await getWbiKeys();
|
const web_keys = await getWbiKeys();
|
||||||
const params = { foo: "114", bar: "514", baz: 1919810 };
|
const params = { foo: "114", bar: "514", baz: 1919810 };
|
||||||
const img_key = web_keys.img_key;
|
const img_key = web_keys.img_key;
|
||||||
const sub_key = web_keys.sub_key;
|
const sub_key = web_keys.sub_key;
|
||||||
const query = encWbi(params, img_key, sub_key);
|
const query = encWbi(params, img_key, sub_key);
|
||||||
setCache("bilibili-wbi", { wbi: query });
|
await setCache("bilibili-wbi", {
|
||||||
|
data: query,
|
||||||
|
updateTime: new Date().toISOString(),
|
||||||
|
});
|
||||||
return query;
|
return query;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
49
src/utils/getToken/coolapk.ts
Normal file
49
src/utils/getToken/coolapk.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import md5 from "md5";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取随机的DEVICE_ID
|
||||||
|
* @returns DEVICE_ID
|
||||||
|
*/
|
||||||
|
const getRandomDEVICE_ID = () => {
|
||||||
|
const id = [10, 6, 6, 6, 14];
|
||||||
|
return id.map((i) => Math.random().toString(36).substring(2, i)).join("-");
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取APP_TOKEN
|
||||||
|
* @returns APP_TOKEN
|
||||||
|
*/
|
||||||
|
const get_app_token = () => {
|
||||||
|
const DEVICE_ID = getRandomDEVICE_ID();
|
||||||
|
const now = Math.round(Date.now() / 1000);
|
||||||
|
const hex_now = "0x" + now.toString(16);
|
||||||
|
const md5_now = md5(now.toString());
|
||||||
|
const s =
|
||||||
|
"token://com.coolapk.market/c67ef5943784d09750dcfbb31020f0ab?" +
|
||||||
|
md5_now +
|
||||||
|
"$" +
|
||||||
|
DEVICE_ID +
|
||||||
|
"&com.coolapk.market";
|
||||||
|
const md5_s = md5(Buffer.from(s).toString("base64"));
|
||||||
|
const token = md5_s + DEVICE_ID + hex_now;
|
||||||
|
return token;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取请求头
|
||||||
|
* @returns 请求头
|
||||||
|
*/
|
||||||
|
export const genHeaders = () => {
|
||||||
|
return {
|
||||||
|
"X-Requested-With": "XMLHttpRequest",
|
||||||
|
"X-App-Id": "com.coolapk.market",
|
||||||
|
"X-App-Token": get_app_token(),
|
||||||
|
"X-Sdk-Int": "29",
|
||||||
|
"X-Sdk-Locale": "zh-CN",
|
||||||
|
"X-App-Version": "11.0",
|
||||||
|
"X-Api-Version": "11",
|
||||||
|
"X-App-Code": "2101202",
|
||||||
|
"User-Agent":
|
||||||
|
"Mozilla/5.0 (Linux; Android 10; Mi 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.5563.15 Mobile Safari/537.36",
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,7 +14,7 @@ const getWereadID = (bookId: string) => {
|
|||||||
// 取哈希结果的前三个字符作为初始值
|
// 取哈希结果的前三个字符作为初始值
|
||||||
let strSub = str.substring(0, 3);
|
let strSub = str.substring(0, 3);
|
||||||
// 判断书籍 ID 的类型并进行转换
|
// 判断书籍 ID 的类型并进行转换
|
||||||
let fa;
|
let fa: (string | any[])[];
|
||||||
if (/^\d*$/.test(bookId)) {
|
if (/^\d*$/.test(bookId)) {
|
||||||
// 如果书籍 ID 只包含数字,则将其拆分成长度为 9 的子字符串,并转换为十六进制表示
|
// 如果书籍 ID 只包含数字,则将其拆分成长度为 9 的子字符串,并转换为十六进制表示
|
||||||
const chunks = [];
|
const chunks = [];
|
||||||
@@ -60,7 +61,7 @@ const getWereadID = (bookId: string) => {
|
|||||||
return strSub;
|
return strSub;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("处理微信读书 ID 时出现错误:" + error);
|
console.error("处理微信读书 ID 时出现错误:" + error);
|
||||||
return null;
|
return undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,54 @@
|
|||||||
import { config } from "../config.js";
|
import { config } from "../config.js";
|
||||||
import { createLogger, format, transports } from "winston";
|
import { createLogger, format, transports } from "winston";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import chalk from "chalk";
|
||||||
|
|
||||||
let pathOption: (typeof transports.File)[] = [];
|
let pathOption: (typeof transports.File)[] = [];
|
||||||
|
|
||||||
// 日志输出目录
|
// 日志输出目录
|
||||||
if (config.USE_LOG_FILE) {
|
if (config.USE_LOG_FILE) {
|
||||||
pathOption = [
|
try {
|
||||||
new transports.File({
|
pathOption = [
|
||||||
filename: path.resolve("logs/error.log"),
|
new transports.File({
|
||||||
level: "error",
|
filename: path.resolve("logs/error.log"),
|
||||||
maxsize: 1024 * 1024,
|
level: "error",
|
||||||
maxFiles: 1,
|
maxsize: 1024 * 1024,
|
||||||
}),
|
maxFiles: 1,
|
||||||
new transports.File({
|
}),
|
||||||
filename: path.resolve("logs/logger.log"),
|
new transports.File({
|
||||||
maxsize: 1024 * 1024,
|
filename: path.resolve("logs/logger.log"),
|
||||||
maxFiles: 1,
|
maxsize: 1024 * 1024,
|
||||||
}),
|
maxFiles: 1,
|
||||||
];
|
}),
|
||||||
|
];
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to initialize log files. Logging to a file will be skipped.", error);
|
||||||
|
pathOption = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 定义不同日志级别的彩色块
|
||||||
|
const levelColors: { [key: string]: string } = {
|
||||||
|
error: chalk.bgRed(" ERROR "),
|
||||||
|
warn: chalk.bgYellow(" WARN "),
|
||||||
|
info: chalk.bgBlue(" INFO "),
|
||||||
|
debug: chalk.bgGreen(" DEBUG "),
|
||||||
|
default: chalk.bgWhite(" LOG "),
|
||||||
|
};
|
||||||
|
|
||||||
|
// 自定义控制台日志输出格式
|
||||||
|
const consoleFormat = format.printf(({ level, message, timestamp, stack }) => {
|
||||||
|
// 获取原始日志级别
|
||||||
|
const originalLevel = Object.keys(levelColors).find((lvl) => level.includes(lvl)) || "default";
|
||||||
|
const colorLevel = levelColors[originalLevel] || levelColors.default;
|
||||||
|
|
||||||
|
let logMessage = `${colorLevel} [${timestamp}] ${message}`;
|
||||||
|
if (stack) {
|
||||||
|
logMessage += `\n${stack}`;
|
||||||
|
}
|
||||||
|
return logMessage;
|
||||||
|
});
|
||||||
|
|
||||||
// logger
|
// logger
|
||||||
const logger = createLogger({
|
const logger = createLogger({
|
||||||
// 最低的日志级别
|
// 最低的日志级别
|
||||||
@@ -39,11 +67,15 @@ const logger = createLogger({
|
|||||||
|
|
||||||
// 控制台输出
|
// 控制台输出
|
||||||
if (process.env.NODE_ENV !== "production") {
|
if (process.env.NODE_ENV !== "production") {
|
||||||
logger.add(
|
try {
|
||||||
new transports.Console({
|
logger.add(
|
||||||
format: format.combine(format.colorize(), format.simple()),
|
new transports.Console({
|
||||||
}),
|
format: format.combine(format.colorize(), consoleFormat),
|
||||||
);
|
}),
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to add console transport. Console logging will be skipped.", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default logger;
|
export default logger;
|
||||||
|
|||||||
@@ -1,12 +1,23 @@
|
|||||||
import RSSParser from "rss-parser";
|
import RSSParser from "rss-parser";
|
||||||
import logger from "./logger.js";
|
import logger from "./logger.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提取 RSS 内容
|
||||||
|
* @param content HTML 内容
|
||||||
|
* @returns RSS 内容
|
||||||
|
*/
|
||||||
export const extractRss = (content: string): string | null => {
|
export const extractRss = (content: string): string | null => {
|
||||||
// 匹配 <rss> 标签及内容
|
// 匹配 <rss> 标签及内容
|
||||||
const rssRegex = /(<rss[\s\S]*?<\/rss>)/i;
|
const rssRegex = /(<rss[\s\S]*?<\/rss>)/i;
|
||||||
const matches = content.match(rssRegex);
|
const matches = content.match(rssRegex);
|
||||||
return matches ? matches[0] : null;
|
return matches ? matches[0] : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析 RSS 内容
|
||||||
|
* @param rssContent RSS 内容
|
||||||
|
* @returns 解析后的 RSS 内容
|
||||||
|
*/
|
||||||
export const parseRSS = async (rssContent: string) => {
|
export const parseRSS = async (rssContent: string) => {
|
||||||
const parser = new RSSParser();
|
const parser = new RSSParser();
|
||||||
// 是否为网址
|
// 是否为网址
|
||||||
@@ -14,7 +25,8 @@ export const parseRSS = async (rssContent: string) => {
|
|||||||
try {
|
try {
|
||||||
new URL(url);
|
new URL(url);
|
||||||
return true;
|
return true;
|
||||||
} catch (_) {
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -35,7 +47,7 @@ export const parseRSS = async (rssContent: string) => {
|
|||||||
// 返回解析数据
|
// 返回解析数据
|
||||||
return items;
|
return items;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("解析 RSS 内容时出错:", error);
|
logger.error("❌ [RSS] An error occurred while parsing RSS content");
|
||||||
return null;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -72,6 +72,7 @@ const Layout: FC = (props) => {
|
|||||||
font-size: 28px;
|
font-size: 28px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
.title .title-tip {
|
.title .title-tip {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
@@ -83,6 +84,7 @@ const Layout: FC = (props) => {
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
border: 1px dashed var(--text-color);
|
border: 1px dashed var(--text-color);
|
||||||
|
user-select: text;
|
||||||
}
|
}
|
||||||
.control {
|
.control {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"strict": true,
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"moduleResolution": "Bundler",
|
"moduleResolution": "Bundler",
|
||||||
"strict": false,
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
"types": ["node"],
|
"types": ["node"],
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"jsxImportSource": "hono/jsx",
|
"jsxImportSource": "hono/jsx",
|
||||||
"outDir": "./dist"
|
"outDir": "./dist"
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "*.test.*"]
|
"exclude": ["node_modules", "*.test.*", "./dist/**/*"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user