alter section display

This commit is contained in:
juzeon 2021-08-02 21:38:23 +08:00
父節點 225cfdbc54
當前提交 656427e444
共有 2 個檔案被更改,包括 6 行新增6 行删除

查看文件

@ -2,7 +2,7 @@ import {IExercise, ITextbook, IToc} from "./types"
export function fillIToc(single: any) { export function fillIToc(single: any) {
return <IToc>{ return <IToc>{
section: single.section, section: single.section.replace(/\//g,'-'),
count: single.count, count: single.count,
pageBegin: single.pageBegin, pageBegin: single.pageBegin,
pageEnd: single.pageEnd pageEnd: single.pageEnd
@ -19,7 +19,7 @@ export function fillITextbook(single: any) {
export function fillIExercise(single: any) { export function fillIExercise(single: any) {
return <IExercise>{ return <IExercise>{
exercise: single.exercise, exercise: single.exercise,
section: single.section, section: single.section.replace(/\//g,'-'),
part: single.part, part: single.part,
page: single.page, page: single.page,
html: single.html html: single.html

查看文件

@ -24,13 +24,13 @@ textbookRouter.get('/:textbook/:section?/:exercise?',
}), }),
query('page').optional().isInt({min: 1}), query('page').optional().isInt({min: 1}),
param('section').optional().notEmpty().bail().custom((input, {req}) => { 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') throw new Error('section not exist')
} }
return true return true
}), }),
param('exercise').optional().notEmpty().bail().custom((input, {req}) => { 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') throw new Error('exercise not exist')
} }
return true return true
@ -40,9 +40,9 @@ textbookRouter.get('/:textbook/:section?/:exercise?',
if (req.query.page) { if (req.query.page) {
res.json(await textbookService.getPage(req.params.textbook, Number(req.query.page))) res.json(await textbookService.getPage(req.params.textbook, Number(req.query.page)))
} else if (req.params.exercise) { } 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) { } 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 { } else {
res.json(await textbookService.getTextbook(req.params.textbook)) res.json(await textbookService.getTextbook(req.params.textbook))
} }