mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
p2p fixes
This commit is contained in:
parent
2edc87d5dd
commit
16d6f04936
17 changed files with 707 additions and 582 deletions
|
@ -59,6 +59,7 @@ import {
|
|||
getSubjNameWithoutYear,
|
||||
SearchResultQuestion,
|
||||
} from '../../../utils/qdbUtils'
|
||||
import constants from '../../../constants.json'
|
||||
|
||||
interface SavedQuestionData {
|
||||
fname: string
|
||||
|
@ -79,7 +80,6 @@ interface SavedQuestionData {
|
|||
const line = '====================================================' // lol
|
||||
const registeredScriptsFile = 'stats/registeredScripts.json'
|
||||
const testUsersFile = 'data/testUsers.json'
|
||||
const userScriptFile = 'submodules/moodle-test-userscript/stable.user.js'
|
||||
const askedQuestionFile = 'stats/askedQuestions'
|
||||
const recievedQuestionFile = 'stats/recievedQuestions'
|
||||
const savedQuestionsFileName = 'savedQuestions.json'
|
||||
|
@ -358,7 +358,9 @@ function saveQuestion(
|
|||
}
|
||||
|
||||
function loadSupportedSites() {
|
||||
const script = utils.ReadFile(userScriptFile).split('\n')
|
||||
const script = utils
|
||||
.ReadFile(constants.moodleTestUserscriptPath)
|
||||
.split('\n')
|
||||
|
||||
let i = 0
|
||||
let stayIn = true
|
||||
|
@ -386,18 +388,6 @@ function loadSupportedSites() {
|
|||
return sites
|
||||
}
|
||||
|
||||
function LoadVersion() {
|
||||
const scriptContent = utils.ReadFile(userScriptFile)
|
||||
|
||||
let temp: string | string[] = scriptContent.split('\n').find((x) => {
|
||||
return x.includes('@version')
|
||||
})
|
||||
temp = temp.split(' ')
|
||||
temp = temp[temp.length - 1]
|
||||
|
||||
return temp
|
||||
}
|
||||
|
||||
function LoadMOTD(motdFile: string) {
|
||||
return utils.ReadFile(motdFile)
|
||||
}
|
||||
|
@ -470,14 +460,14 @@ function setup(data: SubmoduleData): Submodule {
|
|||
app,
|
||||
userDB,
|
||||
/* url */ publicdirs,
|
||||
moduleSpecificData: { questionDbs: questionDbs, dbsFile: dbsFile },
|
||||
moduleSpecificData: { getQuestionDbs, setQuestionDbs, dbsFile },
|
||||
} = data
|
||||
|
||||
const publicDir = publicdirs[0]
|
||||
const motdFile = publicDir + 'motd'
|
||||
const savedQuestionsDir = publicDir + 'savedQuestions'
|
||||
|
||||
let version = LoadVersion()
|
||||
let version = utils.getScriptVersion()
|
||||
let supportedSites = loadSupportedSites()
|
||||
let motd = LoadMOTD(motdFile)
|
||||
let testUsers: number[] = LoadTestUsers()
|
||||
|
@ -498,10 +488,10 @@ function setup(data: SubmoduleData): Submodule {
|
|||
},
|
||||
},
|
||||
{
|
||||
fname: userScriptFile,
|
||||
fname: constants.moodleTestUserscriptPath,
|
||||
logMsg: 'User script file changed',
|
||||
action: () => {
|
||||
version = LoadVersion()
|
||||
version = utils.getScriptVersion()
|
||||
supportedSites = loadSupportedSites()
|
||||
},
|
||||
},
|
||||
|
@ -510,7 +500,7 @@ function setup(data: SubmoduleData): Submodule {
|
|||
app.get('/getDbs', (req: Request, res: Response) => {
|
||||
logger.LogReq(req)
|
||||
res.json(
|
||||
questionDbs.map((qdb) => {
|
||||
getQuestionDbs().map((qdb) => {
|
||||
return {
|
||||
path: qdb.path.replace(publicDir, ''),
|
||||
name: qdb.name,
|
||||
|
@ -528,7 +518,7 @@ function setup(data: SubmoduleData): Submodule {
|
|||
res.setHeader('content-type', 'text/plain; charset=utf-8')
|
||||
|
||||
if (db) {
|
||||
const requestedDb = questionDbs.find((qdb) => {
|
||||
const requestedDb = getQuestionDbs().find((qdb) => {
|
||||
return qdb.name === db
|
||||
})
|
||||
|
||||
|
@ -543,7 +533,7 @@ function setup(data: SubmoduleData): Submodule {
|
|||
stringifiedData += dataToString(requestedDb.data)
|
||||
stringifiedData += '\n' + line + line + '\n'
|
||||
} else {
|
||||
stringifiedData = questionDbs
|
||||
stringifiedData = getQuestionDbs()
|
||||
.map((qdb) => {
|
||||
let result = ''
|
||||
result += '\n' + line
|
||||
|
@ -576,7 +566,7 @@ function setup(data: SubmoduleData): Submodule {
|
|||
|
||||
try {
|
||||
let maxIndex = -1
|
||||
const suitedQuestionDbs = questionDbs.filter((qdb) => {
|
||||
const suitedQuestionDbs = getQuestionDbs().filter((qdb) => {
|
||||
if (maxIndex < qdb.index) {
|
||||
maxIndex = qdb.index
|
||||
}
|
||||
|
@ -584,14 +574,14 @@ function setup(data: SubmoduleData): Submodule {
|
|||
}, [])
|
||||
|
||||
if (suitedQuestionDbs.length === 0) {
|
||||
if (!dbExists(location, questionDbs)) {
|
||||
if (!dbExists(location, getQuestionDbs())) {
|
||||
suitedQuestionDbs.push(
|
||||
getNewQdb(
|
||||
location,
|
||||
maxIndex,
|
||||
dbsFile,
|
||||
publicDir,
|
||||
questionDbs
|
||||
getQuestionDbs()
|
||||
)
|
||||
)
|
||||
} else {
|
||||
|
@ -684,7 +674,7 @@ function setup(data: SubmoduleData): Submodule {
|
|||
question: question,
|
||||
subj: subj,
|
||||
testUrl: testUrl,
|
||||
questionDbs: questionDbs,
|
||||
questionDbs: getQuestionDbs(),
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -730,13 +720,13 @@ function setup(data: SubmoduleData): Submodule {
|
|||
logger.LogReq(req)
|
||||
if (req.query.detailed === 'all') {
|
||||
res.json({
|
||||
detailed: getDetailedRes(questionDbs),
|
||||
simple: getSimplreRes(questionDbs),
|
||||
detailed: getDetailedRes(getQuestionDbs()),
|
||||
simple: getSimplreRes(getQuestionDbs()),
|
||||
})
|
||||
} else if (req.query.detailed) {
|
||||
res.json(getDetailedRes(questionDbs))
|
||||
res.json(getDetailedRes(getQuestionDbs()))
|
||||
} else {
|
||||
res.json(getSimplreRes(questionDbs))
|
||||
res.json(getSimplreRes(getQuestionDbs()))
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -758,7 +748,7 @@ function setup(data: SubmoduleData): Submodule {
|
|||
}
|
||||
|
||||
if (req.query.subjinfo) {
|
||||
result.subjinfo = getSimplreRes(questionDbs)
|
||||
result.subjinfo = getSimplreRes(getQuestionDbs())
|
||||
}
|
||||
if (req.query.version) {
|
||||
result.version = version
|
||||
|
@ -907,10 +897,10 @@ function setup(data: SubmoduleData): Submodule {
|
|||
return
|
||||
}
|
||||
|
||||
const dbIndex = questionDbs.findIndex((qdb) => {
|
||||
const dbIndex = getQuestionDbs().findIndex((qdb) => {
|
||||
return qdb.name === selectedDb.name
|
||||
})
|
||||
const currDb = questionDbs[dbIndex]
|
||||
const currDb = getQuestionDbs()[dbIndex]
|
||||
|
||||
if (dbIndex === -1) {
|
||||
res.json({
|
||||
|
@ -937,7 +927,12 @@ function setup(data: SubmoduleData): Submodule {
|
|||
return
|
||||
}
|
||||
if (resultDb) {
|
||||
questionDbs[dbIndex] = resultDb
|
||||
setQuestionDbs(
|
||||
getQuestionDbs().map((qdb, i) => {
|
||||
if (i === dbIndex) return resultDb
|
||||
return qdb
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
if (editType === 'delete') {
|
||||
|
@ -1025,6 +1020,10 @@ function setup(data: SubmoduleData): Submodule {
|
|||
// TODO: dont allow multiple instances
|
||||
// TODO: get status of it cleaning
|
||||
logger.LogReq(req)
|
||||
res.json({
|
||||
error: 'Not implemented / tested!',
|
||||
})
|
||||
return
|
||||
const user: User = req.session.user
|
||||
const status: string = req.query.status
|
||||
|
||||
|
@ -1057,7 +1056,8 @@ function setup(data: SubmoduleData): Submodule {
|
|||
|
||||
questionCleaner = fork(
|
||||
`${process.cwd()}/src/standaloneUtils/rmDuplicates.js`,
|
||||
['-s', `${process.cwd()}/${questionDbs[0].path}`]
|
||||
['-s', `${process.cwd()}/${getQuestionDbs()[0].path}`] // TODO: this only cleans index
|
||||
// #0?
|
||||
)
|
||||
questionCleaner.on('exit', function (code: number) {
|
||||
console.log('EXIT', code)
|
||||
|
@ -1073,11 +1073,11 @@ function setup(data: SubmoduleData): Submodule {
|
|||
|
||||
return {
|
||||
dailyAction: () => {
|
||||
backupData(questionDbs)
|
||||
ExportDailyDataCount(questionDbs, userDB)
|
||||
backupData(getQuestionDbs())
|
||||
ExportDailyDataCount(getQuestionDbs(), userDB)
|
||||
},
|
||||
load: () => {
|
||||
backupData(questionDbs)
|
||||
backupData(getQuestionDbs())
|
||||
|
||||
filesToWatch.forEach((ftw) => {
|
||||
if (utils.FileExists(ftw.fname)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue