mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added supportedSites api
This commit is contained in:
parent
bf2f63e810
commit
4c03e05686
1 changed files with 39 additions and 0 deletions
|
@ -293,6 +293,35 @@ function saveQuestion(questions, subj, testUrl, userid, savedQuestionsDir) {
|
||||||
utils.WriteFile(JSON.stringify(questionsToSave), `${subjPath}/${fname}`)
|
utils.WriteFile(JSON.stringify(questionsToSave), `${subjPath}/${fname}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadSupportedSites() {
|
||||||
|
const script = utils.ReadFile(userScriptFile).split('\n')
|
||||||
|
|
||||||
|
let i = 0
|
||||||
|
let stayIn = true
|
||||||
|
let inHeader = false
|
||||||
|
let inMatch = false
|
||||||
|
const sites = []
|
||||||
|
while (i < script.length && stayIn) {
|
||||||
|
if (inHeader) {
|
||||||
|
if (script[i].includes('@match')) {
|
||||||
|
inMatch = true
|
||||||
|
}
|
||||||
|
if (inMatch && !script[i].includes('match')) {
|
||||||
|
stayIn = false
|
||||||
|
inMatch = false
|
||||||
|
}
|
||||||
|
if (inMatch) {
|
||||||
|
sites.push(script[i].split(' ').pop())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inHeader = script[i].includes('==UserScript==')
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
return sites
|
||||||
|
}
|
||||||
|
|
||||||
function LoadVersion() {
|
function LoadVersion() {
|
||||||
const scriptContent = utils.ReadFile(userScriptFile)
|
const scriptContent = utils.ReadFile(userScriptFile)
|
||||||
|
|
||||||
|
@ -385,6 +414,7 @@ function setup(data: SubmoduleData): any {
|
||||||
const savedQuestionsDir = publicDir + 'savedQuestions'
|
const savedQuestionsDir = publicDir + 'savedQuestions'
|
||||||
|
|
||||||
let version = LoadVersion()
|
let version = LoadVersion()
|
||||||
|
let supportedSites = loadSupportedSites()
|
||||||
let motd = LoadMOTD(motdFile)
|
let motd = LoadMOTD(motdFile)
|
||||||
let userSpecificMotd = LoadUserSpecificMOTD(userSpecificMotdFile)
|
let userSpecificMotd = LoadUserSpecificMOTD(userSpecificMotdFile)
|
||||||
let testUsers: any = LoadTestUsers()
|
let testUsers: any = LoadTestUsers()
|
||||||
|
@ -420,6 +450,7 @@ function setup(data: SubmoduleData): any {
|
||||||
logMsg: 'User script file changed',
|
logMsg: 'User script file changed',
|
||||||
action: () => {
|
action: () => {
|
||||||
version = LoadVersion()
|
version = LoadVersion()
|
||||||
|
supportedSites = loadSupportedSites()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -662,6 +693,13 @@ function setup(data: SubmoduleData): any {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.get('/supportedSites', function (req: Request, res: any) {
|
||||||
|
logger.LogReq(req)
|
||||||
|
|
||||||
|
res.json(supportedSites)
|
||||||
|
})
|
||||||
|
|
||||||
app.get('/datacount', function (req: Request, res: any) {
|
app.get('/datacount', function (req: Request, res: any) {
|
||||||
logger.LogReq(req)
|
logger.LogReq(req)
|
||||||
if (req.query.detailed === 'all') {
|
if (req.query.detailed === 'all') {
|
||||||
|
@ -675,6 +713,7 @@ function setup(data: SubmoduleData): any {
|
||||||
res.json(getSimplreRes(questionDbs))
|
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 user: User = req.session.user
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue