feat: 新增获取全部接口信息
This commit is contained in:
parent
ffc9e7cb37
commit
e5bd04fde1
11
README.md
11
README.md
@ -32,16 +32,25 @@
|
||||
| 腾讯新闻 | 热点榜 | newsqq | 🟢 |
|
||||
| 抖音热榜 | 热点榜 | douyin | 🟢 |
|
||||
| 英雄联盟 | 更新公告 | lol | 🟢 |
|
||||
| 微信读书 | 飙升榜 | weread | 🟢 |
|
||||
| 历史上的今天 | 指定日期 | calendar | 🟢 |
|
||||
|
||||
### 特殊接口说明
|
||||
|
||||
#### 获取全部接口信息
|
||||
|
||||
获取除了下方特殊接口外的全部接口列表
|
||||
|
||||
```http
|
||||
GET https://{example.com}/all
|
||||
```
|
||||
|
||||
#### 历史上的今天(指定日期)
|
||||
|
||||
将指定的月份和日期传入即可得到当天数据,请注意格式
|
||||
|
||||
```http
|
||||
GET https://api-hot.imsyy.top/calendar/date?month=06&day=01
|
||||
GET https://{example.com}/calendar/date?month=06&day=01
|
||||
```
|
||||
|
||||
## 部署
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dailyhot_api",
|
||||
"version": "0.0.2",
|
||||
"version": "1.0.0",
|
||||
"description": "一个今日热榜",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
@ -3,6 +3,12 @@ const krRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "36氪",
|
||||
subtitle: "热榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "krData";
|
||||
|
||||
@ -56,8 +62,7 @@ krRouter.get("/36kr", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "36氪",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -67,8 +72,7 @@ krRouter.get("/36kr", async (ctx) => {
|
||||
console.error(error);
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "36氪",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
@ -95,8 +99,7 @@ krRouter.get("/36kr/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "36氪",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -114,8 +117,7 @@ krRouter.get("/36kr/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "36氪",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -124,12 +126,12 @@ krRouter.get("/36kr/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "36氪",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
krRouter.info = routerInfo;
|
||||
module.exports = krRouter;
|
||||
|
@ -3,6 +3,9 @@ const baiduRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = { title: "百度", subtitle: "热搜榜" };
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "baiduData";
|
||||
|
||||
@ -54,8 +57,7 @@ baiduRouter.get("/baidu", async (ctx) => {
|
||||
if (!data) {
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "百度",
|
||||
subtitle: "热搜榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
return false;
|
||||
@ -66,8 +68,7 @@ baiduRouter.get("/baidu", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "百度",
|
||||
subtitle: "热搜榜",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -96,8 +97,7 @@ baiduRouter.get("/baidu/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "百度",
|
||||
subtitle: "热搜榜",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -115,8 +115,7 @@ baiduRouter.get("/baidu/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "百度",
|
||||
subtitle: "热搜榜",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -125,12 +124,12 @@ baiduRouter.get("/baidu/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "百度",
|
||||
subtitle: "热搜榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
baiduRouter.info = routerInfo;
|
||||
module.exports = baiduRouter;
|
||||
|
@ -3,6 +3,12 @@ const bilibiliRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "哔哩哔哩",
|
||||
subtitle: "热门榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "bilibiliData";
|
||||
|
||||
@ -50,8 +56,7 @@ bilibiliRouter.get("/bilibili", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "哔哩哔哩",
|
||||
subtitle: "热门榜",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -61,9 +66,8 @@ bilibiliRouter.get("/bilibili", async (ctx) => {
|
||||
console.error(error);
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "哔哩哔哩",
|
||||
subtitle: "热门榜",
|
||||
message: "哔哩哔哩热门榜获取失败",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
});
|
||||
@ -82,8 +86,7 @@ bilibiliRouter.get("/bilibili/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "哔哩哔哩",
|
||||
subtitle: "热门榜",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -101,8 +104,7 @@ bilibiliRouter.get("/bilibili/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "哔哩哔哩",
|
||||
subtitle: "热门榜",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -111,12 +113,12 @@ bilibiliRouter.get("/bilibili/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "哔哩哔哩",
|
||||
subtitle: "热门榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bilibiliRouter.info = routerInfo;
|
||||
module.exports = bilibiliRouter;
|
||||
|
@ -3,6 +3,12 @@ const douyinRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "抖音",
|
||||
subtitle: "热点榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "douyinHotData";
|
||||
const cacheCookieKey = "douyinCookieData";
|
||||
@ -95,8 +101,7 @@ douyinRouter.get("/douyin", async (ctx) => {
|
||||
if (!data) {
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "抖音热点榜",
|
||||
subtitle: "热点榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
return false;
|
||||
@ -107,8 +112,7 @@ douyinRouter.get("/douyin", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "抖音热点榜",
|
||||
subtitle: "热点榜",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -118,6 +122,7 @@ douyinRouter.get("/douyin", async (ctx) => {
|
||||
console.error(error);
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
@ -142,8 +147,7 @@ douyinRouter.get("/douyin/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "抖音热点榜",
|
||||
subtitle: "热点榜",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -161,8 +165,7 @@ douyinRouter.get("/douyin/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "抖音热点榜",
|
||||
subtitle: "热点榜",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -171,12 +174,12 @@ douyinRouter.get("/douyin/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "抖音热点榜",
|
||||
subtitle: "热点榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
douyinRouter.info = routerInfo;
|
||||
module.exports = douyinRouter;
|
||||
|
@ -4,6 +4,14 @@ const Router = require("koa-router");
|
||||
|
||||
const router = new Router();
|
||||
|
||||
// 全部路由数据
|
||||
const allRouterInfo = {
|
||||
name: "全部接口",
|
||||
subtitle: "除了特殊接口外的全部接口列表",
|
||||
total: 0,
|
||||
data: [],
|
||||
};
|
||||
|
||||
// 根目录
|
||||
router.get("/", async (ctx) => {
|
||||
await ctx.render("index");
|
||||
@ -17,10 +25,43 @@ fs.readdirSync(__dirname)
|
||||
const routerModule = require(routerPath);
|
||||
// 自动注册路由
|
||||
if (routerModule instanceof Router) {
|
||||
// 写入路由数据
|
||||
if (routerModule?.info) {
|
||||
allRouterInfo.total++;
|
||||
allRouterInfo.data.push({
|
||||
...routerModule.info,
|
||||
stack: routerModule.stack,
|
||||
});
|
||||
}
|
||||
// 引用路由
|
||||
router.use(routerModule.routes());
|
||||
}
|
||||
});
|
||||
|
||||
// 全部接口路由
|
||||
router.get("/all", async (ctx) => {
|
||||
console.log("获取全部接口路由");
|
||||
if (allRouterInfo.total > 0) {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
...allRouterInfo,
|
||||
};
|
||||
} else if (allRouterInfo.total === 0) {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "暂无接口,请添加",
|
||||
...allRouterInfo,
|
||||
};
|
||||
} else {
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
message: "获取失败",
|
||||
...allRouterInfo,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// 404 路由
|
||||
router.use(async (ctx) => {
|
||||
await ctx.render("404");
|
||||
|
@ -4,6 +4,12 @@ const axios = require("axios");
|
||||
const cheerio = require("cheerio");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "IT之家",
|
||||
subtitle: "热榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "itHomeData";
|
||||
|
||||
@ -78,8 +84,7 @@ itHomeRouter.get("/ithome", async (ctx) => {
|
||||
if (!data) {
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "IT之家",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
return false;
|
||||
@ -90,8 +95,7 @@ itHomeRouter.get("/ithome", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "IT之家",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -101,8 +105,7 @@ itHomeRouter.get("/ithome", async (ctx) => {
|
||||
console.error(error);
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "IT之家",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
@ -122,8 +125,7 @@ itHomeRouter.get("/ithome/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "IT之家",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
updateTime,
|
||||
total: data.length,
|
||||
data: newData,
|
||||
@ -141,8 +143,7 @@ itHomeRouter.get("/ithome/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "IT之家",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -151,12 +152,12 @@ itHomeRouter.get("/ithome/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "IT之家",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
itHomeRouter.info = routerInfo;
|
||||
module.exports = itHomeRouter;
|
||||
|
@ -3,6 +3,12 @@ const juejinRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "稀土掘金",
|
||||
subtitle: "热榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "juejinData";
|
||||
|
||||
@ -47,8 +53,7 @@ juejinRouter.get("/juejin", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "稀土掘金",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -58,8 +63,7 @@ juejinRouter.get("/juejin", async (ctx) => {
|
||||
console.error(error);
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "稀土掘金",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
@ -79,8 +83,7 @@ juejinRouter.get("/juejin/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "稀土掘金",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -98,8 +101,7 @@ juejinRouter.get("/juejin/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "稀土掘金",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -108,12 +110,12 @@ juejinRouter.get("/juejin/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "稀土掘金",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
juejinRouter.info = routerInfo;
|
||||
module.exports = juejinRouter;
|
||||
|
@ -3,6 +3,12 @@ const lolRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "英雄联盟",
|
||||
subtitle: "更新公告",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "lolData";
|
||||
|
||||
@ -10,24 +16,29 @@ const cacheKey = "lolData";
|
||||
let updateTime = new Date().toISOString();
|
||||
|
||||
// 调用路径
|
||||
const url = "https://apps.game.qq.com/cmc/zmMcnTargetContentList?r0=jsonp&page=1&num=16&target=24&source=web_pc&r1=jQuery191002324053053181463_1687855508930&_=1687855508933";
|
||||
const url =
|
||||
"https://apps.game.qq.com/cmc/zmMcnTargetContentList?r0=jsonp&page=1&num=16&target=24&source=web_pc&r1=jQuery191002324053053181463_1687855508930&_=1687855508933";
|
||||
|
||||
// 数据处理
|
||||
const getData = (data) => {
|
||||
if (!data) return [];
|
||||
const dataList = [];
|
||||
try {
|
||||
try {
|
||||
const pattern = /jQuery191002324053053181463_1687855508930\((.*?)\)/s;
|
||||
const matchResult = data.match(pattern);
|
||||
const jsonObject = JSON.parse(matchResult[1])['data'].result;
|
||||
const jsonObject = JSON.parse(matchResult[1])["data"].result;
|
||||
jsonObject.forEach((v) => {
|
||||
dataList.push({
|
||||
title: v.sTitle,
|
||||
desc: v.sAuthor,
|
||||
pic: `https:${v.sIMG}`,
|
||||
hot: Number(v.iTotalPlay),
|
||||
url: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(v.iDocID)}`,
|
||||
mobileUrl: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(v.iDocID)}`,
|
||||
url: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(
|
||||
v.iDocID
|
||||
)}`,
|
||||
mobileUrl: `https://lol.qq.com/news/detail.shtml?docid=${encodeURIComponent(
|
||||
v.iDocID
|
||||
)}`,
|
||||
});
|
||||
});
|
||||
return dataList;
|
||||
@ -54,8 +65,7 @@ lolRouter.get("/lol", async (ctx) => {
|
||||
if (!data) {
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "英雄联盟",
|
||||
subtitle: "更新公告",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
return false;
|
||||
@ -66,8 +76,7 @@ lolRouter.get("/lol", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "英雄联盟",
|
||||
subtitle: "更新公告",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -96,8 +105,7 @@ lolRouter.get("/lol/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "英雄联盟",
|
||||
subtitle: "更新公告",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -115,8 +123,7 @@ lolRouter.get("/lol/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "英雄联盟",
|
||||
subtitle: "更新公告",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -125,12 +132,12 @@ lolRouter.get("/lol/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "英雄联盟",
|
||||
subtitle: "更新公告",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
lolRouter.info = routerInfo;
|
||||
module.exports = lolRouter;
|
||||
|
@ -3,6 +3,12 @@ const newsqqRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "腾讯新闻",
|
||||
subtitle: "热点榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "newsqqData";
|
||||
|
||||
@ -49,8 +55,7 @@ newsqqRouter.get("/newsqq", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "腾讯新闻",
|
||||
subtitle: "热点榜",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -60,8 +65,7 @@ newsqqRouter.get("/newsqq", async (ctx) => {
|
||||
console.error(error);
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "腾讯新闻",
|
||||
subtitle: "热点榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
@ -81,8 +85,7 @@ newsqqRouter.get("/newsqq/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "腾讯新闻",
|
||||
subtitle: "热点榜",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -100,8 +103,7 @@ newsqqRouter.get("/newsqq/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "腾讯新闻",
|
||||
subtitle: "热点榜",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -110,12 +112,12 @@ newsqqRouter.get("/newsqq/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "腾讯新闻",
|
||||
subtitle: "热点榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
newsqqRouter.info = routerInfo;
|
||||
module.exports = newsqqRouter;
|
||||
|
@ -3,6 +3,12 @@ const sspaiRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "少数派",
|
||||
subtitle: "热榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "sspaiData";
|
||||
|
||||
@ -49,8 +55,7 @@ sspaiRouter.get("/sspai", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "少数派",
|
||||
subtitle: "最热",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -60,8 +65,7 @@ sspaiRouter.get("/sspai", async (ctx) => {
|
||||
console.error(error);
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "少数派",
|
||||
subtitle: "最热",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
@ -81,8 +85,7 @@ sspaiRouter.get("/sspai/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "少数派",
|
||||
subtitle: "最热",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -100,8 +103,7 @@ sspaiRouter.get("/sspai/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "少数派",
|
||||
subtitle: "最热",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -110,12 +112,12 @@ sspaiRouter.get("/sspai/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "少数派",
|
||||
subtitle: "最热",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
sspaiRouter.info = routerInfo;
|
||||
module.exports = sspaiRouter;
|
||||
|
@ -3,6 +3,12 @@ const thepaperRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "澎湃新闻",
|
||||
subtitle: "热榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "thepaperData";
|
||||
|
||||
@ -48,8 +54,7 @@ thepaperRouter.get("/thepaper", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "澎湃新闻",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -59,8 +64,7 @@ thepaperRouter.get("/thepaper", async (ctx) => {
|
||||
console.error(error);
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "澎湃新闻",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
@ -80,8 +84,7 @@ thepaperRouter.get("/thepaper/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "澎湃新闻",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -99,8 +102,7 @@ thepaperRouter.get("/thepaper/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "澎湃新闻",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -109,12 +111,12 @@ thepaperRouter.get("/thepaper/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "澎湃新闻",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
thepaperRouter.info = routerInfo;
|
||||
module.exports = thepaperRouter;
|
||||
|
@ -3,6 +3,12 @@ const tiebaRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "百度贴吧",
|
||||
subtitle: "热议榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "tiebaData";
|
||||
|
||||
@ -48,8 +54,7 @@ tiebaRouter.get("/tieba", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "百度贴吧",
|
||||
subtitle: "热议榜",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -59,8 +64,7 @@ tiebaRouter.get("/tieba", async (ctx) => {
|
||||
console.error(error);
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "百度贴吧",
|
||||
subtitle: "热议榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
@ -80,8 +84,7 @@ tiebaRouter.get("/tieba/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "百度贴吧",
|
||||
subtitle: "热议榜",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -99,8 +102,7 @@ tiebaRouter.get("/tieba/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "百度贴吧",
|
||||
subtitle: "热议榜",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -109,12 +111,12 @@ tiebaRouter.get("/tieba/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "百度贴吧",
|
||||
subtitle: "热议榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tiebaRouter.info = routerInfo;
|
||||
module.exports = tiebaRouter;
|
||||
|
@ -3,6 +3,12 @@ const toutiaoRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "今日头条",
|
||||
subtitle: "热榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "toutiaoData";
|
||||
|
||||
@ -47,8 +53,7 @@ toutiaoRouter.get("/toutiao", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "今日头条",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -58,8 +63,7 @@ toutiaoRouter.get("/toutiao", async (ctx) => {
|
||||
console.error(error);
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "今日头条",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
@ -79,8 +83,7 @@ toutiaoRouter.get("/toutiao/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "今日头条",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -98,8 +101,7 @@ toutiaoRouter.get("/toutiao/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "今日头条",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -108,12 +110,12 @@ toutiaoRouter.get("/toutiao/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "今日头条",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
toutiaoRouter.info = routerInfo;
|
||||
module.exports = toutiaoRouter;
|
||||
|
@ -4,6 +4,12 @@ const axios = require("axios");
|
||||
// const cheerio = require("cheerio");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "微博",
|
||||
subtitle: "热搜榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "weiboData";
|
||||
|
||||
@ -50,6 +56,7 @@ weiboRouter.get("/weibo", async (ctx) => {
|
||||
if (!data) {
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
return false;
|
||||
@ -60,8 +67,7 @@ weiboRouter.get("/weibo", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "微博",
|
||||
subtitle: "热搜榜",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -71,8 +77,7 @@ weiboRouter.get("/weibo", async (ctx) => {
|
||||
console.error(error);
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "微博",
|
||||
subtitle: "热搜榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
@ -92,8 +97,7 @@ weiboRouter.get("/weibo/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "微博",
|
||||
subtitle: "热搜榜",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -111,8 +115,7 @@ weiboRouter.get("/weibo/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "微博",
|
||||
subtitle: "热搜榜",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -121,12 +124,12 @@ weiboRouter.get("/weibo/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "微博",
|
||||
subtitle: "热搜榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
weiboRouter.info = routerInfo;
|
||||
module.exports = weiboRouter;
|
||||
|
@ -3,6 +3,12 @@ const wereadRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "微信读书",
|
||||
subtitle: "飙升榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "wereadData";
|
||||
|
||||
@ -10,22 +16,23 @@ const cacheKey = "wereadData";
|
||||
let updateTime = new Date().toISOString();
|
||||
|
||||
// 调用路径
|
||||
const url =
|
||||
"https://weread.qq.com/web/bookListInCategory/rising?maxIndex=0&rank=1";
|
||||
const url = "https://weread.qq.com/web/bookListInCategory/rising?rank=1";
|
||||
|
||||
// 数据处理
|
||||
const getData = (data) => {
|
||||
if (!data) return [];
|
||||
return data.map((v) => {
|
||||
const book = v.bookInfo;
|
||||
console.log(book);
|
||||
return {
|
||||
id: book.topic_id,
|
||||
title: v.topic_name,
|
||||
desc: v.topic_desc,
|
||||
pic: v.topic_pic,
|
||||
hot: v.discuss_num,
|
||||
url: v.topic_url,
|
||||
mobileUrl: v.topic_url,
|
||||
id: book.bookId,
|
||||
title: book.title,
|
||||
desc: book.intro,
|
||||
pic: book.cover.replace("s_", "t9_"),
|
||||
hot: v.readingCount,
|
||||
author: book.author,
|
||||
url: "https://weread.qq.com/web/category/rising",
|
||||
mobileUrl: "https://weread.qq.com/web/category/rising",
|
||||
};
|
||||
});
|
||||
};
|
||||
@ -41,14 +48,18 @@ wereadRouter.get("/weread", async (ctx) => {
|
||||
// 如果缓存中不存在数据
|
||||
console.log("从服务端重新获取微信读书");
|
||||
// 从服务器拉取数据
|
||||
const response = await axios.get(url);
|
||||
const response = await axios.get(url, {
|
||||
Headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.67",
|
||||
},
|
||||
});
|
||||
data = getData(response.data.books);
|
||||
updateTime = new Date().toISOString();
|
||||
if (!data) {
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "微信读书",
|
||||
subtitle: "飙升榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
return false;
|
||||
@ -59,8 +70,7 @@ wereadRouter.get("/weread", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "微信读书",
|
||||
subtitle: "飙升榜",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -81,7 +91,7 @@ wereadRouter.get("/weread/new", async (ctx) => {
|
||||
try {
|
||||
// 从服务器拉取最新数据
|
||||
const response = await axios.get(url);
|
||||
const newData = getData(response.data);
|
||||
const newData = getData(response.data.books);
|
||||
updateTime = new Date().toISOString();
|
||||
console.log("从服务端重新获取微信读书");
|
||||
|
||||
@ -89,8 +99,7 @@ wereadRouter.get("/weread/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "微信读书",
|
||||
subtitle: "飙升榜",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -108,8 +117,7 @@ wereadRouter.get("/weread/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "微信读书",
|
||||
subtitle: "飙升榜",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -118,12 +126,12 @@ wereadRouter.get("/weread/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "微信读书",
|
||||
subtitle: "飙升榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
wereadRouter.info = routerInfo;
|
||||
module.exports = wereadRouter;
|
||||
|
@ -2,6 +2,13 @@ const Router = require("koa-router");
|
||||
const zhihuRouter = new Router();
|
||||
const axios = require("axios");
|
||||
const { get, set, del } = require("../utils/cacheData");
|
||||
const router = require(".");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
title: "知乎",
|
||||
subtitle: "热榜",
|
||||
};
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "zhihuData";
|
||||
@ -59,6 +66,7 @@ zhihuRouter.get("/zhihu", async (ctx) => {
|
||||
if (!data) {
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
return false;
|
||||
@ -69,8 +77,7 @@ zhihuRouter.get("/zhihu", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "知乎",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
from,
|
||||
total: data.length,
|
||||
updateTime,
|
||||
@ -80,8 +87,7 @@ zhihuRouter.get("/zhihu", async (ctx) => {
|
||||
console.error(error);
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "知乎",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
@ -101,8 +107,7 @@ zhihuRouter.get("/zhihu/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "知乎",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
total: newData.length,
|
||||
updateTime,
|
||||
data: newData,
|
||||
@ -120,8 +125,7 @@ zhihuRouter.get("/zhihu/new", async (ctx) => {
|
||||
ctx.body = {
|
||||
code: 200,
|
||||
message: "获取成功",
|
||||
title: "知乎",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
total: cachedData.length,
|
||||
updateTime,
|
||||
data: cachedData,
|
||||
@ -130,12 +134,12 @@ zhihuRouter.get("/zhihu/new", async (ctx) => {
|
||||
// 如果缓存中也没有数据,则返回错误信息
|
||||
ctx.body = {
|
||||
code: 500,
|
||||
title: "知乎",
|
||||
subtitle: "热榜",
|
||||
...routerInfo,
|
||||
message: "获取失败",
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
zhihuRouter.info = routerInfo;
|
||||
module.exports = zhihuRouter;
|
||||
|
39
utils/test.json
Normal file
39
utils/test.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"opts": {},
|
||||
"methods": ["HEAD", "OPTIONS", "GET", "PUT", "PATCH", "POST", "DELETE"],
|
||||
"exclusive": false,
|
||||
"params": {},
|
||||
"stack": [
|
||||
{
|
||||
"opts": {
|
||||
"end": true,
|
||||
"name": null,
|
||||
"sensitive": false,
|
||||
"strict": false,
|
||||
"prefix": ""
|
||||
},
|
||||
"name": null,
|
||||
"methods": ["HEAD", "GET"],
|
||||
"paramNames": [],
|
||||
"stack": [null],
|
||||
"path": "/zhihu",
|
||||
"regexp": {}
|
||||
},
|
||||
{
|
||||
"opts": {
|
||||
"end": true,
|
||||
"name": null,
|
||||
"sensitive": false,
|
||||
"strict": false,
|
||||
"prefix": ""
|
||||
},
|
||||
"name": null,
|
||||
"methods": ["HEAD", "GET"],
|
||||
"paramNames": [],
|
||||
"stack": [null],
|
||||
"path": "/zhihu/new",
|
||||
"regexp": {}
|
||||
}
|
||||
],
|
||||
"info": { "title": "知乎", "subtitle": "热榜" }
|
||||
}
|
Loading…
Reference in New Issue
Block a user