User specific motd changes, adding question db name to found question

This commit is contained in:
mrfry 2021-01-11 14:47:16 +01:00
parent f19226a74e
commit 57d8f642a0
2 changed files with 25 additions and 12 deletions

View file

@ -208,7 +208,7 @@ function GetApp(): ModuleType {
rootRedirectURL = utils.ReadFile(rootRedirectToFile) rootRedirectURL = utils.ReadFile(rootRedirectToFile)
} }
function userShouldGetUserSpecificMOTD(id) { function userShouldGetUserSpecificMOTD(id, cid) {
let shouldSee = true let shouldSee = true
let write = false let write = false
@ -226,7 +226,7 @@ function GetApp(): ModuleType {
if (userSpecificMotd[id].seeCounter) { if (userSpecificMotd[id].seeCounter) {
if (userSpecificMotd[id].seeCounter <= 1) { if (userSpecificMotd[id].seeCounter <= 1) {
shouldSee = false shouldSee = false
} else { } else if (cid) {
userSpecificMotd[id].seeCounter -= 1 userSpecificMotd[id].seeCounter -= 1
write = true write = true
} }
@ -1137,11 +1137,9 @@ function GetApp(): ModuleType {
res.json(response) res.json(response)
const saveableQuestions = response.reduce((acc, res) => { const saveableQuestions = response.reduce((acc, res) => {
// TODO: only save if there isnt an answer for it if (res.answers.length === 0) {
// if (res.answers.length === 0) {
// acc.push(res.question)
// }
acc.push(res.question) acc.push(res.question)
}
return acc return acc
}, []) }, [])
@ -1298,6 +1296,7 @@ function GetApp(): ModuleType {
app.get('/infos', function(req: Request, res) { app.get('/infos', function(req: Request, res) {
const user: User = req.session.user const user: User = req.session.user
const cid: any = req.query.cid
const result: any = { const result: any = {
result: 'success', result: 'success',
@ -1312,9 +1311,11 @@ function GetApp(): ModuleType {
} }
if (req.query.motd) { if (req.query.motd) {
result.motd = motd result.motd = motd
if (userSpecificMotd[user.id] && userShouldGetUserSpecificMOTD(user.id)) {
result.userSpecificMotd = userSpecificMotd[user.id].msg result.userSpecificMotd = userSpecificMotd[user.id].msg
} result.userShouldGetUserSpecificMOTD = userShouldGetUserSpecificMOTD(
user.id,
cid
)
} }
res.json(result) res.json(result)
}) })
@ -1330,7 +1331,7 @@ function GetApp(): ModuleType {
req.headers['cf-connecting-ip'] || req.connection.remoteAddress req.headers['cf-connecting-ip'] || req.connection.remoteAddress
const ua: any = req.headers['user-agent'] const ua: any = req.headers['user-agent']
const registeredScripts = utils.ReadJSON(registeredScriptsFile) const registeredScripts = utils.ReadJSON(registeredScriptsFile)
const { cid, uid, version, date } = req.body const { cid, uid, version, installSource, date } = req.body
const index = registeredScripts.findIndex((registration) => { const index = registeredScripts.findIndex((registration) => {
return registration.cid === cid return registration.cid === cid
@ -1340,6 +1341,7 @@ function GetApp(): ModuleType {
const x: any = { const x: any = {
cid: cid, cid: cid,
version: version, version: version,
installSource: installSource,
date: date, date: date,
ip: ip, ip: ip,
userAgent: ua, userAgent: ua,

View file

@ -569,7 +569,18 @@ if (!isMainThread) {
searchTillMatchPercent, searchTillMatchPercent,
searchInAllIfNoResult searchInAllIfNoResult
) )
searchResult = [...searchResult, ...res] searchResult = [
...searchResult,
...res.map((x) => {
return {
...x,
detailedMatch: {
...x.detailedMatch,
qdb: qdb.name,
},
}
}),
]
} }
}) })
} catch (err) { } catch (err) {