feat: 支持 Redis

This commit is contained in:
imsyy
2024-12-06 18:15:44 +08:00
parent 161b6b612b
commit 51f27af0d6
16 changed files with 296 additions and 120 deletions

View File

@@ -11,6 +11,11 @@ ALLOWED_HOST=""
# ROBOT # ROBOT
DISALLOW_ROBOT=true DISALLOW_ROBOT=true
# Redis
REDIS_HOST="127.0.0.1"
REDIS_PORT=6379
REDIS_PASSWORD=""
# 缓存时长( 秒 # 缓存时长( 秒
CACHE_TTL=3600 CACHE_TTL=3600

View File

@@ -32,53 +32,53 @@
> 示例站点运行于海外服务器,部分国内站点可能存在访问异常,请以实际情况为准 > 示例站点运行于海外服务器,部分国内站点可能存在访问异常,请以实际情况为准
| **站点** | **类别** | **调用名称** | **状态** | | **站点** | **类别** | **调用名称** | **状态** |
| ---------------- | ------------ | -------------- | --------------------------------------------------------------------------------------------------------------------------- | | ---------------- | ------------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 哔哩哔哩 | 热门榜 | bilibili | ![](https://img.shields.io/website.svg?label=bilibili&url=https://api-hot.imsyy.top/bilibili&cacheSeconds=7200) | | 哔哩哔哩 | 热门榜 | bilibili | ![https://api-hot.imsyy.top/bilibili](https://img.shields.io/website.svg?label=bilibili&url=https://api-hot.imsyy.top/bilibili&cacheSeconds=7200) |
| AcFun | 排行榜 | acfun | ![](https://img.shields.io/website.svg?label=acfun&url=https://api-hot.imsyy.top/acfun&cacheSeconds=7200) | | AcFun | 排行榜 | acfun | ![https://api-hot.imsyy.top/acfun](https://img.shields.io/website.svg?label=acfun&url=https://api-hot.imsyy.top/acfun&cacheSeconds=7200) |
| 微博 | 热搜榜 | weibo | ![](https://img.shields.io/website.svg?label=weibo&url=https://api-hot.imsyy.top/weibo&cacheSeconds=7200) | | 微博 | 热搜榜 | weibo | ![https://api-hot.imsyy.top/weibo](https://img.shields.io/website.svg?label=weibo&url=https://api-hot.imsyy.top/weibo&cacheSeconds=7200) |
| 知乎 | 热榜 | zhihu | ![](https://img.shields.io/website.svg?label=zhihu&url=https://api-hot.imsyy.top/zhihu&cacheSeconds=7200) | | 知乎 | 热榜 | zhihu | ![https://api-hot.imsyy.top/zhihu](https://img.shields.io/website.svg?label=zhihu&url=https://api-hot.imsyy.top/zhihu&cacheSeconds=7200) |
| 知乎日报 | 推荐榜 | zhihu-daily | ![](https://img.shields.io/website.svg?label=zhihu-daily&url=https://api-hot.imsyy.top/zhihu-daily&cacheSeconds=7200) | | 知乎日报 | 推荐榜 | zhihu-daily | ![https://api-hot.imsyy.top/zhihu-daily](https://img.shields.io/website.svg?label=zhihu-daily&url=https://api-hot.imsyy.top/zhihu-daily&cacheSeconds=7200) |
| 百度 | 热搜榜 | baidu | ![](https://img.shields.io/website.svg?label=baidu&url=https://api-hot.imsyy.top/baidu&cacheSeconds=7200) | | 百度 | 热搜榜 | baidu | ![https://api-hot.imsyy.top/baidu](https://img.shields.io/website.svg?label=baidu&url=https://api-hot.imsyy.top/baidu&cacheSeconds=7200) |
| 抖音 | 热点榜 | douyin | ![](https://img.shields.io/website.svg?label=douyin&url=https://api-hot.imsyy.top/douyin&cacheSeconds=7200) | | 抖音 | 热点榜 | douyin | ![https://api-hot.imsyy.top/douyin](https://img.shields.io/website.svg?label=douyin&url=https://api-hot.imsyy.top/douyin&cacheSeconds=7200) |
| 快手 | 热点榜 | kuaishou | ![](https://img.shields.io/website.svg?label=kuaishou&url=https://api-hot.imsyy.top/kuaishou&cacheSeconds=7200) | | 快手 | 热点榜 | kuaishou | ![https://api-hot.imsyy.top/kuaishou](https://img.shields.io/website.svg?label=kuaishou&url=https://api-hot.imsyy.top/kuaishou&cacheSeconds=7200) |
| 豆瓣电影 | 新片榜 | douban-movie | ![](https://img.shields.io/website.svg?label=douban-movie&url=https://api-hot.imsyy.top/douban-movie&cacheSeconds=7200) | | 豆瓣电影 | 新片榜 | douban-movie | ![https://api-hot.imsyy.top/douban-movie](https://img.shields.io/website.svg?label=douban-movie&url=https://api-hot.imsyy.top/douban-movie&cacheSeconds=7200) |
| 豆瓣讨论小组 | 讨论精选 | douban-group | ![](https://img.shields.io/website.svg?label=douban-group&url=https://api-hot.imsyy.top/douban-group&cacheSeconds=7200) | | 豆瓣讨论小组 | 讨论精选 | douban-group | ![https://api-hot.imsyy.top/douban-group](https://img.shields.io/website.svg?label=douban-group&url=https://api-hot.imsyy.top/douban-group&cacheSeconds=7200) |
| 百度贴吧 | 热议榜 | tieba | ![](https://img.shields.io/website.svg?label=tieba&url=https://api-hot.imsyy.top/tieba&cacheSeconds=7200) | | 百度贴吧 | 热议榜 | tieba | ![https://api-hot.imsyy.top/tieba](https://img.shields.io/website.svg?label=tieba&url=https://api-hot.imsyy.top/tieba&cacheSeconds=7200) |
| 少数派 | 热榜 | sspai | ![](https://img.shields.io/website.svg?label=sspai&url=https://api-hot.imsyy.top/sspai&cacheSeconds=7200) | | 少数派 | 热榜 | sspai | ![https://api-hot.imsyy.top/sspai](https://img.shields.io/website.svg?label=sspai&url=https://api-hot.imsyy.top/sspai&cacheSeconds=7200) |
| IT之家 | 热榜 | ithome | ![](https://img.shields.io/website.svg?label=ithome&url=https://api-hot.imsyy.top/ithome&cacheSeconds=7200) | | IT之家 | 热榜 | ithome | ![https://api-hot.imsyy.top/ithome](https://img.shields.io/website.svg?label=ithome&url=https://api-hot.imsyy.top/ithome&cacheSeconds=7200) |
| IT之家「喜加一」 | 最新动态 | ithome-xijiayi | ![](https://img.shields.io/website.svg?label=ithome-xijiayi&url=https://api-hot.imsyy.top/ithome-xijiayi&cacheSeconds=7200) | | IT之家「喜加一」 | 最新动态 | ithome-xijiayi | ![https://api-hot.imsyy.top/ithome-xijiayi](https://img.shields.io/website.svg?label=ithome-xijiayi&url=https://api-hot.imsyy.top/ithome-xijiayi&cacheSeconds=7200) |
| 简书 | 热门推荐 | jianshu | ![](https://img.shields.io/website.svg?label=jianshu&url=https://api-hot.imsyy.top/jianshu&cacheSeconds=7200) | | 简书 | 热门推荐 | jianshu | ![https://api-hot.imsyy.top/jianshu](https://img.shields.io/website.svg?label=jianshu&url=https://api-hot.imsyy.top/jianshu&cacheSeconds=7200) |
| 果壳 | 热门文章 | guokr | ![](https://img.shields.io/website.svg?label=guokr&url=https://api-hot.imsyy.top/guokr&cacheSeconds=7200) | | 果壳 | 热门文章 | guokr | ![https://api-hot.imsyy.top/guokr](https://img.shields.io/website.svg?label=guokr&url=https://api-hot.imsyy.top/guokr&cacheSeconds=7200) |
| 澎湃新闻 | 热榜 | thepaper | ![](https://img.shields.io/website.svg?label=thepaper&url=https://api-hot.imsyy.top/thepaper&cacheSeconds=7200) | | 澎湃新闻 | 热榜 | thepaper | ![https://api-hot.imsyy.top/thepaper](https://img.shields.io/website.svg?label=thepaper&url=https://api-hot.imsyy.top/thepaper&cacheSeconds=7200) |
| 今日头条 | 热榜 | toutiao | ![](https://img.shields.io/website.svg?label=toutiao&url=https://api-hot.imsyy.top/toutiao&cacheSeconds=7200) | | 今日头条 | 热榜 | toutiao | ![https://api-hot.imsyy.top/toutiao](https://img.shields.io/website.svg?label=toutiao&url=https://api-hot.imsyy.top/toutiao&cacheSeconds=7200) |
| 36 氪 | 热榜 | 36kr | ![](https://img.shields.io/website.svg?label=36kr&url=https://api-hot.imsyy.top/36kr&cacheSeconds=7200) | | 36 氪 | 热榜 | 36kr | ![https://api-hot.imsyy.top/36kr](https://img.shields.io/website.svg?label=36kr&url=https://api-hot.imsyy.top/36kr&cacheSeconds=7200) |
| 51CTO | 推荐榜 | 51cto | ![](https://img.shields.io/website.svg?label=51cto&url=https://api-hot.imsyy.top/51cto&cacheSeconds=7200) | | 51CTO | 推荐榜 | 51cto | ![https://api-hot.imsyy.top/51cto](https://img.shields.io/website.svg?label=51cto&url=https://api-hot.imsyy.top/51cto&cacheSeconds=7200) |
| CSDN | 排行榜 | csdn | ![](https://img.shields.io/website.svg?label=csdn&url=https://api-hot.imsyy.top/csdn&cacheSeconds=7200) | | CSDN | 排行榜 | csdn | ![https://api-hot.imsyy.top/csdn](https://img.shields.io/website.svg?label=csdn&url=https://api-hot.imsyy.top/csdn&cacheSeconds=7200) |
| NodeSeek | 最新动态 | nodeseek | ![](https://img.shields.io/website.svg?label=nodeseek&url=https://api-hot.imsyy.top/nodeseek&cacheSeconds=7200) | | NodeSeek | 最新动态 | nodeseek | ![https://api-hot.imsyy.top/nodeseek](https://img.shields.io/website.svg?label=nodeseek&url=https://api-hot.imsyy.top/nodeseek&cacheSeconds=7200) |
| 稀土掘金 | 热榜 | juejin | ![](https://img.shields.io/website.svg?label=juejin&url=https://api-hot.imsyy.top/juejin&cacheSeconds=7200) | | 稀土掘金 | 热榜 | juejin | ![https://api-hot.imsyy.top/juejin](https://img.shields.io/website.svg?label=juejin&url=https://api-hot.imsyy.top/juejin&cacheSeconds=7200) |
| 腾讯新闻 | 热点榜 | qq-news | ![](https://img.shields.io/website.svg?label=qq-news&url=https://api-hot.imsyy.top/qq-news&cacheSeconds=7200) | | 腾讯新闻 | 热点榜 | qq-news | ![https://api-hot.imsyy.top/qq-news](https://img.shields.io/website.svg?label=qq-news&url=https://api-hot.imsyy.top/qq-news&cacheSeconds=7200) |
| 新浪网 | 热榜 | sina | ![](https://img.shields.io/website.svg?label=sina&url=https://api-hot.imsyy.top/sina&cacheSeconds=7200) | | 新浪网 | 热榜 | sina | ![https://api-hot.imsyy.top/sina](https://img.shields.io/website.svg?label=sina&url=https://api-hot.imsyy.top/sina&cacheSeconds=7200) |
| 新浪新闻 | 热点榜 | sina-news | ![](https://img.shields.io/website.svg?label=sina-news&url=https://api-hot.imsyy.top/sina-news&cacheSeconds=7200) | | 新浪新闻 | 热点榜 | sina-news | ![https://api-hot.imsyy.top/sina-news](https://img.shields.io/website.svg?label=sina-news&url=https://api-hot.imsyy.top/sina-news&cacheSeconds=7200) |
| 网易新闻 | 热点榜 | netease-news | ![](https://img.shields.io/website.svg?label=netease-news&url=https://api-hot.imsyy.top/netease-news&cacheSeconds=7200) | | 网易新闻 | 热点榜 | netease-news | ![https://api-hot.imsyy.top/netease-news](https://img.shields.io/website.svg?label=netease-news&url=https://api-hot.imsyy.top/netease-news&cacheSeconds=7200) |
| 吾爱破解 | 榜单 | 52pojie | ![](https://img.shields.io/website.svg?label=52pojie&url=https://api-hot.imsyy.top/52pojie&cacheSeconds=7200) | | 吾爱破解 | 榜单 | 52pojie | ![https://api-hot.imsyy.top/52pojie](https://img.shields.io/website.svg?label=52pojie&url=https://api-hot.imsyy.top/52pojie&cacheSeconds=7200) |
| 全球主机交流 | 榜单 | hostloc | ![](https://img.shields.io/website.svg?label=hostloc&url=https://api-hot.imsyy.top/hostloc&cacheSeconds=7200) | | 全球主机交流 | 榜单 | hostloc | ![https://api-hot.imsyy.top/hostloc](https://img.shields.io/website.svg?label=hostloc&url=https://api-hot.imsyy.top/hostloc&cacheSeconds=7200) |
| 虎嗅 | 24小时 | huxiu | ![](https://img.shields.io/website.svg?label=huxiu&url=https://api-hot.imsyy.top/huxiu&cacheSeconds=7200) | | 虎嗅 | 24小时 | huxiu | ![https://api-hot.imsyy.top/huxiu](https://img.shields.io/website.svg?label=huxiu&url=https://api-hot.imsyy.top/huxiu&cacheSeconds=7200) |
| 酷安 | 热榜 | coolapk | ![](https://img.shields.io/website.svg?label=coolapk&url=https://api-hot.imsyy.top/coolapk&cacheSeconds=7200) | | 酷安 | 热榜 | coolapk | ![https://api-hot.imsyy.top/coolapk](https://img.shields.io/website.svg?label=coolapk&url=https://api-hot.imsyy.top/coolapk&cacheSeconds=7200) |
| 虎扑 | 步行街热帖 | hupu | ![](https://img.shields.io/website.svg?label=hupu&url=https://api-hot.imsyy.top/hupu&cacheSeconds=7200) | | 虎扑 | 步行街热帖 | hupu | ![https://api-hot.imsyy.top/hupu](https://img.shields.io/website.svg?label=hupu&url=https://api-hot.imsyy.top/hupu&cacheSeconds=7200) |
| 爱范儿 | 快讯 | ifanr | ![](https://img.shields.io/website.svg?label=ifanr&url=https://api-hot.imsyy.top/ifanr&cacheSeconds=7200) | | 爱范儿 | 快讯 | ifanr | ![https://api-hot.imsyy.top/ifanr](https://img.shields.io/website.svg?label=ifanr&url=https://api-hot.imsyy.top/ifanr&cacheSeconds=7200) |
| 英雄联盟 | 更新公告 | lol | ![](https://img.shields.io/website.svg?label=lol&url=https://api-hot.imsyy.top/lol&cacheSeconds=7200) | | 英雄联盟 | 更新公告 | lol | ![https://api-hot.imsyy.top/lol](https://img.shields.io/website.svg?label=lol&url=https://api-hot.imsyy.top/lol&cacheSeconds=7200) |
| 米游社 | 最新消息 | miyoushe | ![](https://img.shields.io/website.svg?label=miyoushe&url=https://api-hot.imsyy.top/miyoushe&cacheSeconds=7200) | | 米游社 | 最新消息 | miyoushe | ![https://api-hot.imsyy.top/miyoushe](https://img.shields.io/website.svg?label=miyoushe&url=https://api-hot.imsyy.top/miyoushe&cacheSeconds=7200) |
| 原神 | 最新消息 | genshin | ![](https://img.shields.io/website.svg?label=genshin&url=https://api-hot.imsyy.top/genshin&cacheSeconds=7200) | | 原神 | 最新消息 | genshin | ![https://api-hot.imsyy.top/genshin](https://img.shields.io/website.svg?label=genshin&url=https://api-hot.imsyy.top/genshin&cacheSeconds=7200) |
| 崩坏3 | 最新动态 | honkai | ![](https://img.shields.io/website.svg?label=honkai&url=https://api-hot.imsyy.top/honkai&cacheSeconds=7200) | | 崩坏3 | 最新动态 | honkai | ![https://api-hot.imsyy.top/honkai](https://img.shields.io/website.svg?label=honkai&url=https://api-hot.imsyy.top/honkai&cacheSeconds=7200) |
| 崩坏:星穹铁道 | 最新动态 | starrail | ![](https://img.shields.io/website.svg?label=starrail&url=https://api-hot.imsyy.top/starrail&cacheSeconds=7200) | | 崩坏:星穹铁道 | 最新动态 | starrail | ![https://api-hot.imsyy.top/starrail](https://img.shields.io/website.svg?label=starrail&url=https://api-hot.imsyy.top/starrail&cacheSeconds=7200) |
| 微信读书 | 飙升榜 | weread | ![](https://img.shields.io/website.svg?label=weread&url=https://api-hot.imsyy.top/weread&cacheSeconds=7200) | | 微信读书 | 飙升榜 | weread | ![https://api-hot.imsyy.top/weread](https://img.shields.io/website.svg?label=weread&url=https://api-hot.imsyy.top/weread&cacheSeconds=7200) |
| NGA | 热帖 | ngabbs | ![](https://img.shields.io/website.svg?label=ngabbs&url=https://api-hot.imsyy.top/ngabbs&cacheSeconds=7200) | | NGA | 热帖 | ngabbs | ![https://api-hot.imsyy.top/ngabbs](https://img.shields.io/website.svg?label=ngabbs&url=https://api-hot.imsyy.top/ngabbs&cacheSeconds=7200) |
| V2EX | 主题榜 | v2ex | ![](https://img.shields.io/website.svg?label=v2ex&url=https://api-hot.imsyy.top/v2ex&cacheSeconds=7200) | | V2EX | 主题榜 | v2ex | ![https://api-hot.imsyy.top/v2ex](https://img.shields.io/website.svg?label=v2ex&url=https://api-hot.imsyy.top/v2ex&cacheSeconds=7200) |
| HelloGitHub | Trending | hellogithub | ![](https://img.shields.io/website.svg?label=hellogithub&url=https://api-hot.imsyy.top/hellogithub&cacheSeconds=7200) | | HelloGitHub | Trending | hellogithub | ![https://api-hot.imsyy.top/hellogithub](https://img.shields.io/website.svg?label=hellogithub&url=https://api-hot.imsyy.top/hellogithub&cacheSeconds=7200) |
| 中央气象台 | 全国气象预警 | weatheralarm | ![](https://img.shields.io/website.svg?label=weatheralarm&url=https://api-hot.imsyy.top/weatheralarm&cacheSeconds=7200) | | 中央气象台 | 全国气象预警 | weatheralarm | ![https://api-hot.imsyy.top/weatheralarm](https://img.shields.io/website.svg?label=weatheralarm&url=https://api-hot.imsyy.top/weatheralarm&cacheSeconds=7200) |
| 中国地震台 | 地震速报 | earthquake | ![](https://img.shields.io/website.svg?label=earthquake&url=https://api-hot.imsyy.top/earthquake&cacheSeconds=7200) | | 中国地震台 | 地震速报 | earthquake | ![https://api-hot.imsyy.top/earthquake](https://img.shields.io/website.svg?label=earthquake&url=https://api-hot.imsyy.top/earthquake&cacheSeconds=7200) |
| 历史上的今天 | 月-日 | history | ![](https://img.shields.io/website.svg?label=history&url=https://api-hot.imsyy.top/history&cacheSeconds=7200) | | 历史上的今天 | 月-日 | history | ![https://api-hot.imsyy.top/history](https://img.shields.io/website.svg?label=history&url=https://api-hot.imsyy.top/history&cacheSeconds=7200) |
</details> </details>

View File

@@ -45,10 +45,12 @@
"feed": "^4.2.2", "feed": "^4.2.2",
"hono": "^4.6.12", "hono": "^4.6.12",
"iconv-lite": "^0.6.3", "iconv-lite": "^0.6.3",
"ioredis": "^5.4.1",
"md5": "^2.3.0", "md5": "^2.3.0",
"node-cache": "^5.1.2", "node-cache": "^5.1.2",
"rss-parser": "^3.13.0", "rss-parser": "^3.13.0",
"user-agents": "^1.1.379", "user-agents": "^1.1.379",
"uuid": "^11.0.3",
"winston": "^3.17.0" "winston": "^3.17.0"
}, },
"devDependencies": { "devDependencies": {

76
pnpm-lock.yaml generated
View File

@@ -35,6 +35,9 @@ importers:
iconv-lite: iconv-lite:
specifier: ^0.6.3 specifier: ^0.6.3
version: 0.6.3 version: 0.6.3
ioredis:
specifier: ^5.4.1
version: 5.4.1
md5: md5:
specifier: ^2.3.0 specifier: ^2.3.0
version: 2.3.0 version: 2.3.0
@@ -47,6 +50,9 @@ importers:
user-agents: user-agents:
specifier: ^1.1.379 specifier: ^1.1.379
version: 1.1.379 version: 1.1.379
uuid:
specifier: ^11.0.3
version: 11.0.3
winston: winston:
specifier: ^3.17.0 specifier: ^3.17.0
version: 3.17.0 version: 3.17.0
@@ -307,6 +313,9 @@ packages:
resolution: {integrity: sha512-c7hNEllBlenFTHBky65mhq8WD2kbN9Q6gk0bTk8lSBvc554jpXSkST1iePudpt7+A/AQvuHs9EMqjHDXMY1lrA==} resolution: {integrity: sha512-c7hNEllBlenFTHBky65mhq8WD2kbN9Q6gk0bTk8lSBvc554jpXSkST1iePudpt7+A/AQvuHs9EMqjHDXMY1lrA==}
engines: {node: '>=18.18'} engines: {node: '>=18.18'}
'@ioredis/commands@1.2.0':
resolution: {integrity: sha512-Sx1pU8EM64o2BrqNpEO1CNLtKQwyhuXuqyfH7oGKCk+1a33d2r5saW8zNwm3j6BTExtjrv2BxTgzzkMwts6vGg==}
'@nodelib/fs.scandir@2.1.5': '@nodelib/fs.scandir@2.1.5':
resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
engines: {node: '>= 8'} engines: {node: '>= 8'}
@@ -473,6 +482,10 @@ packages:
resolution: {integrity: sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==} resolution: {integrity: sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==}
engines: {node: '>=0.8'} 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: color-convert@1.9.3:
resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==} resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==}
@@ -540,6 +553,10 @@ packages:
resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
engines: {node: '>=0.4.0'} 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: dom-serializer@2.0.0:
resolution: {integrity: sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==} resolution: {integrity: sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==}
@@ -736,6 +753,10 @@ packages:
inherits@2.0.4: inherits@2.0.4:
resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} 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: is-arrayish@0.3.2:
resolution: {integrity: sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==} resolution: {integrity: sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==}
@@ -791,6 +812,12 @@ packages:
lodash.clonedeep@4.5.0: lodash.clonedeep@4.5.0:
resolution: {integrity: sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==} 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: lodash.merge@4.6.2:
resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}
@@ -900,6 +927,14 @@ packages:
resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==} resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==}
engines: {node: '>= 6'} 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: resolve-from@4.0.0:
resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==}
engines: {node: '>=4'} engines: {node: '>=4'}
@@ -949,6 +984,9 @@ packages:
stack-trace@0.0.10: stack-trace@0.0.10:
resolution: {integrity: sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==} resolution: {integrity: sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==}
standard-as-callback@2.1.0:
resolution: {integrity: sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A==}
string_decoder@1.3.0: string_decoder@1.3.0:
resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==}
@@ -1017,6 +1055,10 @@ packages:
util-deprecate@1.0.2: util-deprecate@1.0.2:
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
uuid@11.0.3:
resolution: {integrity: sha512-d0z310fCWv5dJwnX1Y/MncBAqGMKEzlBb1AOf7z9K8ALnd0utBX/msg/fA0+sbyN1ihbMsLhrBlnl1ak7Wa0rg==}
hasBin: true
whatwg-encoding@3.1.1: whatwg-encoding@3.1.1:
resolution: {integrity: sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==} resolution: {integrity: sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==}
engines: {node: '>=18'} engines: {node: '>=18'}
@@ -1196,6 +1238,8 @@ snapshots:
'@humanwhocodes/retry@0.4.1': {} '@humanwhocodes/retry@0.4.1': {}
'@ioredis/commands@1.2.0': {}
'@nodelib/fs.scandir@2.1.5': '@nodelib/fs.scandir@2.1.5':
dependencies: dependencies:
'@nodelib/fs.stat': 2.0.5 '@nodelib/fs.stat': 2.0.5
@@ -1392,6 +1436,8 @@ snapshots:
clone@2.1.2: {} clone@2.1.2: {}
cluster-key-slot@1.1.2: {}
color-convert@1.9.3: color-convert@1.9.3:
dependencies: dependencies:
color-name: 1.1.3 color-name: 1.1.3
@@ -1457,6 +1503,8 @@ snapshots:
delayed-stream@1.0.0: {} delayed-stream@1.0.0: {}
denque@2.1.0: {}
dom-serializer@2.0.0: dom-serializer@2.0.0:
dependencies: dependencies:
domelementtype: 2.3.0 domelementtype: 2.3.0
@@ -1684,6 +1732,20 @@ snapshots:
inherits@2.0.4: {} 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-arrayish@0.3.2: {}
is-buffer@1.1.6: {} is-buffer@1.1.6: {}
@@ -1727,6 +1789,10 @@ snapshots:
lodash.clonedeep@4.5.0: {} lodash.clonedeep@4.5.0: {}
lodash.defaults@4.2.0: {}
lodash.isarguments@3.1.0: {}
lodash.merge@4.6.2: {} lodash.merge@4.6.2: {}
logform@2.7.0: logform@2.7.0:
@@ -1837,6 +1903,12 @@ snapshots:
string_decoder: 1.3.0 string_decoder: 1.3.0
util-deprecate: 1.0.2 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-from@4.0.0: {}
resolve-pkg-maps@1.0.0: {} resolve-pkg-maps@1.0.0: {}
@@ -1874,6 +1946,8 @@ snapshots:
stack-trace@0.0.10: {} stack-trace@0.0.10: {}
standard-as-callback@2.1.0: {}
string_decoder@1.3.0: string_decoder@1.3.0:
dependencies: dependencies:
safe-buffer: 5.2.1 safe-buffer: 5.2.1
@@ -1934,6 +2008,8 @@ snapshots:
util-deprecate@1.0.2: {} util-deprecate@1.0.2: {}
uuid@11.0.3: {}
whatwg-encoding@3.1.1: whatwg-encoding@3.1.1:
dependencies: dependencies:
iconv-lite: 0.6.3 iconv-lite: 0.6.3

View File

@@ -12,6 +12,9 @@ export type Config = {
ALLOWED_HOST: string; ALLOWED_HOST: string;
USE_LOG_FILE: boolean; USE_LOG_FILE: boolean;
RSS_MODE: boolean; RSS_MODE: boolean;
REDIS_HOST: string;
REDIS_PORT: number;
REDIS_PASSWORD: string;
}; };
// 验证并提取环境变量 // 验证并提取环境变量
@@ -45,4 +48,7 @@ export const config: Config = {
ALLOWED_HOST: getEnvVariable("ALLOWED_HOST") || "imsyy.top", ALLOWED_HOST: getEnvVariable("ALLOWED_HOST") || "imsyy.top",
USE_LOG_FILE: getBooleanEnvVariable("USE_LOG_FILE", true), USE_LOG_FILE: getBooleanEnvVariable("USE_LOG_FILE", true),
RSS_MODE: getBooleanEnvVariable("RSS_MODE", false), RSS_MODE: getBooleanEnvVariable("RSS_MODE", false),
REDIS_HOST: getEnvVariable("REDIS_HOST") || "127.0.0.1",
REDIS_PORT: getNumericEnvVariable("REDIS_PORT", 6379),
REDIS_PASSWORD: getEnvVariable("REDIS_PASSWORD") || "",
}; };

View File

@@ -48,7 +48,7 @@ const findTsFiles = (dirPath: string, allFiles: string[] = [], basePath: string
if (fs.existsSync(routersDirPath) && fs.statSync(routersDirPath).isDirectory()) { if (fs.existsSync(routersDirPath) && fs.statSync(routersDirPath).isDirectory()) {
allRoutePath = findTsFiles(routersDirPath); allRoutePath = findTsFiles(routersDirPath);
} else { } else {
console.error(`目录 ${routersDirPath} 不存在或不是目录`); console.error(`📂 The directory ${routersDirPath} does not exist or is not a directory`);
} }
// 注册全部路由 // 注册全部路由
@@ -82,30 +82,13 @@ for (let index = 0; index < allRoutePath.length; index++) {
c.header("Content-Type", "application/xml; charset=utf-8"); c.header("Content-Type", "application/xml; charset=utf-8");
return c.body(rss); return c.body(rss);
} else { } else {
return c.json( return c.json({ code: 500, message: "RSS generation failed" }, 500);
{
code: 500,
message: "RSS 生成失败",
},
500,
);
} }
} }
return c.json({ return c.json({ code: 200, ...listData });
code: 200,
...listData,
});
}); });
// 请求方式错误 // 请求方式错误
listApp.all("*", (c) => listApp.all("*", (c) => c.json({ code: 405, message: "Method Not Allowed" }, 405));
c.json(
{
code: 405,
message: "Method Not Allowed",
},
405,
),
);
} }
// 获取全部路由 // 获取全部路由
@@ -120,13 +103,10 @@ app.get("/all", (c) =>
return { return {
name: path, name: path,
path: undefined, path: undefined,
message: "该接口暂时下线", message: "This interface is temporarily offline",
}; };
} }
return { return { name: path, path: `/${path}` };
name: path,
path: `/${path}`,
};
}), }),
}, },
200, 200,

View File

@@ -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", "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 utf8Data = iconv.decode(result.data, "gbk");
const list = await parseRSS(utf8Data); const list = await parseRSS(utf8Data);

View File

@@ -21,7 +21,7 @@ const getList = async (noCache: boolean) => {
const result = await get({ const result = await get({
url, url,
noCache, noCache,
headers: await genHeaders(), headers: genHeaders(),
}); });
const list = result.data.data; const list = result.data.data;
return { return {

View File

@@ -3,28 +3,31 @@ import type { RouterType } from "../router.types.js";
import { parseChineseNumber } from "../utils/getNum.js"; import { parseChineseNumber } from "../utils/getNum.js";
import { get } from "../utils/getData.js"; import { get } from "../utils/getData.js";
const typeMap: Record<string, string> = {
all: "新浪热榜",
hotcmnt: "热议榜",
minivideo: "视频热榜",
ent: "娱乐热榜",
ai: "AI热榜",
auto: "汽车热榜",
mother: "育儿热榜",
fashion: "时尚热榜",
travel: "旅游热榜",
esg: "ESG热榜",
};
export const handleRoute = async (c: ListContext, noCache: boolean) => { export const handleRoute = async (c: ListContext, noCache: boolean) => {
const type = c.req.query("type") || "1"; const type = c.req.query("type") || "all";
const listData = await getList({ type }, noCache); const listData = await getList({ type }, noCache);
const routeData: RouterData = { const routeData: RouterData = {
name: "sina", name: "sina",
title: "新浪网", title: "新浪网",
type: "热榜太多,一个就够", type: typeMap[type],
description: "热榜太多,一个就够",
params: { params: {
type: { type: {
name: "榜单分类", name: "榜单分类",
type: { type: typeMap,
all: "新浪热榜",
hotcmnt: "热议榜",
minivideo: "视频热榜",
ent: "娱乐热榜",
ai: "AI热榜",
auto: "汽车热榜",
mother: "育儿热榜",
fashion: "时尚热榜",
travel: "旅游热榜",
esg: "ESG热榜",
},
}, },
}, },
link: "https://sinanews.sina.cn/", link: "https://sinanews.sina.cn/",

View File

@@ -1,8 +1,14 @@
import { config } from "../config.js"; import { config } from "../config.js";
import NodeCache from "node-cache";
import logger from "./logger.js"; import logger from "./logger.js";
import NodeCache from "node-cache";
import Redis from "ioredis";
// init interface CacheData {
updateTime: string;
data: unknown;
}
// init NodeCache
const cache = new NodeCache({ const cache = new NodeCache({
// 缓存过期时间( 秒 // 缓存过期时间( 秒
stdTTL: config.CACHE_TTL, stdTTL: config.CACHE_TTL,
@@ -14,24 +20,119 @@ const cache = new NodeCache({
maxKeys: 100, maxKeys: 100,
}); });
interface GetCache<T> { // init Redis client
updateTime: string; const redis = new Redis({
data: T; host: config.REDIS_HOST,
} port: config.REDIS_PORT,
password: config.REDIS_PASSWORD,
// 仅在第一次建立连接
lazyConnect: true,
});
// 从缓存中获取数据 // Redis 是否可用
export const getCache = <T>(key: string): GetCache<T> | undefined => { 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); 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); 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; 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;
}; };

View File

@@ -49,9 +49,9 @@ export const get = async (options: Get) => {
logger.info(`🌐 [GET] ${url}`); logger.info(`🌐 [GET] ${url}`);
try { try {
// 检查缓存 // 检查缓存
if (noCache) delCache(url); if (noCache) await delCache(url);
else { else {
const cachedData = getCache(url); const cachedData = await getCache(url);
if (cachedData) { if (cachedData) {
logger.info("💾 [CHCHE] The request is cached"); logger.info("💾 [CHCHE] The request is cached");
return { fromCache: true, data: cachedData.data, updateTime: cachedData.updateTime }; 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 updateTime = new Date().toISOString();
const data = originaInfo ? response : responseData; const data = originaInfo ? response : responseData;
setCache(url, { data, updateTime }, ttl); await setCache(url, { data, updateTime }, ttl);
// 返回数据 // 返回数据
logger.info(`✅ [${response?.statusText}] request was successful`); logger.info(`✅ [${response?.status}] request was successful`);
return { fromCache: false, data, updateTime }; return { fromCache: false, data, updateTime };
} catch (error) { } catch (error) {
logger.error("❌ [ERROR] request failed"); logger.error("❌ [ERROR] request failed");
@@ -79,9 +79,9 @@ export const post = async (options: Post) => {
logger.info(`🌐 [POST] ${url}`); logger.info(`🌐 [POST] ${url}`);
try { try {
// 检查缓存 // 检查缓存
if (noCache) delCache(url); if (noCache) await delCache(url);
else { else {
const cachedData = getCache(url); const cachedData = await getCache(url);
if (cachedData) { if (cachedData) {
logger.info("💾 [CHCHE] The request is cached"); logger.info("💾 [CHCHE] The request is cached");
return { fromCache: true, data: cachedData.data, updateTime: cachedData.updateTime }; 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 updateTime = new Date().toISOString();
const data = originaInfo ? response : responseData; const data = originaInfo ? response : responseData;
if (!noCache) { if (!noCache) {
setCache(url, { data, updateTime }, ttl); await setCache(url, { data, updateTime }, ttl);
} }
// 返回数据 // 返回数据
logger.info(`✅ [${response?.statusText}] request was successful`); logger.info(`✅ [${response?.status}] request was successful`);
return { fromCache: false, data, updateTime }; return { fromCache: false, data, updateTime };
} catch (error) { } catch (error) {
logger.error("❌ [ERROR] request failed"); logger.error("❌ [ERROR] request failed");

View File

@@ -3,7 +3,7 @@ import { get } from "../getData.js";
import md5 from "md5"; import md5 from "md5";
export const getToken = async () => { export const getToken = async () => {
const cachedData = getCache("51cto-token"); const cachedData = await getCache("51cto-token");
if (cachedData && typeof cachedData === "object" && "token" in cachedData) { if (cachedData && typeof cachedData === "object" && "token" in cachedData) {
const { token } = cachedData as { token: string }; const { token } = cachedData as { token: string };
return token; return token;
@@ -12,7 +12,7 @@ export const getToken = async () => {
url: "https://api-media.51cto.com/api/token-get", url: "https://api-media.51cto.com/api/token-get",
}); });
const token = result.data.data.data.token; const token = result.data.data.data.token;
setCache("51cto-token", { token }); await setCache("51cto-token", { token });
return token; return token;
}; };

View File

@@ -67,7 +67,7 @@ const getWbiKeys = async (): Promise<EncodedKeys> => {
}; };
const getBiliWbi = async (): Promise<string> => { const getBiliWbi = async (): Promise<string> => {
const cachedData = getCache("bilibili-wbi"); const cachedData = await getCache("bilibili-wbi");
console.log(cachedData); console.log(cachedData);
if (cachedData && typeof cachedData === "object" && "wbi" in cachedData) { if (cachedData && typeof cachedData === "object" && "wbi" in cachedData) {
const { wbi } = cachedData as { wbi: string }; const { wbi } = cachedData as { wbi: string };
@@ -78,7 +78,7 @@ const getBiliWbi = async (): Promise<string> => {
const img_key = web_keys.img_key; const img_key = web_keys.img_key;
const sub_key = web_keys.sub_key; const sub_key = web_keys.sub_key;
const query = encWbi(params, img_key, sub_key); const query = encWbi(params, img_key, sub_key);
setCache("bilibili-wbi", { wbi: query }); await setCache("bilibili-wbi", { wbi: query });
return query; return query;
}; };

View File

@@ -13,18 +13,18 @@ const getRandomDEVICE_ID = () => {
* 获取APP_TOKEN * 获取APP_TOKEN
* @returns APP_TOKEN * @returns APP_TOKEN
*/ */
const get_app_token = async () => { const get_app_token = () => {
const DEVICE_ID = getRandomDEVICE_ID(); const DEVICE_ID = getRandomDEVICE_ID();
const now = Math.round(Date.now() / 1000); const now = Math.round(Date.now() / 1000);
const hex_now = "0x" + now.toString(16); const hex_now = "0x" + now.toString(16);
const md5_now = await md5(now.toString()); const md5_now = md5(now.toString());
const s = const s =
"token://com.coolapk.market/c67ef5943784d09750dcfbb31020f0ab?" + "token://com.coolapk.market/c67ef5943784d09750dcfbb31020f0ab?" +
md5_now + md5_now +
"$" + "$" +
DEVICE_ID + DEVICE_ID +
"&com.coolapk.market"; "&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; const token = md5_s + DEVICE_ID + hex_now;
return token; return token;
}; };
@@ -33,11 +33,11 @@ const get_app_token = async () => {
* 获取请求头 * 获取请求头
* @returns 请求头 * @returns 请求头
*/ */
export const genHeaders = async () => { export const genHeaders = () => {
return { return {
"X-Requested-With": "XMLHttpRequest", "X-Requested-With": "XMLHttpRequest",
"X-App-Id": "com.coolapk.market", "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-Int": "29",
"X-Sdk-Locale": "zh-CN", "X-Sdk-Locale": "zh-CN",
"X-App-Version": "11.0", "X-App-Version": "11.0",

View File

@@ -47,7 +47,7 @@ export const parseRSS = async (rssContent: string) => {
// 返回解析数据 // 返回解析数据
return items; return items;
} catch (error) { } catch (error) {
logger.error("❌ [ERROR] An error occurred while parsing RSS content"); logger.error("❌ [RSS] An error occurred while parsing RSS content");
throw error; throw error;
} }
}; };

View File

@@ -72,6 +72,7 @@ const Layout: FC = (props) => {
font-size: 28px; font-size: 28px;
font-weight: bold; font-weight: bold;
margin-bottom: 12px; margin-bottom: 12px;
text-align: center;
} }
.title .title-tip { .title .title-tip {
font-size: 20px; font-size: 20px;
@@ -83,6 +84,7 @@ const Layout: FC = (props) => {
padding: 20px; padding: 20px;
border-radius: 12px; border-radius: 12px;
border: 1px dashed var(--text-color); border: 1px dashed var(--text-color);
user-select: text;
} }
.control { .control {
display: flex; display: flex;