mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 05:04:56 +08:00
✨ feat: 支持 Redis
This commit is contained in:
@@ -11,6 +11,11 @@ ALLOWED_HOST=""
|
||||
# ROBOT
|
||||
DISALLOW_ROBOT=true
|
||||
|
||||
# Redis
|
||||
REDIS_HOST="127.0.0.1"
|
||||
REDIS_PORT=6379
|
||||
REDIS_PASSWORD=""
|
||||
|
||||
# 缓存时长( 秒 )
|
||||
CACHE_TTL=3600
|
||||
|
||||
|
||||
92
README.md
92
README.md
@@ -33,52 +33,52 @@
|
||||
> 示例站点运行于海外服务器,部分国内站点可能存在访问异常,请以实际情况为准
|
||||
|
||||
| **站点** | **类别** | **调用名称** | **状态** |
|
||||
| ---------------- | ------------ | -------------- | --------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 哔哩哔哩 | 热门榜 | bilibili |  |
|
||||
| AcFun | 排行榜 | acfun |  |
|
||||
| 微博 | 热搜榜 | weibo |  |
|
||||
| 知乎 | 热榜 | zhihu |  |
|
||||
| 知乎日报 | 推荐榜 | zhihu-daily |  |
|
||||
| 百度 | 热搜榜 | baidu |  |
|
||||
| 抖音 | 热点榜 | douyin |  |
|
||||
| 快手 | 热点榜 | kuaishou |  |
|
||||
| 豆瓣电影 | 新片榜 | douban-movie |  |
|
||||
| 豆瓣讨论小组 | 讨论精选 | douban-group |  |
|
||||
| 百度贴吧 | 热议榜 | tieba |  |
|
||||
| 少数派 | 热榜 | sspai |  |
|
||||
| IT之家 | 热榜 | ithome |  |
|
||||
| IT之家「喜加一」 | 最新动态 | ithome-xijiayi |  |
|
||||
| 简书 | 热门推荐 | jianshu |  |
|
||||
| 果壳 | 热门文章 | guokr |  |
|
||||
| 澎湃新闻 | 热榜 | thepaper |  |
|
||||
| 今日头条 | 热榜 | toutiao |  |
|
||||
| 36 氪 | 热榜 | 36kr |  |
|
||||
| 51CTO | 推荐榜 | 51cto |  |
|
||||
| CSDN | 排行榜 | csdn |  |
|
||||
| NodeSeek | 最新动态 | nodeseek |  |
|
||||
| 稀土掘金 | 热榜 | juejin |  |
|
||||
| 腾讯新闻 | 热点榜 | qq-news |  |
|
||||
| 新浪网 | 热榜 | sina |  |
|
||||
| 新浪新闻 | 热点榜 | sina-news |  |
|
||||
| 网易新闻 | 热点榜 | netease-news |  |
|
||||
| 吾爱破解 | 榜单 | 52pojie |  |
|
||||
| 全球主机交流 | 榜单 | hostloc |  |
|
||||
| 虎嗅 | 24小时 | huxiu |  |
|
||||
| 酷安 | 热榜 | coolapk |  |
|
||||
| 虎扑 | 步行街热帖 | hupu |  |
|
||||
| 爱范儿 | 快讯 | ifanr |  |
|
||||
| 英雄联盟 | 更新公告 | lol |  |
|
||||
| 米游社 | 最新消息 | miyoushe |  |
|
||||
| 原神 | 最新消息 | genshin |  |
|
||||
| 崩坏3 | 最新动态 | honkai |  |
|
||||
| 崩坏:星穹铁道 | 最新动态 | starrail |  |
|
||||
| 微信读书 | 飙升榜 | weread |  |
|
||||
| NGA | 热帖 | ngabbs |  |
|
||||
| V2EX | 主题榜 | v2ex |  |
|
||||
| HelloGitHub | Trending | hellogithub |  |
|
||||
| 中央气象台 | 全国气象预警 | weatheralarm |  |
|
||||
| 中国地震台 | 地震速报 | earthquake |  |
|
||||
| 历史上的今天 | 月-日 | history |  |
|
||||
| ---------------- | ------------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 哔哩哔哩 | 热门榜 | bilibili |  |
|
||||
| AcFun | 排行榜 | acfun |  |
|
||||
| 微博 | 热搜榜 | weibo |  |
|
||||
| 知乎 | 热榜 | zhihu |  |
|
||||
| 知乎日报 | 推荐榜 | zhihu-daily |  |
|
||||
| 百度 | 热搜榜 | baidu |  |
|
||||
| 抖音 | 热点榜 | douyin |  |
|
||||
| 快手 | 热点榜 | kuaishou |  |
|
||||
| 豆瓣电影 | 新片榜 | douban-movie |  |
|
||||
| 豆瓣讨论小组 | 讨论精选 | douban-group |  |
|
||||
| 百度贴吧 | 热议榜 | tieba |  |
|
||||
| 少数派 | 热榜 | sspai |  |
|
||||
| IT之家 | 热榜 | ithome |  |
|
||||
| IT之家「喜加一」 | 最新动态 | ithome-xijiayi |  |
|
||||
| 简书 | 热门推荐 | jianshu |  |
|
||||
| 果壳 | 热门文章 | guokr |  |
|
||||
| 澎湃新闻 | 热榜 | thepaper |  |
|
||||
| 今日头条 | 热榜 | toutiao |  |
|
||||
| 36 氪 | 热榜 | 36kr |  |
|
||||
| 51CTO | 推荐榜 | 51cto |  |
|
||||
| CSDN | 排行榜 | csdn |  |
|
||||
| NodeSeek | 最新动态 | nodeseek |  |
|
||||
| 稀土掘金 | 热榜 | juejin |  |
|
||||
| 腾讯新闻 | 热点榜 | qq-news |  |
|
||||
| 新浪网 | 热榜 | sina |  |
|
||||
| 新浪新闻 | 热点榜 | sina-news |  |
|
||||
| 网易新闻 | 热点榜 | netease-news |  |
|
||||
| 吾爱破解 | 榜单 | 52pojie |  |
|
||||
| 全球主机交流 | 榜单 | hostloc |  |
|
||||
| 虎嗅 | 24小时 | huxiu |  |
|
||||
| 酷安 | 热榜 | coolapk |  |
|
||||
| 虎扑 | 步行街热帖 | hupu |  |
|
||||
| 爱范儿 | 快讯 | ifanr |  |
|
||||
| 英雄联盟 | 更新公告 | lol |  |
|
||||
| 米游社 | 最新消息 | miyoushe |  |
|
||||
| 原神 | 最新消息 | genshin |  |
|
||||
| 崩坏3 | 最新动态 | honkai |  |
|
||||
| 崩坏:星穹铁道 | 最新动态 | starrail |  |
|
||||
| 微信读书 | 飙升榜 | weread |  |
|
||||
| NGA | 热帖 | ngabbs |  |
|
||||
| V2EX | 主题榜 | v2ex |  |
|
||||
| HelloGitHub | Trending | hellogithub |  |
|
||||
| 中央气象台 | 全国气象预警 | weatheralarm |  |
|
||||
| 中国地震台 | 地震速报 | earthquake |  |
|
||||
| 历史上的今天 | 月-日 | history |  |
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
@@ -45,10 +45,12 @@
|
||||
"feed": "^4.2.2",
|
||||
"hono": "^4.6.12",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"ioredis": "^5.4.1",
|
||||
"md5": "^2.3.0",
|
||||
"node-cache": "^5.1.2",
|
||||
"rss-parser": "^3.13.0",
|
||||
"user-agents": "^1.1.379",
|
||||
"uuid": "^11.0.3",
|
||||
"winston": "^3.17.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
76
pnpm-lock.yaml
generated
76
pnpm-lock.yaml
generated
@@ -35,6 +35,9 @@ importers:
|
||||
iconv-lite:
|
||||
specifier: ^0.6.3
|
||||
version: 0.6.3
|
||||
ioredis:
|
||||
specifier: ^5.4.1
|
||||
version: 5.4.1
|
||||
md5:
|
||||
specifier: ^2.3.0
|
||||
version: 2.3.0
|
||||
@@ -47,6 +50,9 @@ importers:
|
||||
user-agents:
|
||||
specifier: ^1.1.379
|
||||
version: 1.1.379
|
||||
uuid:
|
||||
specifier: ^11.0.3
|
||||
version: 11.0.3
|
||||
winston:
|
||||
specifier: ^3.17.0
|
||||
version: 3.17.0
|
||||
@@ -307,6 +313,9 @@ packages:
|
||||
resolution: {integrity: sha512-c7hNEllBlenFTHBky65mhq8WD2kbN9Q6gk0bTk8lSBvc554jpXSkST1iePudpt7+A/AQvuHs9EMqjHDXMY1lrA==}
|
||||
engines: {node: '>=18.18'}
|
||||
|
||||
'@ioredis/commands@1.2.0':
|
||||
resolution: {integrity: sha512-Sx1pU8EM64o2BrqNpEO1CNLtKQwyhuXuqyfH7oGKCk+1a33d2r5saW8zNwm3j6BTExtjrv2BxTgzzkMwts6vGg==}
|
||||
|
||||
'@nodelib/fs.scandir@2.1.5':
|
||||
resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
|
||||
engines: {node: '>= 8'}
|
||||
@@ -473,6 +482,10 @@ packages:
|
||||
resolution: {integrity: sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==}
|
||||
engines: {node: '>=0.8'}
|
||||
|
||||
cluster-key-slot@1.1.2:
|
||||
resolution: {integrity: sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
color-convert@1.9.3:
|
||||
resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==}
|
||||
|
||||
@@ -540,6 +553,10 @@ packages:
|
||||
resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
|
||||
engines: {node: '>=0.4.0'}
|
||||
|
||||
denque@2.1.0:
|
||||
resolution: {integrity: sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==}
|
||||
engines: {node: '>=0.10'}
|
||||
|
||||
dom-serializer@2.0.0:
|
||||
resolution: {integrity: sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==}
|
||||
|
||||
@@ -736,6 +753,10 @@ packages:
|
||||
inherits@2.0.4:
|
||||
resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==}
|
||||
|
||||
ioredis@5.4.1:
|
||||
resolution: {integrity: sha512-2YZsvl7jopIa1gaePkeMtd9rAcSjOOjPtpcLlOeusyO+XH2SK5ZcT+UCrElPP+WVIInh2TzeI4XW9ENaSLVVHA==}
|
||||
engines: {node: '>=12.22.0'}
|
||||
|
||||
is-arrayish@0.3.2:
|
||||
resolution: {integrity: sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==}
|
||||
|
||||
@@ -791,6 +812,12 @@ packages:
|
||||
lodash.clonedeep@4.5.0:
|
||||
resolution: {integrity: sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==}
|
||||
|
||||
lodash.defaults@4.2.0:
|
||||
resolution: {integrity: sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ==}
|
||||
|
||||
lodash.isarguments@3.1.0:
|
||||
resolution: {integrity: sha512-chi4NHZlZqZD18a0imDHnZPrDeBbTtVN7GXMwuGdRH9qotxAjYs3aVLKc7zNOG9eddR5Ksd8rvFEBc9SsggPpg==}
|
||||
|
||||
lodash.merge@4.6.2:
|
||||
resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}
|
||||
|
||||
@@ -900,6 +927,14 @@ packages:
|
||||
resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==}
|
||||
engines: {node: '>= 6'}
|
||||
|
||||
redis-errors@1.2.0:
|
||||
resolution: {integrity: sha512-1qny3OExCf0UvUV/5wpYKf2YwPcOqXzkwKKSmKHiE6ZMQs5heeE/c8eXK+PNllPvmjgAbfnsbpkGZWy8cBpn9w==}
|
||||
engines: {node: '>=4'}
|
||||
|
||||
redis-parser@3.0.0:
|
||||
resolution: {integrity: sha512-DJnGAeenTdpMEH6uAJRK/uiyEIH9WVsUmoLwzudwGJUwZPp80PDBWPHXSAGNPwNvIXAbe7MSUB1zQFugFml66A==}
|
||||
engines: {node: '>=4'}
|
||||
|
||||
resolve-from@4.0.0:
|
||||
resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==}
|
||||
engines: {node: '>=4'}
|
||||
@@ -949,6 +984,9 @@ packages:
|
||||
stack-trace@0.0.10:
|
||||
resolution: {integrity: sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==}
|
||||
|
||||
standard-as-callback@2.1.0:
|
||||
resolution: {integrity: sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A==}
|
||||
|
||||
string_decoder@1.3.0:
|
||||
resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==}
|
||||
|
||||
@@ -1017,6 +1055,10 @@ packages:
|
||||
util-deprecate@1.0.2:
|
||||
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
|
||||
|
||||
uuid@11.0.3:
|
||||
resolution: {integrity: sha512-d0z310fCWv5dJwnX1Y/MncBAqGMKEzlBb1AOf7z9K8ALnd0utBX/msg/fA0+sbyN1ihbMsLhrBlnl1ak7Wa0rg==}
|
||||
hasBin: true
|
||||
|
||||
whatwg-encoding@3.1.1:
|
||||
resolution: {integrity: sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==}
|
||||
engines: {node: '>=18'}
|
||||
@@ -1196,6 +1238,8 @@ snapshots:
|
||||
|
||||
'@humanwhocodes/retry@0.4.1': {}
|
||||
|
||||
'@ioredis/commands@1.2.0': {}
|
||||
|
||||
'@nodelib/fs.scandir@2.1.5':
|
||||
dependencies:
|
||||
'@nodelib/fs.stat': 2.0.5
|
||||
@@ -1392,6 +1436,8 @@ snapshots:
|
||||
|
||||
clone@2.1.2: {}
|
||||
|
||||
cluster-key-slot@1.1.2: {}
|
||||
|
||||
color-convert@1.9.3:
|
||||
dependencies:
|
||||
color-name: 1.1.3
|
||||
@@ -1457,6 +1503,8 @@ snapshots:
|
||||
|
||||
delayed-stream@1.0.0: {}
|
||||
|
||||
denque@2.1.0: {}
|
||||
|
||||
dom-serializer@2.0.0:
|
||||
dependencies:
|
||||
domelementtype: 2.3.0
|
||||
@@ -1684,6 +1732,20 @@ snapshots:
|
||||
|
||||
inherits@2.0.4: {}
|
||||
|
||||
ioredis@5.4.1:
|
||||
dependencies:
|
||||
'@ioredis/commands': 1.2.0
|
||||
cluster-key-slot: 1.1.2
|
||||
debug: 4.3.7
|
||||
denque: 2.1.0
|
||||
lodash.defaults: 4.2.0
|
||||
lodash.isarguments: 3.1.0
|
||||
redis-errors: 1.2.0
|
||||
redis-parser: 3.0.0
|
||||
standard-as-callback: 2.1.0
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
is-arrayish@0.3.2: {}
|
||||
|
||||
is-buffer@1.1.6: {}
|
||||
@@ -1727,6 +1789,10 @@ snapshots:
|
||||
|
||||
lodash.clonedeep@4.5.0: {}
|
||||
|
||||
lodash.defaults@4.2.0: {}
|
||||
|
||||
lodash.isarguments@3.1.0: {}
|
||||
|
||||
lodash.merge@4.6.2: {}
|
||||
|
||||
logform@2.7.0:
|
||||
@@ -1837,6 +1903,12 @@ snapshots:
|
||||
string_decoder: 1.3.0
|
||||
util-deprecate: 1.0.2
|
||||
|
||||
redis-errors@1.2.0: {}
|
||||
|
||||
redis-parser@3.0.0:
|
||||
dependencies:
|
||||
redis-errors: 1.2.0
|
||||
|
||||
resolve-from@4.0.0: {}
|
||||
|
||||
resolve-pkg-maps@1.0.0: {}
|
||||
@@ -1874,6 +1946,8 @@ snapshots:
|
||||
|
||||
stack-trace@0.0.10: {}
|
||||
|
||||
standard-as-callback@2.1.0: {}
|
||||
|
||||
string_decoder@1.3.0:
|
||||
dependencies:
|
||||
safe-buffer: 5.2.1
|
||||
@@ -1934,6 +2008,8 @@ snapshots:
|
||||
|
||||
util-deprecate@1.0.2: {}
|
||||
|
||||
uuid@11.0.3: {}
|
||||
|
||||
whatwg-encoding@3.1.1:
|
||||
dependencies:
|
||||
iconv-lite: 0.6.3
|
||||
|
||||
@@ -12,6 +12,9 @@ export type Config = {
|
||||
ALLOWED_HOST: string;
|
||||
USE_LOG_FILE: boolean;
|
||||
RSS_MODE: boolean;
|
||||
REDIS_HOST: string;
|
||||
REDIS_PORT: number;
|
||||
REDIS_PASSWORD: string;
|
||||
};
|
||||
|
||||
// 验证并提取环境变量
|
||||
@@ -45,4 +48,7 @@ export const config: Config = {
|
||||
ALLOWED_HOST: getEnvVariable("ALLOWED_HOST") || "imsyy.top",
|
||||
USE_LOG_FILE: getBooleanEnvVariable("USE_LOG_FILE", true),
|
||||
RSS_MODE: getBooleanEnvVariable("RSS_MODE", false),
|
||||
REDIS_HOST: getEnvVariable("REDIS_HOST") || "127.0.0.1",
|
||||
REDIS_PORT: getNumericEnvVariable("REDIS_PORT", 6379),
|
||||
REDIS_PASSWORD: getEnvVariable("REDIS_PASSWORD") || "",
|
||||
};
|
||||
|
||||
@@ -48,7 +48,7 @@ const findTsFiles = (dirPath: string, allFiles: string[] = [], basePath: string
|
||||
if (fs.existsSync(routersDirPath) && fs.statSync(routersDirPath).isDirectory()) {
|
||||
allRoutePath = findTsFiles(routersDirPath);
|
||||
} else {
|
||||
console.error(`目录 ${routersDirPath} 不存在或不是目录`);
|
||||
console.error(`📂 The directory ${routersDirPath} does not exist or is not a directory`);
|
||||
}
|
||||
|
||||
// 注册全部路由
|
||||
@@ -82,30 +82,13 @@ for (let index = 0; index < allRoutePath.length; index++) {
|
||||
c.header("Content-Type", "application/xml; charset=utf-8");
|
||||
return c.body(rss);
|
||||
} else {
|
||||
return c.json(
|
||||
{
|
||||
code: 500,
|
||||
message: "RSS 生成失败",
|
||||
},
|
||||
500,
|
||||
);
|
||||
return c.json({ code: 500, message: "RSS generation failed" }, 500);
|
||||
}
|
||||
}
|
||||
return c.json({
|
||||
code: 200,
|
||||
...listData,
|
||||
});
|
||||
return c.json({ code: 200, ...listData });
|
||||
});
|
||||
// 请求方式错误
|
||||
listApp.all("*", (c) =>
|
||||
c.json(
|
||||
{
|
||||
code: 405,
|
||||
message: "Method Not Allowed",
|
||||
},
|
||||
405,
|
||||
),
|
||||
);
|
||||
listApp.all("*", (c) => c.json({ code: 405, message: "Method Not Allowed" }, 405));
|
||||
}
|
||||
|
||||
// 获取全部路由
|
||||
@@ -120,13 +103,10 @@ app.get("/all", (c) =>
|
||||
return {
|
||||
name: path,
|
||||
path: undefined,
|
||||
message: "该接口暂时下线",
|
||||
message: "This interface is temporarily offline",
|
||||
};
|
||||
}
|
||||
return {
|
||||
name: path,
|
||||
path: `/${path}`,
|
||||
};
|
||||
return { name: path, path: `/${path}` };
|
||||
}),
|
||||
},
|
||||
200,
|
||||
|
||||
@@ -43,6 +43,7 @@ const getList = async (options: Options, noCache: boolean): Promise<RouterResTyp
|
||||
"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 utf8Data = iconv.decode(result.data, "gbk");
|
||||
const list = await parseRSS(utf8Data);
|
||||
|
||||
@@ -21,7 +21,7 @@ const getList = async (noCache: boolean) => {
|
||||
const result = await get({
|
||||
url,
|
||||
noCache,
|
||||
headers: await genHeaders(),
|
||||
headers: genHeaders(),
|
||||
});
|
||||
const list = result.data.data;
|
||||
return {
|
||||
|
||||
@@ -3,17 +3,7 @@ import type { RouterType } from "../router.types.js";
|
||||
import { parseChineseNumber } from "../utils/getNum.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: "sina",
|
||||
title: "新浪网",
|
||||
type: "热榜太多,一个就够",
|
||||
params: {
|
||||
type: {
|
||||
name: "榜单分类",
|
||||
type: {
|
||||
const typeMap: Record<string, string> = {
|
||||
all: "新浪热榜",
|
||||
hotcmnt: "热议榜",
|
||||
minivideo: "视频热榜",
|
||||
@@ -24,7 +14,20 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
||||
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/",
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import { config } from "../config.js";
|
||||
import NodeCache from "node-cache";
|
||||
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({
|
||||
// 缓存过期时间( 秒 )
|
||||
stdTTL: config.CACHE_TTL,
|
||||
@@ -14,24 +20,119 @@ const cache = new NodeCache({
|
||||
maxKeys: 100,
|
||||
});
|
||||
|
||||
interface GetCache<T> {
|
||||
updateTime: string;
|
||||
data: T;
|
||||
}
|
||||
// init Redis client
|
||||
const redis = new Redis({
|
||||
host: config.REDIS_HOST,
|
||||
port: config.REDIS_PORT,
|
||||
password: config.REDIS_PASSWORD,
|
||||
// 仅在第一次建立连接
|
||||
lazyConnect: true,
|
||||
});
|
||||
|
||||
// 从缓存中获取数据
|
||||
export const getCache = <T>(key: string): GetCache<T> | undefined => {
|
||||
// Redis 是否可用
|
||||
let isRedisAvailable: boolean = false;
|
||||
let isRedisTried: boolean = false;
|
||||
|
||||
// Redis 连接错误
|
||||
redis.on("error", (err) => {
|
||||
if (!isRedisTried) {
|
||||
isRedisAvailable = false;
|
||||
isRedisTried = true;
|
||||
logger.error(
|
||||
`📦 [Redis] connection failed: ${err instanceof Error ? err.message : "Unknown error"}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Redis 连接状态
|
||||
const ensureRedisConnection = async () => {
|
||||
if (!isRedisTried) {
|
||||
try {
|
||||
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"}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 从缓存中获取数据
|
||||
* @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) {
|
||||
const data = JSON.parse(redisResult);
|
||||
return data;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`📦 [Redis] get error: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
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, JSON.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);
|
||||
if (logger) logger.info(`💾 [CHCHE] ${key} has been cached`);
|
||||
if (logger) logger.info(`💾 [NodeCache] ${key} has been cached`);
|
||||
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;
|
||||
if (isRedisAvailable) {
|
||||
try {
|
||||
await redis.del(key);
|
||||
if (logger) logger.info(`🗑️ [REDIS] ${key} has been deleted from Redis`);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`📦 [Redis] del error: ${error instanceof Error ? error.message : "Unknown error"}`,
|
||||
);
|
||||
redisSuccess = false;
|
||||
}
|
||||
}
|
||||
// 尝试删除 NodeCache
|
||||
const nodeCacheSuccess = cache.del(key) > 0;
|
||||
if (logger) logger.info(`🗑️ [CACHE] ${key} has been deleted from NodeCache`);
|
||||
return redisSuccess && nodeCacheSuccess;
|
||||
};
|
||||
|
||||
@@ -49,9 +49,9 @@ export const get = async (options: Get) => {
|
||||
logger.info(`🌐 [GET] ${url}`);
|
||||
try {
|
||||
// 检查缓存
|
||||
if (noCache) delCache(url);
|
||||
if (noCache) await delCache(url);
|
||||
else {
|
||||
const cachedData = getCache(url);
|
||||
const cachedData = await getCache(url);
|
||||
if (cachedData) {
|
||||
logger.info("💾 [CHCHE] The request is cached");
|
||||
return { fromCache: true, data: cachedData.data, updateTime: cachedData.updateTime };
|
||||
@@ -63,9 +63,9 @@ export const get = async (options: Get) => {
|
||||
// 存储新获取的数据到缓存
|
||||
const updateTime = new Date().toISOString();
|
||||
const data = originaInfo ? response : responseData;
|
||||
setCache(url, { data, updateTime }, ttl);
|
||||
await setCache(url, { data, updateTime }, ttl);
|
||||
// 返回数据
|
||||
logger.info(`✅ [${response?.statusText}] request was successful`);
|
||||
logger.info(`✅ [${response?.status}] request was successful`);
|
||||
return { fromCache: false, data, updateTime };
|
||||
} catch (error) {
|
||||
logger.error("❌ [ERROR] request failed");
|
||||
@@ -79,9 +79,9 @@ export const post = async (options: Post) => {
|
||||
logger.info(`🌐 [POST] ${url}`);
|
||||
try {
|
||||
// 检查缓存
|
||||
if (noCache) delCache(url);
|
||||
if (noCache) await delCache(url);
|
||||
else {
|
||||
const cachedData = getCache(url);
|
||||
const cachedData = await getCache(url);
|
||||
if (cachedData) {
|
||||
logger.info("💾 [CHCHE] The request is cached");
|
||||
return { fromCache: true, data: cachedData.data, updateTime: cachedData.updateTime };
|
||||
@@ -94,10 +94,10 @@ export const post = async (options: Post) => {
|
||||
const updateTime = new Date().toISOString();
|
||||
const data = originaInfo ? response : responseData;
|
||||
if (!noCache) {
|
||||
setCache(url, { data, updateTime }, ttl);
|
||||
await setCache(url, { data, updateTime }, ttl);
|
||||
}
|
||||
// 返回数据
|
||||
logger.info(`✅ [${response?.statusText}] request was successful`);
|
||||
logger.info(`✅ [${response?.status}] request was successful`);
|
||||
return { fromCache: false, data, updateTime };
|
||||
} catch (error) {
|
||||
logger.error("❌ [ERROR] request failed");
|
||||
|
||||
@@ -3,7 +3,7 @@ import { get } from "../getData.js";
|
||||
import md5 from "md5";
|
||||
|
||||
export const getToken = async () => {
|
||||
const cachedData = getCache("51cto-token");
|
||||
const cachedData = await getCache("51cto-token");
|
||||
if (cachedData && typeof cachedData === "object" && "token" in cachedData) {
|
||||
const { token } = cachedData as { token: string };
|
||||
return token;
|
||||
@@ -12,7 +12,7 @@ export const getToken = async () => {
|
||||
url: "https://api-media.51cto.com/api/token-get",
|
||||
});
|
||||
const token = result.data.data.data.token;
|
||||
setCache("51cto-token", { token });
|
||||
await setCache("51cto-token", { token });
|
||||
return token;
|
||||
};
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ const getWbiKeys = async (): Promise<EncodedKeys> => {
|
||||
};
|
||||
|
||||
const getBiliWbi = async (): Promise<string> => {
|
||||
const cachedData = getCache("bilibili-wbi");
|
||||
const cachedData = await getCache("bilibili-wbi");
|
||||
console.log(cachedData);
|
||||
if (cachedData && typeof cachedData === "object" && "wbi" in cachedData) {
|
||||
const { wbi } = cachedData as { wbi: string };
|
||||
@@ -78,7 +78,7 @@ const getBiliWbi = async (): Promise<string> => {
|
||||
const img_key = web_keys.img_key;
|
||||
const sub_key = web_keys.sub_key;
|
||||
const query = encWbi(params, img_key, sub_key);
|
||||
setCache("bilibili-wbi", { wbi: query });
|
||||
await setCache("bilibili-wbi", { wbi: query });
|
||||
return query;
|
||||
};
|
||||
|
||||
|
||||
@@ -13,18 +13,18 @@ const getRandomDEVICE_ID = () => {
|
||||
* 获取APP_TOKEN
|
||||
* @returns APP_TOKEN
|
||||
*/
|
||||
const get_app_token = async () => {
|
||||
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 = await md5(now.toString());
|
||||
const md5_now = 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 md5_s = md5(Buffer.from(s).toString("base64"));
|
||||
const token = md5_s + DEVICE_ID + hex_now;
|
||||
return token;
|
||||
};
|
||||
@@ -33,11 +33,11 @@ const get_app_token = async () => {
|
||||
* 获取请求头
|
||||
* @returns 请求头
|
||||
*/
|
||||
export const genHeaders = async () => {
|
||||
export const genHeaders = () => {
|
||||
return {
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
"X-App-Id": "com.coolapk.market",
|
||||
"X-App-Token": await get_app_token(),
|
||||
"X-App-Token": get_app_token(),
|
||||
"X-Sdk-Int": "29",
|
||||
"X-Sdk-Locale": "zh-CN",
|
||||
"X-App-Version": "11.0",
|
||||
|
||||
@@ -47,7 +47,7 @@ export const parseRSS = async (rssContent: string) => {
|
||||
// 返回解析数据
|
||||
return items;
|
||||
} catch (error) {
|
||||
logger.error("❌ [ERROR] An error occurred while parsing RSS content");
|
||||
logger.error("❌ [RSS] An error occurred while parsing RSS content");
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -72,6 +72,7 @@ const Layout: FC = (props) => {
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
.title .title-tip {
|
||||
font-size: 20px;
|
||||
@@ -83,6 +84,7 @@ const Layout: FC = (props) => {
|
||||
padding: 20px;
|
||||
border-radius: 12px;
|
||||
border: 1px dashed var(--text-color);
|
||||
user-select: text;
|
||||
}
|
||||
.control {
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user