feat: 新增获取全部接口信息

This commit is contained in:
imsyy
2023-07-03 16:14:40 +08:00
parent ffc9e7cb37
commit e5bd04fde1
19 changed files with 301 additions and 171 deletions

View File

@@ -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;