|
1 | 1 | 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"); |
3 | 4 | const { decrypt } = require("../utils/crypto");
|
4 | 5 | const { success, fail } = require("../utils/request");
|
5 | 6 |
|
| 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 | + |
6 | 23 | router.get("/api/v1/lectures/basic", async (ctx) => {
|
7 | 24 | ctx.body = {
|
8 | 25 | success: true,
|
9 | 26 | 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), |
22 | 28 | };
|
23 | 29 | });
|
24 | 30 |
|
25 | 31 | router.get("/api/v1/lectures/intro", async (ctx) => {
|
26 | 32 | ctx.body = {
|
27 | 33 | success: true,
|
28 | 34 | 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), |
51 | 36 | };
|
52 | 37 | });
|
53 | 38 |
|
54 | 39 | router.get("/api/v1/lectures/:id", async (ctx) => {
|
55 | 40 | const id = ctx.params.id;
|
56 |
| - const lecture = lectures[id]; |
| 41 | + const lecture = lecturesId[id]; |
57 | 42 | if (!lecture) {
|
58 | 43 | ctx.body = fail({ message: "讲义不存在" });
|
59 | 44 | } else {
|
|
0 commit comments