mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 21:24:55 +08:00
Compare commits
14 Commits
v2.0.0-rc.
...
v2.0.0-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11addd20ca | ||
|
|
23375519ba | ||
|
|
2ba46c5e0e | ||
|
|
d4a52a6b24 | ||
|
|
d73ca1170c | ||
|
|
93d90eb653 | ||
|
|
a3bb42d26c | ||
|
|
093312ea8c | ||
|
|
13f019a5aa | ||
|
|
ce5d381093 | ||
|
|
679fdab87e | ||
|
|
8c8a86957b | ||
|
|
8e077640b1 | ||
|
|
5555cc6f00 |
14
.github/workflows/docker.yml
vendored
14
.github/workflows/docker.yml
vendored
@@ -3,9 +3,10 @@ name: Publish Docker image
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
push_to_registry:
|
||||
build-docker:
|
||||
name: Push Docker image to multiple registries
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
@@ -15,6 +16,12 @@ jobs:
|
||||
- name: Check out the repo
|
||||
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
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
@@ -36,11 +43,14 @@ jobs:
|
||||
imsyy/dailyhot-api
|
||||
ghcr.io/${{ github.repository }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: |
|
||||
linux/amd64
|
||||
linux/arm64
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
32
.github/workflows/npm.yml
vendored
Normal file
32
.github/workflows/npm.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
name: Publish npm package
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
publish-npm:
|
||||
runs-on:
|
||||
ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [20]
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
registry-url: https://registry.npmjs.org
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Publish to npm
|
||||
run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
2
.npmignore
Normal file
2
.npmignore
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
dist/logs/
|
||||
@@ -10,22 +10,22 @@ We pledge to act and interact in ways that contribute to an open, welcoming, div
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our community include:
|
||||
|
||||
- Demonstrating empathy and kindness toward other people
|
||||
- Being respectful of differing opinions, viewpoints, and experiences
|
||||
- Giving and gracefully accepting constructive feedback
|
||||
- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
||||
- Focusing on what is best not just for us as individuals, but for the overall community
|
||||
- Demonstrating empathy and kindness toward other people
|
||||
- Being respectful of differing opinions, viewpoints, and experiences
|
||||
- Giving and gracefully accepting constructive feedback
|
||||
- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
||||
- Focusing on what is best not just for us as individuals, but for the overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
- The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
- Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
- Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
- The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
- Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
- Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
|
||||
14
Dockerfile
14
Dockerfile
@@ -1,8 +1,14 @@
|
||||
FROM node:20-alpine AS base
|
||||
|
||||
# 安装 Puppeteer 所需的依赖库
|
||||
RUN apk add --no-cache chromium nss freetype harfbuzz ca-certificates libc6-compat
|
||||
|
||||
# 配置 Chromium
|
||||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
|
||||
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
|
||||
|
||||
FROM base AS builder
|
||||
|
||||
RUN apk add --no-cache libc6-compat
|
||||
RUN npm install -g pnpm
|
||||
WORKDIR /app
|
||||
|
||||
@@ -10,9 +16,9 @@ COPY package*json tsconfig.json pnpm-lock.yaml .env ./
|
||||
COPY src ./src
|
||||
COPY public ./public
|
||||
|
||||
RUN pnpm install && \
|
||||
pnpm build && \
|
||||
pnpm prune --production
|
||||
RUN pnpm install
|
||||
RUN pnpm build
|
||||
RUN pnpm prune --production
|
||||
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
29
README.md
29
README.md
@@ -2,6 +2,12 @@
|
||||
<img alt="logo" height="120" src="./public/favicon.png" width="120"/>
|
||||
<h2>今日热榜</h2>
|
||||
<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>
|
||||
|
||||
## 🚩 特性
|
||||
@@ -46,6 +52,10 @@
|
||||
| 稀土掘金 | 热榜 | juejin | 🟢 |
|
||||
| 腾讯新闻 | 热点榜 | qq-news | 🟢 |
|
||||
| 网易新闻 | 热点榜 | netease-news | 🟢 |
|
||||
| 吾爱破解 | 榜单 | 52pojie | 🟢 |
|
||||
| 全球主机交流 | 榜单 | hostloc | 🟢 |
|
||||
| 虎嗅 | 24小时 | huxiu | 🟢 |
|
||||
| 爱范儿 | 快讯 | ifanr | 🟢 |
|
||||
| 英雄联盟 | 更新公告 | lol | 🟢 |
|
||||
| 原神 | 最新消息 | genshin | 🟢 |
|
||||
| 崩坏3 | 最新动态 | honkai | 🟢 |
|
||||
@@ -57,6 +67,25 @@
|
||||
| 中央气象台 | 全国气象预警 | weatheralarm | 🟢 |
|
||||
| 中国地震台 | 地震速报 | earthquake | 🟢 |
|
||||
|
||||
## ⚙️ 使用
|
||||
|
||||
本项目支持 `Node.js` 调用,可在安装完成后调用 `serveHotApi` 来开启服务器
|
||||
|
||||
```bash
|
||||
pnpm add dailyhot-api
|
||||
```
|
||||
|
||||
```js
|
||||
import serveHotApi from "dailyhot-api";
|
||||
|
||||
/**
|
||||
* 启动服务器
|
||||
* @param {Number} [port] - 端口号
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
serveHotApi(3000);
|
||||
```
|
||||
|
||||
## ⚙️ 部署
|
||||
|
||||
具体使用说明可参考 [我的博客](https://blog.imsyy.top/posts/2024/0408),下方仅讲解基础操作:
|
||||
|
||||
39
package.json
39
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dailyhot_api",
|
||||
"version": "2.0.0-rc.2",
|
||||
"name": "dailyhot-api",
|
||||
"version": "2.0.0-rc.5",
|
||||
"description": "An Api on Today's Hot list",
|
||||
"keywords": [
|
||||
"API",
|
||||
@@ -12,11 +12,22 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/DIYgod/RSSHub.git"
|
||||
"url": "git+https://github.com/imsyy/DailyHotApi.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "imsyy",
|
||||
"main": "src/index.ts",
|
||||
"main": "dist/index.js",
|
||||
"types": "src/types.d.ts",
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true,
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"dist/**/*",
|
||||
"src/types.d.ts",
|
||||
"!dist/logs/**/*"
|
||||
],
|
||||
"scripts": {
|
||||
"format": "prettier --write .",
|
||||
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts,.vue --fix",
|
||||
@@ -27,24 +38,28 @@
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@hono/node-server": "^1.9.1",
|
||||
"axios": "^1.6.8",
|
||||
"@hono/node-server": "^1.11.2",
|
||||
"axios": "^1.7.2",
|
||||
"cheerio": "1.0.0-rc.12",
|
||||
"dayjs": "^1.11.11",
|
||||
"dotenv": "^16.4.5",
|
||||
"feed": "^4.2.2",
|
||||
"hono": "^4.2.2",
|
||||
"hono": "^4.4.3",
|
||||
"md5": "^2.3.0",
|
||||
"node-cache": "^5.1.2",
|
||||
"puppeteer": "^22.10.0",
|
||||
"puppeteer-cluster": "^0.24.0",
|
||||
"rss-parser": "^3.13.0",
|
||||
"winston": "^3.13.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.12.5",
|
||||
"@typescript-eslint/eslint-plugin": "^7.5.0",
|
||||
"@typescript-eslint/parser": "^7.5.0",
|
||||
"@types/node": "^20.14.1",
|
||||
"@typescript-eslint/eslint-plugin": "^7.12.0",
|
||||
"@typescript-eslint/parser": "^7.12.0",
|
||||
"eslint": "^8.57.0",
|
||||
"prettier": "^3.2.5",
|
||||
"prettier": "^3.3.0",
|
||||
"tsx": "^3.14.0",
|
||||
"typescript": "^5.4.4"
|
||||
"typescript": "^5.4.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
|
||||
2970
pnpm-lock.yaml
generated
2970
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,8 @@ import { cors } from "hono/cors";
|
||||
import { config } from "./config.js";
|
||||
import { serveStatic } from "@hono/node-server/serve-static";
|
||||
import { compress } from "hono/compress";
|
||||
import { prettyJSON } from "hono/pretty-json";
|
||||
import { trimTrailingSlash } from "hono/trailing-slash";
|
||||
import logger from "./utils/logger.js";
|
||||
import registry from "./registry.js";
|
||||
import robotstxt from "./robots.txt.js";
|
||||
@@ -15,6 +17,12 @@ const app = new Hono();
|
||||
// 压缩响应
|
||||
app.use(compress());
|
||||
|
||||
// prettyJSON
|
||||
app.use(prettyJSON());
|
||||
|
||||
// 尾部斜杠重定向
|
||||
app.use(trimTrailingSlash());
|
||||
|
||||
// CORS
|
||||
app.use(
|
||||
"*",
|
||||
|
||||
@@ -27,7 +27,7 @@ const getNumericEnvVariable = (key: string, defaultValue: number): number => {
|
||||
const value = getEnvVariable(key) ?? String(defaultValue);
|
||||
const parsedValue = parseInt(value, 10);
|
||||
if (isNaN(parsedValue)) {
|
||||
return defaultValue
|
||||
return defaultValue;
|
||||
}
|
||||
return parsedValue;
|
||||
};
|
||||
|
||||
24
src/index.ts
24
src/index.ts
@@ -3,13 +3,21 @@ import { config } from "./config.js";
|
||||
import logger from "./utils/logger.js";
|
||||
import app from "./app.js";
|
||||
|
||||
logger.info(`🔥 DailyHot API 成功在端口 ${config.PORT} 上运行`);
|
||||
logger.info(`🔗 Local: 👉 http://localhost:${config.PORT}`);
|
||||
|
||||
// 启动服务器
|
||||
const server = serve({
|
||||
fetch: app.fetch,
|
||||
port: config.PORT,
|
||||
});
|
||||
const serveHotApi = (port: number = config.PORT) => {
|
||||
try {
|
||||
const apiServer = serve({
|
||||
fetch: app.fetch,
|
||||
port,
|
||||
});
|
||||
logger.info(`🔥 DailyHot API 成功在端口 ${port} 上运行`);
|
||||
logger.info(`🔗 Local: 👉 http://localhost:${port}`);
|
||||
return apiServer;
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
export default server;
|
||||
serveHotApi();
|
||||
|
||||
export default serveHotApi;
|
||||
|
||||
54
src/router.types.ts → src/router.types.d.ts
vendored
54
src/router.types.ts → src/router.types.d.ts
vendored
@@ -1,6 +1,7 @@
|
||||
export type RouterType = {
|
||||
"36kr": {
|
||||
itemId: number;
|
||||
publishTime: number;
|
||||
templateMaterial: {
|
||||
widgetTitle: string;
|
||||
authorName: string;
|
||||
@@ -16,6 +17,7 @@ export type RouterType = {
|
||||
hotEvent: {
|
||||
hotScore: number;
|
||||
};
|
||||
timestamp: number;
|
||||
miniProShareImage: string;
|
||||
};
|
||||
"netease-news": {
|
||||
@@ -23,6 +25,7 @@ export type RouterType = {
|
||||
imgsrc: string;
|
||||
source: string;
|
||||
docid: string;
|
||||
ptime: string;
|
||||
};
|
||||
"zhihu-daily": {
|
||||
id: number;
|
||||
@@ -38,16 +41,28 @@ export type RouterType = {
|
||||
cover: string;
|
||||
abstract: string;
|
||||
source_id: number;
|
||||
pubdate: string;
|
||||
};
|
||||
discuz: {
|
||||
title: string;
|
||||
link: string;
|
||||
guid: string;
|
||||
content?: string;
|
||||
pubDate?: string;
|
||||
author?: string;
|
||||
};
|
||||
bilibili: {
|
||||
bvid: string;
|
||||
title: string;
|
||||
desc: string;
|
||||
pic: string;
|
||||
owner: {
|
||||
desc?: string;
|
||||
pubdate: string;
|
||||
pic?: string;
|
||||
author?: string;
|
||||
video_review?: number;
|
||||
owner?: {
|
||||
name: string;
|
||||
};
|
||||
stat: {
|
||||
stat?: {
|
||||
view: number;
|
||||
};
|
||||
short_link_v2?: string;
|
||||
@@ -72,12 +87,14 @@ export type RouterType = {
|
||||
note: string;
|
||||
category: string;
|
||||
raw_hot: number;
|
||||
onboard_time: number;
|
||||
};
|
||||
zhihu: {
|
||||
target: {
|
||||
id: number;
|
||||
title: string;
|
||||
excerpt: string;
|
||||
created: number;
|
||||
};
|
||||
children: [
|
||||
{
|
||||
@@ -90,6 +107,7 @@ export type RouterType = {
|
||||
sentence_id: string;
|
||||
word: string;
|
||||
hot_value: number;
|
||||
event_time: number;
|
||||
};
|
||||
baidu: {
|
||||
index: number;
|
||||
@@ -107,6 +125,7 @@ export type RouterType = {
|
||||
subject: string;
|
||||
content: string;
|
||||
cover: string;
|
||||
created_at: number;
|
||||
};
|
||||
stat: {
|
||||
view_num: number;
|
||||
@@ -128,6 +147,7 @@ export type RouterType = {
|
||||
intro: string;
|
||||
cover: string;
|
||||
author: string;
|
||||
publishTime: string;
|
||||
};
|
||||
};
|
||||
toutiao: {
|
||||
@@ -143,6 +163,7 @@ export type RouterType = {
|
||||
name: string;
|
||||
pic: string;
|
||||
praiseTimes: string;
|
||||
pubTimeLong: number;
|
||||
};
|
||||
sspai: {
|
||||
id: number;
|
||||
@@ -150,6 +171,7 @@ export type RouterType = {
|
||||
summary: string;
|
||||
banner: string;
|
||||
like_count: number;
|
||||
released_time: number;
|
||||
author: {
|
||||
nickname: string;
|
||||
};
|
||||
@@ -160,6 +182,7 @@ export type RouterType = {
|
||||
sTitle: string;
|
||||
iTotalPlay: string;
|
||||
iDocID: string;
|
||||
sCreated: string;
|
||||
};
|
||||
ngabbs: {
|
||||
tid: number;
|
||||
@@ -167,6 +190,7 @@ export type RouterType = {
|
||||
author: string;
|
||||
tpcurl: string;
|
||||
replies: number;
|
||||
postdate: number;
|
||||
};
|
||||
tieba: {
|
||||
topic_id: number;
|
||||
@@ -175,6 +199,7 @@ export type RouterType = {
|
||||
topic_pic: string;
|
||||
topic_url: string;
|
||||
discuss_num: number;
|
||||
create_time: number;
|
||||
};
|
||||
acfun: {
|
||||
dougaId: string;
|
||||
@@ -183,6 +208,7 @@ export type RouterType = {
|
||||
contentDesc: string;
|
||||
likeCount: number;
|
||||
coverUrl: string;
|
||||
contributeTime: number;
|
||||
};
|
||||
hellogithub: {
|
||||
item_id: string;
|
||||
@@ -191,6 +217,7 @@ export type RouterType = {
|
||||
description: string;
|
||||
summary: string;
|
||||
clicks_total: number;
|
||||
updated_at: string;
|
||||
};
|
||||
v2ex: {
|
||||
title: string;
|
||||
@@ -214,4 +241,23 @@ export type RouterType = {
|
||||
url: string;
|
||||
pic: string;
|
||||
};
|
||||
huxiu: {
|
||||
object_id: number;
|
||||
content: string;
|
||||
url: string;
|
||||
user_info: {
|
||||
username: string;
|
||||
};
|
||||
publish_time: string;
|
||||
};
|
||||
ifanr: {
|
||||
buzz_original_url: string;
|
||||
id: number;
|
||||
post_content: string;
|
||||
post_id: number;
|
||||
post_title: string;
|
||||
like_count: number;
|
||||
comment_count: number;
|
||||
created_at: number;
|
||||
};
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { post } from "../utils/getData.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "hot";
|
||||
@@ -65,6 +66,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
title: item.widgetTitle,
|
||||
cover: item.widgetImage,
|
||||
author: item.authorName,
|
||||
timestamp: getTime(v.publishTime),
|
||||
hot: item.statCollect,
|
||||
url: `https://www.36kr.com/p/${v.itemId}`,
|
||||
mobileUrl: `https://m.36kr.com/p/${v.itemId}`,
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { RouterData } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { getToken, sign } from "../utils/getToken/51cto.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
@@ -47,6 +48,7 @@ const getList = async (noCache: boolean) => {
|
||||
title: v.title,
|
||||
cover: v.cover,
|
||||
desc: v.abstract,
|
||||
timestamp: getTime(v.pubdate),
|
||||
url: v.url,
|
||||
mobileUrl: v.url,
|
||||
})),
|
||||
|
||||
66
src/routes/52pojie.ts
Normal file
66
src/routes/52pojie.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { web } from "../utils/getData.js";
|
||||
import { extractRss, parseRSS } from "../utils/parseRSS.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "hot";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "52pojie",
|
||||
title: "吾爱破解",
|
||||
type: "榜单",
|
||||
parameData: {
|
||||
type: {
|
||||
name: "榜单分类",
|
||||
type: {
|
||||
tech: "新鲜出炉",
|
||||
newthread: "技术分享",
|
||||
hot: "人气热门",
|
||||
digest: "精华采撷",
|
||||
},
|
||||
},
|
||||
},
|
||||
link: "https://www.52pojie.cn/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
|
||||
const getList = async (options: Options, noCache: boolean) => {
|
||||
const { type } = options;
|
||||
const url = `https://www.52pojie.cn/forum.php?mod=guide&view=${type}&rss=1`;
|
||||
const result = await web({
|
||||
url,
|
||||
noCache,
|
||||
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);
|
||||
return await parseRSS(rssContent);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
const list = await parseData();
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: list.map((v: RouterType["discuz"]) => ({
|
||||
id: v.guid,
|
||||
title: v.title,
|
||||
desc: v.content,
|
||||
author: v.author,
|
||||
timestamp: getTime(v.pubDate),
|
||||
hot: null,
|
||||
url: v.link,
|
||||
mobileUrl: v.link,
|
||||
})),
|
||||
};
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "-1";
|
||||
@@ -67,6 +68,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
desc: v.contentDesc,
|
||||
cover: v.coverUrl,
|
||||
author: v.userName,
|
||||
timestamp: getTime(v.contributeTime),
|
||||
hot: v.likeCount,
|
||||
url: `https://www.acfun.cn/v/ac${v.dougaId}`,
|
||||
mobileUrl: `https://m.acfun.cn/v/?ac=${v.dougaId}`,
|
||||
|
||||
@@ -55,6 +55,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
desc: v.desc,
|
||||
cover: v.img,
|
||||
author: v.show?.length ? v.show : "",
|
||||
timestamp: null,
|
||||
hot: Number(v.hotScore),
|
||||
url: `https://www.baidu.com/s?wd=${encodeURIComponent(v.query)}`,
|
||||
mobileUrl: v.rawUrl,
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getBiliWbi from "../utils/getToken/bilibili.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "0";
|
||||
@@ -53,19 +54,52 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
},
|
||||
noCache,
|
||||
});
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: list.map((v: RouterType["bilibili"]) => ({
|
||||
id: v.bvid,
|
||||
title: v.title,
|
||||
desc: v.desc,
|
||||
cover: v.pic.replace(/http:/, "https:"),
|
||||
author: v.owner.name,
|
||||
hot: v.stat.view,
|
||||
url: v.short_link_v2 || `https://www.bilibili.com/video/${v.bvid}`,
|
||||
mobileUrl: `https://m.bilibili.com/video/${v.bvid}`,
|
||||
})),
|
||||
};
|
||||
// 是否触发风控
|
||||
if (result.data?.data?.list?.length > 0) {
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: list.map((v: RouterType["bilibili"]) => ({
|
||||
id: v.bvid,
|
||||
title: v.title,
|
||||
desc: v.desc || "该视频暂无简介",
|
||||
cover: v.pic.replace(/http:/, "https:"),
|
||||
author: v.owner.name,
|
||||
timestamp: getTime(v.pubdate),
|
||||
hot: v.stat.view,
|
||||
url: v.short_link_v2 || `https://www.bilibili.com/video/${v.bvid}`,
|
||||
mobileUrl: `https://m.bilibili.com/video/${v.bvid}`,
|
||||
})),
|
||||
};
|
||||
}
|
||||
// 采用备用接口
|
||||
else {
|
||||
const url = `https://api.bilibili.com/x/web-interface/ranking?jsonp=jsonp?rid=${type}&type=1&callback=__jp0`;
|
||||
const result = await get({
|
||||
url,
|
||||
headers: {
|
||||
Referer: `https://www.bilibili.com/ranking/all`,
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
|
||||
},
|
||||
noCache,
|
||||
});
|
||||
const list = result.data.data.list;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: list.map((v: RouterType["bilibili"]) => ({
|
||||
id: v.bvid,
|
||||
title: v.title,
|
||||
desc: v.desc || "该视频暂无简介",
|
||||
cover: v.pic.replace(/http:/, "https:"),
|
||||
author: v.author,
|
||||
timestamp: null,
|
||||
hot: v.video_review,
|
||||
url: `https://www.bilibili.com/video/${v.bvid}`,
|
||||
mobileUrl: `https://m.bilibili.com/video/${v.bvid}`,
|
||||
})),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -42,6 +42,8 @@ const getList = async (noCache: boolean) => {
|
||||
title: dom.find("h3 a").text().trim(),
|
||||
cover: dom.find(".pic-wrap img").attr("src"),
|
||||
desc: dom.find(".block p").text().trim(),
|
||||
timestamp: dom.find("span.pubtime").text().trim(),
|
||||
hot: null,
|
||||
url,
|
||||
mobileUrl: `https://m.douban.com/group/topic/${getNumbers(url)}/`,
|
||||
};
|
||||
|
||||
@@ -50,9 +50,10 @@ const getList = async (noCache: boolean) => {
|
||||
title: `【${score}】${dom.find("a").attr("title")}`,
|
||||
cover: dom.find("img").attr("src"),
|
||||
desc: dom.find("p.pl").text(),
|
||||
timestamp: null,
|
||||
hot: getNumbers(dom.find("span.pl").text()),
|
||||
url,
|
||||
mobileUrl:`https://m.douban.com/movie/subject/${getNumbers(url)}/`,
|
||||
mobileUrl: `https://m.douban.com/movie/subject/${getNumbers(url)}/`,
|
||||
};
|
||||
});
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 { fromCache, data, updateTime } = await getList(noCache);
|
||||
@@ -51,6 +52,7 @@ const getList = async (noCache: boolean) => {
|
||||
data: list.map((v: RouterType["douyin"]) => ({
|
||||
id: v.sentence_id,
|
||||
title: v.word,
|
||||
timestamp: getTime(v.event_time),
|
||||
hot: v.hot_value,
|
||||
url: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
|
||||
mobileUrl: `https://www.douyin.com/hot/${encodeURIComponent(v.sentence_id)}`,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
const mappings = {
|
||||
O_TIME: "发震时刻(UTC+8)",
|
||||
@@ -68,6 +69,8 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
id: NEW_DID,
|
||||
title: `${LOCATION_C}发生${M}级地震`,
|
||||
desc: contentBuilder.join("\n"),
|
||||
timestamp: getTime(v["O_TIME"]),
|
||||
hot: null,
|
||||
url: `https://news.ceic.ac.cn/${NEW_DID}.html`,
|
||||
mobileUrl: `https://news.ceic.ac.cn/${NEW_DID}.html`,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
@@ -44,6 +45,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
desc: data.content,
|
||||
cover: data.cover,
|
||||
author: v.user.nickname,
|
||||
timestamp: getTime(data.created_at),
|
||||
hot: v.stat.view_num,
|
||||
url: `https://www.miyoushe.com/ys/article/${data.post_id}`,
|
||||
mobileUrl: `https://m.miyoushe.com/ys/#/article/${data.post_id}`,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const sort = c.req.query("sort") || "hot";
|
||||
@@ -41,6 +42,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
title: v.title,
|
||||
desc: v.summary,
|
||||
author: v.author,
|
||||
timestamp: getTime(v.updated_at),
|
||||
hot: v.clicks_total,
|
||||
url: `https://hellogithub.com/repository/${v.item_id}`,
|
||||
mobileUrl: `https://hellogithub.com/repository/${v.item_id}`,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
@@ -44,6 +45,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
desc: data.content,
|
||||
cover: data.cover || v.image_list[0].url,
|
||||
author: v.user.nickname,
|
||||
timestamp: getTime(data.created_at),
|
||||
hot: v.stat.view_num,
|
||||
url: `https://www.miyoushe.com/bh3/article/${data.post_id}`,
|
||||
mobileUrl: `https://m.miyoushe.com/bh3/#/article/${data.post_id}`,
|
||||
|
||||
66
src/routes/hostloc.ts
Normal file
66
src/routes/hostloc.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { web } from "../utils/getData.js";
|
||||
import { extractRss, parseRSS } from "../utils/parseRSS.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "hot";
|
||||
const { fromCache, data, updateTime } = await getList({ type }, noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "hostloc",
|
||||
title: "全球主机交流",
|
||||
type: "榜单",
|
||||
parameData: {
|
||||
type: {
|
||||
name: "榜单分类",
|
||||
type: {
|
||||
hot: "最新热门",
|
||||
digest: "最新精华",
|
||||
new: "最新回复",
|
||||
newthread: "最新发表",
|
||||
},
|
||||
},
|
||||
},
|
||||
link: "https://hostloc.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
|
||||
const getList = async (options: Options, noCache: boolean) => {
|
||||
const { type } = options;
|
||||
const url = `https://hostloc.com/forum.php?mod=guide&view=${type}&rss=1`;
|
||||
const result = await web({
|
||||
url,
|
||||
noCache,
|
||||
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);
|
||||
return await parseRSS(rssContent);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
const list = await parseData();
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: list.map((v: RouterType["discuz"]) => ({
|
||||
id: v.guid,
|
||||
title: v.title,
|
||||
desc: v.content,
|
||||
author: v.author,
|
||||
timestamp: getTime(v.pubDate),
|
||||
hot: null,
|
||||
url: v.link,
|
||||
mobileUrl: v.link,
|
||||
})),
|
||||
};
|
||||
};
|
||||
54
src/routes/huxiu.ts
Normal file
54
src/routes/huxiu.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
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 { fromCache, data, updateTime } = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "huxiu",
|
||||
title: "虎嗅",
|
||||
type: "24小时",
|
||||
link: "https://www.huxiu.com/moment/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
|
||||
// 标题处理
|
||||
const titleProcessing = (text: string) => {
|
||||
const paragraphs = text.split("<br><br>");
|
||||
const title = paragraphs.shift().replace(/。$/, "");
|
||||
const intro = paragraphs.join("<br><br>");
|
||||
return { title, intro };
|
||||
};
|
||||
|
||||
const getList = async (noCache: boolean) => {
|
||||
const url = `https://www.huxiu.com/moment/`;
|
||||
const result = await get({
|
||||
url,
|
||||
noCache,
|
||||
});
|
||||
// 正则查找
|
||||
const pattern =
|
||||
/<script>[\s\S]*?window\.__INITIAL_STATE__\s*=\s*(\{[\s\S]*?\});[\s\S]*?<\/script>/;
|
||||
const matchResult = result.data.match(pattern);
|
||||
const jsonObject = JSON.parse(matchResult[1]).moment.momentList.moment_list.datalist;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: jsonObject.map((v: RouterType["huxiu"]) => ({
|
||||
id: v.object_id,
|
||||
title: titleProcessing(v.content).title,
|
||||
desc: titleProcessing(v.content).intro,
|
||||
author: v.user_info.username,
|
||||
timestamp: getTime(v.publish_time),
|
||||
hot: null,
|
||||
url: v.url || "https://www.huxiu.com/moment/",
|
||||
mobileUrl: v.url || "https://m.huxiu.com/moment/",
|
||||
})),
|
||||
};
|
||||
};
|
||||
39
src/routes/ifanr.ts
Normal file
39
src/routes/ifanr.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 { fromCache, data, updateTime } = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "ifanr",
|
||||
title: "爱范儿",
|
||||
type: "快讯",
|
||||
description: "15秒了解全球新鲜事",
|
||||
link: "https://www.ifanr.com/digest/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
|
||||
const getList = async (noCache: boolean) => {
|
||||
const url = "https://sso.ifanr.com/api/v5/wp/buzz/?limit=20&offset=0";
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.objects;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: list.map((v: RouterType["ifanr"]) => ({
|
||||
id: v.id,
|
||||
title: v.post_title,
|
||||
desc: v.post_content,
|
||||
timestamp: getTime(v.created_at),
|
||||
hot: v.like_count || v.comment_count,
|
||||
url: `https://www.ifanr.com/${v.id}` || v.buzz_original_url,
|
||||
mobileUrl: `https://www.ifanr.com/digest/${v.id}` || v.buzz_original_url,
|
||||
})),
|
||||
};
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { RouterData } from "../types.js";
|
||||
import { load } from "cheerio";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
@@ -35,11 +36,15 @@ const getList = async (noCache: boolean) => {
|
||||
const listData = listDom.toArray().map((item) => {
|
||||
const dom = $(item);
|
||||
const href = dom.find("a").attr("href");
|
||||
const time = dom.find("span.time").text().trim();
|
||||
const match = time.match(/'([^']+)'/);
|
||||
const dateTime = match ? match[1] : null;
|
||||
return {
|
||||
id: href ? Number(replaceLink(href, true)) : 100000,
|
||||
title: dom.find(".newsbody h2").text().trim(),
|
||||
desc: dom.find(".newsbody p").text().trim(),
|
||||
cover: dom.find("img").attr("data-original"),
|
||||
timestamp: getTime(dateTime),
|
||||
hot: Number(dom.find(".comment").text().replace(/\D/g, "")),
|
||||
url: href || undefined,
|
||||
mobileUrl: href ? replaceLink(href) : undefined,
|
||||
|
||||
@@ -43,6 +43,7 @@ const getList = async (noCache: boolean) => {
|
||||
id: href ? Number(replaceLink(href, true)) : 100000,
|
||||
title: dom.find(".plc-title").text().trim(),
|
||||
cover: dom.find("img").attr("data-original"),
|
||||
timestamp: dom.find("span.post-time").text().trim(),
|
||||
hot: Number(dom.find(".review-num").text().replace(/\D/g, "")),
|
||||
url: href ? replaceLink(href) : undefined,
|
||||
mobileUrl: href || undefined,
|
||||
|
||||
@@ -45,6 +45,8 @@ const getList = async (noCache: boolean) => {
|
||||
cover: dom.find("img").attr("src"),
|
||||
desc: dom.find("p.abstract").text()?.trim(),
|
||||
author: dom.find("a.nickname").text()?.trim(),
|
||||
hot: null,
|
||||
timestamp: null,
|
||||
url: `https://www.jianshu.com${href}`,
|
||||
mobileUrl: `https://www.jianshu.com${href}`,
|
||||
};
|
||||
|
||||
@@ -29,6 +29,7 @@ const getList = async (noCache: boolean) => {
|
||||
title: v.content.title,
|
||||
author: v.author.name,
|
||||
hot: v.content_counter.hot_rank,
|
||||
timestamp: null,
|
||||
url: `https://juejin.cn/post/${v.content.content_id}`,
|
||||
mobileUrl: `https://juejin.cn/post/${v.content.content_id}`,
|
||||
})),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 { fromCache, data, updateTime } = await getList(noCache);
|
||||
@@ -31,6 +32,7 @@ const getList = async (noCache: boolean) => {
|
||||
cover: `https:${v.sIMG}`,
|
||||
author: v.sAuthor,
|
||||
hot: Number(v.iTotalPlay),
|
||||
timestamp: getTime(v.sCreated),
|
||||
url: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(v.iDocID)}`,
|
||||
mobileUrl: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(v.iDocID)}`,
|
||||
})),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 { fromCache, data, updateTime } = await getList(noCache);
|
||||
@@ -29,6 +30,8 @@ const getList = async (noCache: boolean) => {
|
||||
title: v.title,
|
||||
cover: v.imgsrc,
|
||||
author: v.source,
|
||||
hot: null,
|
||||
timestamp: getTime(v.ptime),
|
||||
url: `https://www.163.com/dy/article/${v.docid}.html`,
|
||||
mobileUrl: `https://m.163.com/dy/article/${v.docid}.html`,
|
||||
})),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { RouterData } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { post } from "../utils/getData.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
@@ -48,6 +49,7 @@ const getList = async (noCache: boolean) => {
|
||||
title: v.subject,
|
||||
author: v.author,
|
||||
hot: v.replies,
|
||||
timestamp: getTime(v.postdate),
|
||||
url: `https://bbs.nga.cn${v.tpcurl}`,
|
||||
mobileUrl: `https://bbs.nga.cn${v.tpcurl}`,
|
||||
})),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 { fromCache, data, updateTime } = await getList(noCache);
|
||||
@@ -19,7 +20,8 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
|
||||
const getList = async (noCache: boolean) => {
|
||||
const url = `https://r.inews.qq.com/gw/event/hot_ranking_list?page_size=50`;
|
||||
const result = await get({ url, noCache });const list = result.data.idlist[0].newslist.slice(1);
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.idlist[0].newslist.slice(1);
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
@@ -30,6 +32,7 @@ const getList = async (noCache: boolean) => {
|
||||
cover: v.miniProShareImage,
|
||||
author: v.source,
|
||||
hot: v.hotEvent.hotScore,
|
||||
timestamp: getTime(v.timestamp),
|
||||
url: `https://new.qq.com/rain/a/${v.id}`,
|
||||
mobileUrl: `https://view.inews.qq.com/k/${v.id}`,
|
||||
})),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "热门文章";
|
||||
@@ -38,6 +39,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
desc: v.summary,
|
||||
cover: v.banner,
|
||||
author: v.author.nickname,
|
||||
timestamp: getTime(v.released_time),
|
||||
hot: v.like_count,
|
||||
url: `https://sspai.com/post/${v.id}`,
|
||||
mobileUrl: `https://sspai.com/post/${v.id}`,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const type = c.req.query("type") || "1";
|
||||
@@ -44,6 +45,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
desc: data.content,
|
||||
cover: data.cover,
|
||||
author: v.user.nickname,
|
||||
timestamp: getTime(data.created_at),
|
||||
hot: v.stat.view_num,
|
||||
url: `https://www.miyoushe.com/sr/article/${data.post_id}`,
|
||||
mobileUrl: `https://m.miyoushe.com/sr/#/article/${data.post_id}`,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 { fromCache, data, updateTime } = await getList(noCache);
|
||||
@@ -29,6 +30,7 @@ const getList = async (noCache: boolean) => {
|
||||
title: v.name,
|
||||
cover: v.pic,
|
||||
hot: Number(v.praiseTimes),
|
||||
timestamp: getTime(v.pubTimeLong),
|
||||
url: `https://www.thepaper.cn/newsDetail_forward_${v.contId}`,
|
||||
mobileUrl: `https://m.thepaper.cn/newsDetail_forward_${v.contId}`,
|
||||
})),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 { fromCache, data, updateTime } = await getList(noCache);
|
||||
@@ -31,6 +32,7 @@ const getList = async (noCache: boolean) => {
|
||||
desc: v.topic_desc,
|
||||
cover: v.topic_pic,
|
||||
hot: v.discuss_num,
|
||||
timestamp: getTime(v.create_time),
|
||||
url: v.topic_url,
|
||||
mobileUrl: v.topic_url,
|
||||
})),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 { fromCache, data, updateTime } = await getList(noCache);
|
||||
@@ -28,6 +29,7 @@ const getList = async (noCache: boolean) => {
|
||||
id: v.ClusterIdStr,
|
||||
title: v.Title,
|
||||
cover: v.Image.url,
|
||||
timestamp: getTime(v.ClusterIdStr),
|
||||
hot: Number(v.HotValue),
|
||||
url: `https://www.toutiao.com/trending/${v.ClusterIdStr}/`,
|
||||
mobileUrl: `https://api.toutiaoapi.com/feoffline/amos_land/new/html/main/index.html?topic_id=${v.ClusterIdStr}`,
|
||||
|
||||
@@ -31,7 +31,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
const { type } = options;
|
||||
const url = `https://www.v2ex.com/api/topics/${type}.json`;
|
||||
const result = await get({ url, noCache });
|
||||
const list = result.data.data.list;
|
||||
const list = result.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
@@ -40,6 +40,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
title: v.title,
|
||||
desc: v.content,
|
||||
author: v.member.username,
|
||||
timestamp: null,
|
||||
hot: v.replies,
|
||||
url: v.url,
|
||||
mobileUrl: v.url,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { RouterData, ListContext, Options } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
const province = c.req.query("province") || "";
|
||||
@@ -38,6 +39,8 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
title: v.title,
|
||||
desc: v.issuetime + " " + v.title,
|
||||
cover: v.pic,
|
||||
timestamp: getTime(v.issuetime),
|
||||
hot: null,
|
||||
url: `http://nmc.cn${v.url}`,
|
||||
mobileUrl: `http://nmc.cn${v.url}`,
|
||||
})),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 { fromCache, data, updateTime } = await getList(noCache);
|
||||
@@ -32,6 +33,7 @@ const getList = async (noCache: boolean) => {
|
||||
title: v.word,
|
||||
desc: v.note || key,
|
||||
author: v.category,
|
||||
timestamp: getTime(v.onboard_time),
|
||||
hot: v.raw_hot,
|
||||
url: `https://s.weibo.com/weibo?q=${encodeURIComponent(key)}&t=31&band_rank=1&Refer=top`,
|
||||
mobileUrl: `https://s.weibo.com/weibo?q=${encodeURIComponent(
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { RouterData } from "../types.js";
|
||||
import type { RouterType } from "../router.types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import getWereadID from "../utils/getToken/weread.js";
|
||||
import getTime from "../utils/getTime.js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
@@ -40,6 +41,7 @@ const getList = async (noCache: boolean) => {
|
||||
author: data.author,
|
||||
desc: data.intro,
|
||||
cover: data.cover.replace("s_", "t9_"),
|
||||
timestamp: getTime(data.publishTime),
|
||||
hot: v.readingCount,
|
||||
url: `https://weread.qq.com/web/bookDetail/${getWereadID(data.bookId)}`,
|
||||
mobileUrl: `https://weread.qq.com/web/bookDetail/${getWereadID(data.bookId)}`,
|
||||
|
||||
@@ -19,13 +19,13 @@ export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
};
|
||||
|
||||
const getList = async (noCache: boolean) => {
|
||||
const url = `https://news-at.zhihu.com/api/4/news/latest`;
|
||||
const url = `https://daily.zhihu.com/api/4/news/latest`;
|
||||
const result = await get({
|
||||
url,
|
||||
noCache,
|
||||
headers: {
|
||||
Referer: "https://news-at.zhihu.com/api/4/news/latest",
|
||||
Host: "news-at.zhihu.com",
|
||||
Referer: "https://daily.zhihu.com/api/4/news/latest",
|
||||
Host: "daily.zhihu.com",
|
||||
},
|
||||
});
|
||||
const list = result.data.stories.filter((el: RouterType["zhihu-daily"]) => el.type === 0);
|
||||
@@ -37,6 +37,8 @@ const getList = async (noCache: boolean) => {
|
||||
title: v.title,
|
||||
cover: v.images[0],
|
||||
author: v.hint,
|
||||
hot: null,
|
||||
timestamp: null,
|
||||
url: v.url,
|
||||
mobileUrl: v.url,
|
||||
})),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 { fromCache, data, updateTime } = await getList(noCache);
|
||||
@@ -31,6 +32,7 @@ const getList = async (noCache: boolean) => {
|
||||
title: data.title,
|
||||
desc: data.excerpt,
|
||||
cover: v.children[0].thumbnail,
|
||||
timestamp: getTime(data.created),
|
||||
hot: parseInt(v.detail_text.replace(/[^\d]/g, "")) * 10000,
|
||||
url: `https://www.zhihu.com/question/${data.id}`,
|
||||
mobileUrl: `https://www.zhihu.com/question/${data.id}`,
|
||||
|
||||
14
src/types.ts → src/types.d.ts
vendored
14
src/types.ts → src/types.d.ts
vendored
@@ -10,7 +10,8 @@ export type ListItem = {
|
||||
cover?: string;
|
||||
author?: string;
|
||||
desc?: string;
|
||||
hot?: number;
|
||||
hot: number | null;
|
||||
timestamp: number | string | null;
|
||||
url: string | undefined;
|
||||
mobileUrl: string | undefined;
|
||||
};
|
||||
@@ -50,7 +51,18 @@ export type Post = {
|
||||
originaInfo?: boolean;
|
||||
};
|
||||
|
||||
export type Web = {
|
||||
url: string;
|
||||
timeout?: number;
|
||||
noCache?: boolean;
|
||||
ttl?: number;
|
||||
userAgent?: string;
|
||||
};
|
||||
|
||||
// 参数类型
|
||||
export type Options = {
|
||||
[key: string]: string | undefined;
|
||||
};
|
||||
|
||||
// serveHotApi
|
||||
export default function serveHotApi(port?: number): unknown;
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Get, Post } from "../types.ts";
|
||||
import type { Get, Post, Web } from "../types.ts";
|
||||
import { config } from "../config.js";
|
||||
import { getCache, setCache, delCache } from "./cache.js";
|
||||
import { Cluster } from "puppeteer-cluster";
|
||||
import logger from "./logger.js";
|
||||
import axios from "axios";
|
||||
|
||||
@@ -11,6 +12,27 @@ const request = axios.create({
|
||||
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) => {
|
||||
@@ -98,3 +120,33 @@ export const post = async (options: Post) => {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
28
src/utils/getTime.ts
Normal file
28
src/utils/getTime.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import dayjs from "dayjs";
|
||||
|
||||
const getTime = (timeInput: string | number): number => {
|
||||
try {
|
||||
let num: number | string;
|
||||
// 尝试将输入转换为数字
|
||||
if (typeof timeInput === "string") {
|
||||
num = Number(timeInput);
|
||||
// 检查转换结果是否为有效数字
|
||||
if (isNaN(num)) {
|
||||
// 处理为字符串的日期时间
|
||||
return dayjs(timeInput).valueOf();
|
||||
}
|
||||
} else {
|
||||
num = timeInput;
|
||||
}
|
||||
// 是否为毫秒级时间戳
|
||||
if (num > 946684800000) {
|
||||
return num;
|
||||
} else {
|
||||
return num * 1000;
|
||||
}
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export default getTime;
|
||||
41
src/utils/parseRSS.ts
Normal file
41
src/utils/parseRSS.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import RSSParser from "rss-parser";
|
||||
import logger from "./logger.js";
|
||||
|
||||
export const extractRss = (content: string): string | null => {
|
||||
// 匹配 <rss> 标签及内容
|
||||
const rssRegex = /(<rss[\s\S]*?<\/rss>)/i;
|
||||
const matches = content.match(rssRegex);
|
||||
return matches ? matches[0] : null;
|
||||
};
|
||||
export const parseRSS = async (rssContent: string) => {
|
||||
const parser = new RSSParser();
|
||||
// 是否为网址
|
||||
const isUrl = (url: string) => {
|
||||
try {
|
||||
new URL(url);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
try {
|
||||
const feed = isUrl(rssContent)
|
||||
? await parser.parseURL(rssContent)
|
||||
: await parser.parseString(rssContent);
|
||||
const items = feed.items.map((item) => ({
|
||||
title: item.title, // 文章标题
|
||||
link: item.link, // 文章链接
|
||||
pubDate: item.pubDate, // 发布日期
|
||||
author: item.creator ?? item.author, // 作者
|
||||
content: item.content, // 内容
|
||||
contentSnippet: item.contentSnippet, // 内容摘要
|
||||
guid: item.guid, // 全局唯一标识符
|
||||
categories: item.categories, // 分类
|
||||
}));
|
||||
// 返回解析数据
|
||||
return items;
|
||||
} catch (error) {
|
||||
logger.error("解析 RSS 内容时出错:", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -1,12 +1,7 @@
|
||||
import type { FC } from "hono/jsx";
|
||||
import { css, Style } from "hono/css";
|
||||
|
||||
type LayoutProps = {
|
||||
title: string;
|
||||
children: JSX.Element | JSX.Element[];
|
||||
};
|
||||
|
||||
const Layout: FC<LayoutProps> = (props) => {
|
||||
const Layout: FC = (props) => {
|
||||
const globalClass = css`
|
||||
:-hono-global {
|
||||
* {
|
||||
|
||||
@@ -20,7 +20,13 @@ const NotFound: FC = () => {
|
||||
</div>
|
||||
<div class="control">
|
||||
<button id="home-button">
|
||||
<svg className="btn-icon" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24">
|
||||
<svg
|
||||
className="btn-icon"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="32"
|
||||
height="32"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M10 19v-5h4v5c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-7h1.7c.46 0 .68-.57.33-.87L12.67 3.6c-.38-.34-.96-.34-1.34 0l-8.36 7.53c-.34.3-.13.87.33.87H5v7c0 .55.45 1 1 1h3c.55 0 1-.45 1-1"
|
||||
|
||||
Reference in New Issue
Block a user