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:
@@ -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') {
|
||||||
|
Submodule submodules/qmining-page updated: aae943336a...fbf0c40fbb
Reference in New Issue
Block a user