mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 13:14:55 +08:00
feat: 新增获取全部接口信息
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user