Skip to content

Commit 2ebc791

Browse files
author
lucifer
committed
feat: 61
1 parent d78e83f commit 2ebc791

File tree

6 files changed

+305
-50
lines changed

6 files changed

+305
-50
lines changed

middleware/passport.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const db = [
99
{
1010
login: "azl397985856",
1111
},
12+
{
13+
login: "Yueqi-19",
14+
},
1215
];
1316

1417
module.exports = async function checkAuth(ctx, next) {
@@ -33,10 +36,12 @@ module.exports = async function checkAuth(ctx, next) {
3336
}
3437
} catch (err) {
3538
console.log("token 解析失败:", err);
39+
return;
3640
}
3741
}
3842
}
3943
const code = ctx.query.code;
44+
if (!code) return;
4045
const { access_token } = await fetch(
4146
`https://github.com/login/oauth/access_token?code=${code}&client_id=${clientId}&client_secret=${secret}`,
4247
{
@@ -46,6 +51,7 @@ module.exports = async function checkAuth(ctx, next) {
4651
},
4752
}
4853
).then((res) => res.json());
54+
if (!access_token) return;
4955

5056
const user = await fetch("https://api.github.com/user", {
5157
headers: {

routes/lectures.js

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,44 @@
11
const router = require("koa-router")();
2-
const lectures = require("../static/lectures/lectures.json");
2+
const lectures = require("../static/lectures/lectures-by-category.json");
3+
const lecturesId = require("../static/lectures/lectures-by-id.json");
34
const { decrypt } = require("../utils/crypto");
45
const { success, fail } = require("../utils/request");
56

7+
router.get("/api/v1/lectures/advance", async (ctx) => {
8+
ctx.body = {
9+
success: true,
10+
code: 0,
11+
data: Object.values(lectures.advance),
12+
};
13+
});
14+
15+
router.get("/api/v1/lectures/topic", async (ctx) => {
16+
ctx.body = {
17+
success: true,
18+
code: 0,
19+
data: Object.values(lectures.topic),
20+
};
21+
});
22+
623
router.get("/api/v1/lectures/basic", async (ctx) => {
724
ctx.body = {
825
success: true,
926
code: 0,
10-
data: [
11-
{
12-
title: "01. 数组,栈,队列",
13-
desc: "主要介绍了数组,栈,队列基本原理,基础 API 以及其对应的复杂度",
14-
image: {
15-
url:
16-
"https://tva1.sinaimg.cn/large/007S8ZIlly1gfbikq9ipmj30cd0a73yp.jpg",
17-
alt: "栈",
18-
},
19-
id: 1,
20-
},
21-
],
27+
data: Object.values(lectures.basic),
2228
};
2329
});
2430

2531
router.get("/api/v1/lectures/intro", async (ctx) => {
2632
ctx.body = {
2733
success: true,
2834
code: 0,
29-
data: [
30-
{
31-
title: "01. 数据结构与算法概述",
32-
desc: "主要介绍了数据结构与算法是在研究什么",
33-
image: {
34-
url:
35-
"https://cdn.jsdelivr.net/gh/azl397985856/cdn/2020-10-22/1603338453129-image.png",
36-
alt: "数据结构总览",
37-
},
38-
id: -1,
39-
},
40-
{
41-
title: "02. 如何衡量算法的性能",
42-
desc: "介绍复杂度",
43-
image: {
44-
url:
45-
"https://cdn.jsdelivr.net/gh/azl397985856/cdn/2020-10-22/1603339778900-image.png",
46-
alt: "复杂度",
47-
},
48-
id: -2,
49-
},
50-
],
35+
data: Object.values(lectures.intro),
5136
};
5237
});
5338

5439
router.get("/api/v1/lectures/:id", async (ctx) => {
5540
const id = ctx.params.id;
56-
const lecture = lectures[id];
41+
const lecture = lecturesId[id];
5742
if (!lecture) {
5843
ctx.body = fail({ message: "讲义不存在" });
5944
} else {

0 commit comments

Comments
 (0)