From 656427e444167aed31ce8570a71db37faf2f181f Mon Sep 17 00:00:00 2001 From: juzeon <812312770@qq.com> Date: Mon, 2 Aug 2021 21:38:23 +0800 Subject: [PATCH] alter section display --- slader-legacy-backend/src/entity-fill.ts | 4 ++-- slader-legacy-backend/src/routers/textbook-router.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/slader-legacy-backend/src/entity-fill.ts b/slader-legacy-backend/src/entity-fill.ts index c1c4a8f..74c6ae8 100644 --- a/slader-legacy-backend/src/entity-fill.ts +++ b/slader-legacy-backend/src/entity-fill.ts @@ -2,7 +2,7 @@ import {IExercise, ITextbook, IToc} from "./types" export function fillIToc(single: any) { return { - section: single.section, + section: single.section.replace(/\//g,'-'), count: single.count, pageBegin: single.pageBegin, pageEnd: single.pageEnd @@ -19,7 +19,7 @@ export function fillITextbook(single: any) { export function fillIExercise(single: any) { return { exercise: single.exercise, - section: single.section, + section: single.section.replace(/\//g,'-'), part: single.part, page: single.page, html: single.html diff --git a/slader-legacy-backend/src/routers/textbook-router.ts b/slader-legacy-backend/src/routers/textbook-router.ts index 1234831..e80a25a 100644 --- a/slader-legacy-backend/src/routers/textbook-router.ts +++ b/slader-legacy-backend/src/routers/textbook-router.ts @@ -24,13 +24,13 @@ textbookRouter.get('/:textbook/:section?/:exercise?', }), query('page').optional().isInt({min: 1}), param('section').optional().notEmpty().bail().custom((input, {req}) => { - if (!textbookModel.existSection(req.params!.textbook, input)) { + if (!textbookModel.existSection(req.params!.textbook, input.replace(/-/g, '/'))) { throw new Error('section not exist') } return true }), param('exercise').optional().notEmpty().bail().custom((input, {req}) => { - if (!textbookModel.existExercise(req.params!.textbook, req.params!.section, input)) { + if (!textbookModel.existExercise(req.params!.textbook, req.params!.section.replace(/-/g, '/'), input)) { throw new Error('exercise not exist') } return true @@ -40,9 +40,9 @@ textbookRouter.get('/:textbook/:section?/:exercise?', if (req.query.page) { res.json(await textbookService.getPage(req.params.textbook, Number(req.query.page))) } else if (req.params.exercise) { - res.json(await textbookService.getExercise(req.params.textbook, req.params.section, req.params.exercise)) + res.json(await textbookService.getExercise(req.params.textbook, req.params.section.replace(/-/g, '/'), req.params.exercise)) } else if (req.params.section) { - res.json(await textbookService.getSection(req.params.textbook, req.params.section)) + res.json(await textbookService.getSection(req.params.textbook, req.params.section.replace(/-/g, '/'))) } else { res.json(await textbookService.getTextbook(req.params.textbook)) }