mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 21:24:55 +08:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b610ef8cd | ||
|
|
d27ef0d116 | ||
|
|
d0dfba27dc | ||
|
|
293c4d623e | ||
|
|
097a1b3628 | ||
|
|
ec50d5ced1 | ||
|
|
c713d34ba1 | ||
|
|
c4772962f4 | ||
|
|
36802252c0 | ||
|
|
7f5449089d | ||
|
|
53c68a3d69 | ||
|
|
447e0c6153 | ||
|
|
55f4e22693 | ||
|
|
c791e29a59 | ||
|
|
91775a0763 | ||
|
|
a742f9df78 | ||
|
|
f213d9810b | ||
|
|
250a90cf2e | ||
|
|
a4a1055604 | ||
|
|
fd3d911b04 |
@@ -4,6 +4,10 @@ PORT = 6688
|
||||
# 允许的域名
|
||||
ALLOWED_DOMAIN = "*"
|
||||
|
||||
# 允许的主域名,填写格式为 imsyy.top
|
||||
## 若填写该项,将忽略 ALLOWED_DOMAIN
|
||||
ALLOWED_HOST = ""
|
||||
|
||||
# ROBOT
|
||||
DISALLOW_ROBOT = true
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@ node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
*.local
|
||||
.env
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
|
||||
@@ -15,10 +15,13 @@ FROM base AS builder
|
||||
RUN npm install -g pnpm
|
||||
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 public ./public
|
||||
|
||||
# add .env.example to .env
|
||||
RUN [ ! -e ".env" ] && cp .env.example .env || true
|
||||
|
||||
RUN pnpm install
|
||||
RUN pnpm build
|
||||
RUN pnpm prune --production
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
| 36 氪 | 热榜 | 36kr | 🟢 |
|
||||
| 51CTO | 推荐榜 | 51cto | 🟢 |
|
||||
| CSDN | 排行榜 | csdn | 🟢 |
|
||||
| NodeSeek | 最新动态 | nodeseek | 🟠 |
|
||||
| 稀土掘金 | 热榜 | juejin | 🟢 |
|
||||
| 腾讯新闻 | 热点榜 | qq-news | 🟢 |
|
||||
| 新浪网 | 热榜 | sina | 🟢 |
|
||||
@@ -61,6 +62,7 @@
|
||||
| 吾爱破解 | 榜单 | 52pojie | ❌ |
|
||||
| 全球主机交流 | 榜单 | hostloc | ❌ |
|
||||
| 虎嗅 | 24小时 | huxiu | 🟢 |
|
||||
| 酷安 | 热榜 | coolapk | 🟢 |
|
||||
| 虎扑 | 步行街热帖 | hupu | 🟢 |
|
||||
| 爱范儿 | 快讯 | ifanr | 🟢 |
|
||||
| 英雄联盟 | 更新公告 | lol | 🟢 |
|
||||
@@ -71,8 +73,8 @@
|
||||
| NGA | 热帖 | ngabbs | 🟢 |
|
||||
| V2EX | 主题榜 | v2ex | ⚠️ |
|
||||
| HelloGitHub | Trending | hellogithub | 🟢 |
|
||||
| 中央气象台 | 全国气象预警 | weatheralarm | 🟢 |
|
||||
| 中国地震台 | 地震速报 | earthquake | 🟢 |
|
||||
| 中央气象台 | 全国气象预警 | weatheralarm | 🟠 |
|
||||
| 中国地震台 | 地震速报 | earthquake | 🟠 |
|
||||
| 历史上的今天 | 月-日 | history | 🟢 |
|
||||
|
||||
</details>
|
||||
@@ -141,6 +143,8 @@ cd DailyHotApi
|
||||
npm install
|
||||
```
|
||||
|
||||
复制 `/.env.example` 文件并重命名为 `/.env` 并修改配置
|
||||
|
||||
#### 开发
|
||||
|
||||
```bash
|
||||
|
||||
28
package.json
28
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dailyhot-api",
|
||||
"version": "2.0.3",
|
||||
"version": "2.0.6",
|
||||
"description": "An Api on Today's Hot list",
|
||||
"keywords": [
|
||||
"API",
|
||||
@@ -32,32 +32,34 @@
|
||||
"dev": "cross-env NODE_ENV=development tsx watch --no-cache src/index.ts",
|
||||
"dev:cache": "cross-env NODE_ENV=development tsx watch src/index.ts",
|
||||
"build": "tsc --project tsconfig.json",
|
||||
"start": "tsx src/index.ts"
|
||||
"start": "cross-env NODE_ENV=development tsx dist/index.js"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@hono/node-server": "^1.11.2",
|
||||
"axios": "^1.7.2",
|
||||
"@hono/node-server": "^1.13.5",
|
||||
"axios": "^1.7.7",
|
||||
"chalk": "^5.3.0",
|
||||
"cheerio": "1.0.0-rc.12",
|
||||
"dayjs": "^1.11.11",
|
||||
"dayjs": "^1.11.13",
|
||||
"dotenv": "^16.4.5",
|
||||
"feed": "^4.2.2",
|
||||
"hono": "^4.4.5",
|
||||
"hono": "^4.6.9",
|
||||
"md5": "^2.3.0",
|
||||
"node-cache": "^5.1.2",
|
||||
"rss-parser": "^3.13.0",
|
||||
"winston": "^3.13.0"
|
||||
"winston": "^3.16.0",
|
||||
"xml2js": "^0.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.14.2",
|
||||
"@typescript-eslint/eslint-plugin": "^7.13.0",
|
||||
"@typescript-eslint/parser": "^7.13.0",
|
||||
"@types/node": "^20.17.6",
|
||||
"@types/xml2js": "^0.4.14",
|
||||
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
||||
"@typescript-eslint/parser": "^7.18.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.57.0",
|
||||
"prettier": "^3.3.2",
|
||||
"eslint": "^8.57.1",
|
||||
"prettier": "^3.3.3",
|
||||
"tsx": "^3.14.0",
|
||||
"typescript": "^5.4.5"
|
||||
"typescript": "^5.6.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
|
||||
511
pnpm-lock.yaml
generated
511
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -28,7 +28,11 @@ app.use(
|
||||
"*",
|
||||
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"],
|
||||
allowHeaders: ["X-Custom-Header", "Upgrade-Insecure-Requests"],
|
||||
credentials: true,
|
||||
|
||||
@@ -9,6 +9,7 @@ export type Config = {
|
||||
CACHE_TTL: number;
|
||||
REQUEST_TIMEOUT: number;
|
||||
ALLOWED_DOMAIN: string;
|
||||
ALLOWED_HOST: string;
|
||||
USE_LOG_FILE: boolean;
|
||||
RSS_MODE: boolean;
|
||||
};
|
||||
@@ -45,6 +46,7 @@ export const config: Config = {
|
||||
CACHE_TTL: getNumericEnvVariable("CACHE_TTL", 3600),
|
||||
REQUEST_TIMEOUT: getNumericEnvVariable("CACHE_TTL", 6000),
|
||||
ALLOWED_DOMAIN: getEnvVariable("ALLOWED_DOMAIN") || "*",
|
||||
ALLOWED_HOST: getEnvVariable("ALLOWED_HOST") || "imsyy.top",
|
||||
USE_LOG_FILE: getBooleanEnvVariable("USE_LOG_FILE", true),
|
||||
RSS_MODE: getBooleanEnvVariable("RSS_MODE", false),
|
||||
};
|
||||
|
||||
18
src/router.types.d.ts
vendored
18
src/router.types.d.ts
vendored
@@ -85,8 +85,8 @@ export type RouterType = {
|
||||
word: string;
|
||||
word_scheme: string;
|
||||
note: string;
|
||||
category: string;
|
||||
raw_hot: number;
|
||||
flag_desc: string;
|
||||
num: number;
|
||||
onboard_time: number;
|
||||
};
|
||||
zhihu: {
|
||||
@@ -126,9 +126,8 @@ export type RouterType = {
|
||||
content: string;
|
||||
cover: string;
|
||||
created_at: number;
|
||||
};
|
||||
stat: {
|
||||
view_num: number;
|
||||
view_status: number;
|
||||
images: string[];
|
||||
};
|
||||
user: {
|
||||
nickname: string;
|
||||
@@ -307,4 +306,13 @@ export type RouterType = {
|
||||
top_num: string;
|
||||
time: string;
|
||||
};
|
||||
coolapk: {
|
||||
id: number;
|
||||
ttitle: string;
|
||||
shareUrl: string;
|
||||
username:string;
|
||||
tpic: string;
|
||||
message: string;
|
||||
replynum: number;
|
||||
};
|
||||
};
|
||||
|
||||
44
src/routes/coolapk.ts
Normal file
44
src/routes/coolapk.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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 { fromCache, data, updateTime } = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "coolapk",
|
||||
title: "酷安",
|
||||
type: "热榜",
|
||||
link: "https://www.coolapk.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
};
|
||||
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: await genHeaders(),
|
||||
});
|
||||
const list = result.data.data;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: list.map((v: RouterType["coolapk"]) => ({
|
||||
id: v.id,
|
||||
title: v.message,
|
||||
cover: v.tpic,
|
||||
author: v.username,
|
||||
desc: v.ttitle,
|
||||
timestamp: null,
|
||||
hot: null,
|
||||
url: v.shareUrl,
|
||||
mobileUrl: v.shareUrl,
|
||||
})),
|
||||
};
|
||||
};
|
||||
@@ -54,8 +54,8 @@ const getList = async (noCache: boolean) => {
|
||||
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)}`,
|
||||
url: `https://www.douyin.com/hot/${v.sentence_id}`,
|
||||
mobileUrl: `https://www.douyin.com/hot/${v.sentence_id}`,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -31,7 +31,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
|
||||
const getList = async (options: Options, noCache: boolean) => {
|
||||
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 list = result.data.data.list;
|
||||
return {
|
||||
@@ -43,10 +43,10 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
id: data.post_id,
|
||||
title: data.subject,
|
||||
desc: data.content,
|
||||
cover: data.cover,
|
||||
author: v.user.nickname,
|
||||
cover: data.cover || data?.images?.[0],
|
||||
author: v.user?.nickname || null,
|
||||
timestamp: getTime(data.created_at),
|
||||
hot: v.stat.view_num,
|
||||
hot: data.view_status,
|
||||
url: `https://www.miyoushe.com/ys/article/${data.post_id}`,
|
||||
mobileUrl: `https://m.miyoushe.com/ys/#/article/${data.post_id}`,
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
data: list.map((v: RouterType["history"], index: number) => ({
|
||||
id: index,
|
||||
title: load(v.title).text().trim(),
|
||||
cover: v.cover ? v.pic_share : null || null,
|
||||
cover: v.cover ? v.pic_share : null,
|
||||
desc: load(v.desc).text().trim(),
|
||||
year: v.year,
|
||||
timestamp: null,
|
||||
|
||||
@@ -31,7 +31,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
|
||||
const getList = async (options: Options, noCache: boolean) => {
|
||||
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 list = result.data.data.list;
|
||||
return {
|
||||
@@ -43,10 +43,10 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
id: data.post_id,
|
||||
title: data.subject,
|
||||
desc: data.content,
|
||||
cover: data.cover || v.image_list[0].url,
|
||||
author: v.user.nickname,
|
||||
cover: data.cover || data?.images?.[0],
|
||||
author: v.user?.nickname || null,
|
||||
timestamp: getTime(data.created_at),
|
||||
hot: v.stat.view_num,
|
||||
hot: data.view_status,
|
||||
url: `https://www.miyoushe.com/bh3/article/${data.post_id}`,
|
||||
mobileUrl: `https://m.miyoushe.com/bh3/#/article/${data.post_id}`,
|
||||
};
|
||||
|
||||
47
src/routes/nodeseek.ts
Normal file
47
src/routes/nodeseek.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import type { RouterData } from "../types.js";
|
||||
import { get } from "../utils/getData.js";
|
||||
import { parseStringPromise } from "xml2js";
|
||||
|
||||
export const handleRoute = async (_: undefined, noCache: boolean) => {
|
||||
const { fromCache, data, updateTime } = await getList(noCache);
|
||||
const routeData: RouterData = {
|
||||
name: "nodeseek",
|
||||
title: "NodeSeek",
|
||||
type: "最新",
|
||||
params: {
|
||||
type: {
|
||||
name: "分类",
|
||||
type: {
|
||||
all: "所有",
|
||||
},
|
||||
},
|
||||
},
|
||||
link: "https://www.nodeseek.com/",
|
||||
total: data?.length || 0,
|
||||
updateTime,
|
||||
fromCache,
|
||||
data,
|
||||
};
|
||||
return routeData;
|
||||
};
|
||||
|
||||
const getList = async (noCache: boolean) => {
|
||||
const url = `https://rss.nodeseek.com/`;
|
||||
const result = await get({ url, noCache });
|
||||
const rssData = await parseStringPromise(result.data);
|
||||
const list = rssData.rss.channel[0].item;
|
||||
return {
|
||||
fromCache: result.fromCache,
|
||||
updateTime: result.updateTime,
|
||||
data: list.map((v) => ({
|
||||
id: v.guid[0]._,
|
||||
title: v.title[0],
|
||||
desc: v.description ? v.description[0] : "",
|
||||
author: v["dc:creator"] ? v["dc:creator"][0] : "unknown",
|
||||
timestamp: new Date(v.pubDate[0]).getTime(),
|
||||
hot: null, // NodeSeek RSS 中没有类似于hot的字段
|
||||
url: v.link[0],
|
||||
mobileUrl: v.link[0],
|
||||
})),
|
||||
};
|
||||
};
|
||||
@@ -31,7 +31,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
|
||||
const getList = async (options: Options, noCache: boolean) => {
|
||||
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 list = result.data.data.list;
|
||||
return {
|
||||
@@ -43,10 +43,10 @@ const getList = async (options: Options, noCache: boolean) => {
|
||||
id: data.post_id,
|
||||
title: data.subject,
|
||||
desc: data.content,
|
||||
cover: data.cover,
|
||||
author: v.user.nickname,
|
||||
cover: data.cover || data?.images?.[0],
|
||||
author: v.user?.nickname || null,
|
||||
timestamp: getTime(data.created_at),
|
||||
hot: v.stat.view_num,
|
||||
hot: data.view_status,
|
||||
url: `https://www.miyoushe.com/sr/article/${data.post_id}`,
|
||||
mobileUrl: `https://m.miyoushe.com/sr/#/article/${data.post_id}`,
|
||||
};
|
||||
|
||||
@@ -32,9 +32,9 @@ const getList = async (noCache: boolean) => {
|
||||
id: v.mid,
|
||||
title: v.word,
|
||||
desc: v.note || key,
|
||||
author: v.category,
|
||||
author: v.flag_desc,
|
||||
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`,
|
||||
mobileUrl: `https://s.weibo.com/weibo?q=${encodeURIComponent(
|
||||
key,
|
||||
|
||||
@@ -35,7 +35,7 @@ const getList = async (noCache: boolean) => {
|
||||
data: list.map((v: RouterType["zhihu-daily"]) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
cover: v.images[0],
|
||||
cover: v.images?.[0] ?? null,
|
||||
author: v.hint,
|
||||
hot: null,
|
||||
timestamp: null,
|
||||
|
||||
@@ -33,7 +33,7 @@ const getList = async (noCache: boolean) => {
|
||||
desc: data.excerpt,
|
||||
cover: v.children[0].thumbnail,
|
||||
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}`,
|
||||
mobileUrl: `https://www.zhihu.com/question/${data.id}`,
|
||||
};
|
||||
|
||||
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 = async () => {
|
||||
const DEVICE_ID = getRandomDEVICE_ID();
|
||||
const now = Math.round(Date.now() / 1000);
|
||||
const hex_now = "0x" + now.toString(16);
|
||||
const md5_now = await md5(now.toString());
|
||||
const s =
|
||||
"token://com.coolapk.market/c67ef5943784d09750dcfbb31020f0ab?" +
|
||||
md5_now +
|
||||
"$" +
|
||||
DEVICE_ID +
|
||||
"&com.coolapk.market";
|
||||
const md5_s = await md5(Buffer.from(s).toString("base64"));
|
||||
const token = md5_s + DEVICE_ID + hex_now;
|
||||
return token;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取请求头
|
||||
* @returns 请求头
|
||||
*/
|
||||
export const genHeaders = async () => {
|
||||
return {
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
"X-App-Id": "com.coolapk.market",
|
||||
"X-App-Token": await 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",
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user