Changed auth exceptions, saving question from /ask if its matches are less than 90%

This commit is contained in:
mrfry 2021-04-30 16:08:34 +02:00
parent d5f6f22262
commit 742f8866c7
3 changed files with 24 additions and 28 deletions

View file

@ -437,7 +437,7 @@ function setup(data: SubmoduleData): any {
)
})
app.get('/allqr.txt', function(req: Request, res: any) {
app.get('/allqr.txt', function (req: Request, res: any) {
logger.LogReq(req)
const db: any = req.query.db
let stringifiedData = ''
@ -475,7 +475,7 @@ function setup(data: SubmoduleData): any {
res.end(stringifiedData)
})
app.post('/isAdding', function(req: Request, res: any) {
app.post('/isAdding', function (req: Request, res: any) {
logger.LogReq(req)
const user: User = req.session.user
const dryRun = testUsers.includes(user.id)
@ -563,7 +563,7 @@ function setup(data: SubmoduleData): any {
}
})
app.post('/ask', function(req: Request, res) {
app.post('/ask', function (req: Request, res) {
const user: User = req.session.user
if (!req.body.questions) {
@ -604,7 +604,11 @@ function setup(data: SubmoduleData): any {
res.json(response)
const saveableQuestions = response.reduce((acc, res) => {
if (res.answers.length === 0) {
const save = res.answers.every((answer) => {
return answer.match < 90
})
if (save) {
acc.push(res.question)
}
return acc
@ -621,7 +625,8 @@ function setup(data: SubmoduleData): any {
}
})
})
app.get('/ask', function(req: Request, res) {
app.get('/ask', function (req: Request, res) {
if (Object.keys(req.query).length === 0) {
logger.DebugLog(`No query params /ask GET`, 'ask', 1)
res.json({
@ -657,7 +662,7 @@ function setup(data: SubmoduleData): any {
})
}
})
app.get('/datacount', function(req: Request, res: any) {
app.get('/datacount', function (req: Request, res: any) {
logger.LogReq(req)
if (req.query.detailed === 'all') {
res.json({
@ -670,7 +675,7 @@ function setup(data: SubmoduleData): any {
res.json(getSimplreRes(questionDbs))
}
})
app.get('/infos', function(req: Request, res) {
app.get('/infos', function (req: Request, res) {
const user: User = req.session.user
const result: any = {
@ -715,7 +720,7 @@ function setup(data: SubmoduleData): any {
res.json({ msg: 'done' })
})
app.post('/registerscript', function(req: Request, res) {
app.post('/registerscript', function (req: Request, res) {
logger.LogReq(req)
if (!utils.FileExists(registeredScriptsFile)) {
@ -777,7 +782,7 @@ function setup(data: SubmoduleData): any {
logger.LogReq(req)
const files = utils.ReadDir(savedQuestionsDir)
files.sort(function(a, b) {
files.sort(function (a, b) {
return (
fs.statSync(savedQuestionsDir + '/' + b).mtime.getTime() -
fs.statSync(savedQuestionsDir + '/' + a).mtime.getTime()