mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
ability to download subjects in txt
This commit is contained in:
parent
e4f7d32b1c
commit
eed99e6f02
2 changed files with 25 additions and 3 deletions
|
@ -53,6 +53,7 @@ import {
|
||||||
dataToString,
|
dataToString,
|
||||||
getSubjNameWithoutYear,
|
getSubjNameWithoutYear,
|
||||||
SearchResultQuestion,
|
SearchResultQuestion,
|
||||||
|
subjectToString,
|
||||||
} from '../../../utils/qdbUtils'
|
} from '../../../utils/qdbUtils'
|
||||||
import { paths } from '../../../utils/files'
|
import { paths } from '../../../utils/files'
|
||||||
import constants from '../../../constants'
|
import constants from '../../../constants'
|
||||||
|
@ -499,11 +500,32 @@ function setup(data: SubmoduleData): Submodule {
|
||||||
app.get('/allqr.txt', function (req: Request, res: Response) {
|
app.get('/allqr.txt', function (req: Request, res: Response) {
|
||||||
logger.LogReq(req)
|
logger.LogReq(req)
|
||||||
const db: string = req.query.db
|
const db: string = req.query.db
|
||||||
|
const subjectName: string = req.query.subj
|
||||||
let stringifiedData = ''
|
let stringifiedData = ''
|
||||||
|
|
||||||
res.setHeader('content-type', 'text/plain; charset=utf-8')
|
res.setHeader('content-type', 'text/plain; charset=utf-8')
|
||||||
|
|
||||||
if (db) {
|
if (subjectName) {
|
||||||
|
const requestedDb = getQuestionDbs().find((qdb) => {
|
||||||
|
return qdb.name === db
|
||||||
|
})
|
||||||
|
if (!requestedDb) {
|
||||||
|
res.end(`No such db ${db}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const requestedSubject = requestedDb.data.find((subject) => {
|
||||||
|
return subject.Name === subjectName
|
||||||
|
})
|
||||||
|
if (!requestedSubject) {
|
||||||
|
res.end(`No such db ${db}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
stringifiedData = '\n' + line
|
||||||
|
stringifiedData += ` Questions in "${requestedDb.name}"-"${subjectName}": `
|
||||||
|
stringifiedData += line + '\n'
|
||||||
|
stringifiedData += subjectToString(requestedSubject)
|
||||||
|
stringifiedData += '\n' + line + line + '\n'
|
||||||
|
} else if (db) {
|
||||||
const requestedDb = getQuestionDbs().find((qdb) => {
|
const requestedDb = getQuestionDbs().find((qdb) => {
|
||||||
return qdb.name === db
|
return qdb.name === db
|
||||||
})
|
})
|
||||||
|
@ -514,7 +536,7 @@ function setup(data: SubmoduleData): Submodule {
|
||||||
}
|
}
|
||||||
|
|
||||||
stringifiedData = '\n' + line
|
stringifiedData = '\n' + line
|
||||||
stringifiedData += ` Questions in ${requestedDb.name}: `
|
stringifiedData += ` Questions in "${requestedDb.name}": `
|
||||||
stringifiedData += line + '\n'
|
stringifiedData += line + '\n'
|
||||||
stringifiedData += dataToString(requestedDb.data)
|
stringifiedData += dataToString(requestedDb.data)
|
||||||
stringifiedData += '\n' + line + line + '\n'
|
stringifiedData += '\n' + line + line + '\n'
|
||||||
|
|
|
@ -354,7 +354,7 @@ function questionToString(question: Question): string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function subjectToString(subj: Subject): string {
|
export function subjectToString(subj: Subject): string {
|
||||||
const { Questions, Name } = subj
|
const { Questions, Name } = subj
|
||||||
|
|
||||||
const result: string[] = []
|
const result: string[] = []
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue