mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Changed auth exceptions, saving question from /ask if its matches are less than 90%
This commit is contained in:
parent
d5f6f22262
commit
742f8866c7
3 changed files with 24 additions and 28 deletions
|
@ -19,7 +19,8 @@
|
|||
"nextdir": "nextStatic/qminingPagePublic",
|
||||
"name": "qmining",
|
||||
"urls": [
|
||||
"qmining.frylabs.net"
|
||||
"qmining.frylabs.net",
|
||||
"localhost"
|
||||
],
|
||||
"isNextJs": true
|
||||
},
|
||||
|
@ -30,9 +31,7 @@
|
|||
],
|
||||
"name": "api",
|
||||
"urls": [
|
||||
"api.frylabs.net",
|
||||
"localhost",
|
||||
"superhedghog.frylabs.net"
|
||||
"api.frylabs.net"
|
||||
]
|
||||
},
|
||||
"main": {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -54,15 +54,7 @@ function GetApp(): ModuleType {
|
|||
auth({
|
||||
userDB: userDB,
|
||||
jsonResponse: false,
|
||||
exceptions: [
|
||||
'/thanks',
|
||||
'/thanks.html',
|
||||
'/img/thanks.gif',
|
||||
'/favicon.ico',
|
||||
'/moodle-test-userscript/stable.user.js',
|
||||
'/irc',
|
||||
'/donate',
|
||||
],
|
||||
exceptions: ['/favicon.ico', '/img/'],
|
||||
})
|
||||
)
|
||||
app.use((req: Request, res, next) => {
|
||||
|
@ -112,7 +104,7 @@ function GetApp(): ModuleType {
|
|||
// --------------------------------------------------------------
|
||||
|
||||
// to be backwards compatible
|
||||
app.get('/ask', function(req: Request, res) {
|
||||
app.get('/ask', function (req: Request, res) {
|
||||
logger.DebugLog(`Qmining module ask redirect`, 'ask', 1)
|
||||
res.redirect(
|
||||
`http://api.frylabs.net/ask?q=${req.query.q}&subj=${req.query.subj}&data=${req.query.data}`
|
||||
|
@ -192,7 +184,7 @@ function GetApp(): ModuleType {
|
|||
]
|
||||
|
||||
simpleRedirects.forEach((redirect) => {
|
||||
app.get(redirect.from, function(req: Request, res) {
|
||||
app.get(redirect.from, function (req: Request, res) {
|
||||
if (!redirect.nolog) {
|
||||
logger.LogReq(req)
|
||||
}
|
||||
|
@ -220,7 +212,7 @@ function GetApp(): ModuleType {
|
|||
|
||||
routes.forEach((route) => {
|
||||
logger.DebugLog(`Added route /${route}`, 'Qmining routes', 1)
|
||||
app.get(`/${route}`, function(req: Request, res) {
|
||||
app.get(`/${route}`, function (req: Request, res) {
|
||||
res.redirect(
|
||||
utils.formatUrl({
|
||||
pathname: `${route}.html`,
|
||||
|
@ -234,16 +226,16 @@ function GetApp(): ModuleType {
|
|||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
app.get('/', function(req: Request, res) {
|
||||
app.get('/', function (req: Request, res) {
|
||||
res.end('hai')
|
||||
logger.LogReq(req)
|
||||
})
|
||||
|
||||
app.get('*', function(req: Request, res) {
|
||||
app.get('*', function (req: Request, res) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
app.post('*', function(req: Request, res) {
|
||||
app.post('*', function (req: Request, res) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue