Skip to content

Commit 15feb28

Browse files
author
lucifer
committed
feat: d2
1 parent 3c28c21 commit 15feb28

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

middleware/mockUserInfo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = async function checkAuth(ctx, next) {
66
login: "azl397985856",
77
avatar_url: "https://avatars.githubusercontent.com/u/12479470?v=4",
88
name: "lucifer",
9-
pay: true,
9+
pay: false,
1010
};
1111

1212
await next();

routes/dailyProblem.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ const router = require("koa-router")();
22
const solutions = require("../static/solution/solutions.json");
33
const { decrypt } = require("../utils/crypto");
44

5-
const { success } = require("../utils/request");
5+
const { success, fail } = require("../utils/request");
6+
7+
function getCurrentDay(date) {
8+
return 1;
9+
}
610

711
router.get("/api/v1/daily-problem", async (ctx) => {
812
// 1. 如果用户指定了时间,则获取指定时间,否则获取今天
@@ -67,9 +71,17 @@ router.get("/api/v1/daily-problem", async (ctx) => {
6771

6872
router.get("/api/v1/daily-problem/solution", async (ctx) => {
6973
// 逻辑和上面类似,只是返回值为 Markdown
70-
ctx.body = success({
71-
content: decrypt(solutions[1].content),
72-
});
74+
75+
const day = ctx.query.day || getCurrentDay(); // 用户指定的实际第几天(注意这里的 day 是数字,含义为第 day 天)
76+
if (day in solutions) {
77+
ctx.body = success({
78+
content: decrypt(solutions[day].content),
79+
});
80+
} else {
81+
ctx.body = fail({
82+
message: "当前暂时没有官方题解,请联系当前讲师进行处理~",
83+
});
84+
}
7385
});
7486

7587
module.exports = router;

0 commit comments

Comments
 (0)