mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Fixed question db overwriting
This commit is contained in:
parent
5ca0abbabf
commit
a9eeaf51b4
4 changed files with 29 additions and 3 deletions
|
@ -149,7 +149,7 @@ function GetApp(): ModuleType {
|
||||||
)
|
)
|
||||||
|
|
||||||
const dataFiles: Array<DataFile> = utils.ReadJSON(dbsFile)
|
const dataFiles: Array<DataFile> = utils.ReadJSON(dbsFile)
|
||||||
const questionDbs = loadJSON(dataFiles, publicDir)
|
const questionDbs: Array<QuestionDb> = loadJSON(dataFiles, publicDir)
|
||||||
let version = ''
|
let version = ''
|
||||||
let rootRedirectURL = ''
|
let rootRedirectURL = ''
|
||||||
let motd = ''
|
let motd = ''
|
||||||
|
@ -268,6 +268,7 @@ function GetApp(): ModuleType {
|
||||||
return {
|
return {
|
||||||
path: qdb.path.replace(publicDir, ''),
|
path: qdb.path.replace(publicDir, ''),
|
||||||
name: qdb.name,
|
name: qdb.name,
|
||||||
|
locked: qdb.locked,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -873,6 +874,12 @@ function GetApp(): ModuleType {
|
||||||
return loadedNewDb
|
return loadedNewDb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dbExists(location, qdbs: Array<QuestionDb>) {
|
||||||
|
return qdbs.some((qdb) => {
|
||||||
|
return qdb.name === location
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
app.post('/isAdding', function(req: Request, res: any) {
|
app.post('/isAdding', function(req: Request, res: any) {
|
||||||
logger.LogReq(req)
|
logger.LogReq(req)
|
||||||
const user: User = req.session.user
|
const user: User = req.session.user
|
||||||
|
@ -897,7 +904,21 @@ function GetApp(): ModuleType {
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
if (suitedQuestionDbs.length === 0) {
|
if (suitedQuestionDbs.length === 0) {
|
||||||
suitedQuestionDbs.push(getNewQdb(location, maxIndex))
|
if (!dbExists(location, questionDbs)) {
|
||||||
|
suitedQuestionDbs.push(getNewQdb(location, maxIndex))
|
||||||
|
} else {
|
||||||
|
logger.Log(
|
||||||
|
`Tried to add existing db named ${location}!`,
|
||||||
|
logger.GetColor('red')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (suitedQuestionDbs.length === 0) {
|
||||||
|
res.json({
|
||||||
|
status: 'fail',
|
||||||
|
msg: 'No suitable dbs to add questions to',
|
||||||
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
processIncomingRequest(req.body, suitedQuestionDbs, dryRun, user)
|
processIncomingRequest(req.body, suitedQuestionDbs, dryRun, user)
|
||||||
|
|
|
@ -20,6 +20,7 @@ export interface Subject {
|
||||||
export interface DataFile {
|
export interface DataFile {
|
||||||
path: string
|
path: string
|
||||||
name: string
|
name: string
|
||||||
|
locked?: Boolean
|
||||||
shouldSearch:
|
shouldSearch:
|
||||||
| string
|
| string
|
||||||
| {
|
| {
|
||||||
|
|
|
@ -306,6 +306,10 @@ export function shouldSaveDataFile(
|
||||||
df: DataFile,
|
df: DataFile,
|
||||||
recievedData: RecievedData
|
recievedData: RecievedData
|
||||||
): Boolean {
|
): Boolean {
|
||||||
|
if (df.locked) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if (df.shouldSave.version) {
|
if (df.shouldSave.version) {
|
||||||
const { compare, val } = df.shouldSave.version
|
const { compare, val } = df.shouldSave.version
|
||||||
if (compare === 'equals') {
|
if (compare === 'equals') {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit aae943336ab052e61f61e20d2c3dd0b45a263183
|
Subproject commit fbf0c40fbb70d712402baf3aa9294093f66a89ab
|
Loading…
Add table
Add a link
Reference in a new issue