diff --git a/src/modules/api/api.ts b/src/modules/api/api.ts index 72567bf..4473862 100644 --- a/src/modules/api/api.ts +++ b/src/modules/api/api.ts @@ -149,7 +149,7 @@ function GetApp(): ModuleType { ) const dataFiles: Array = utils.ReadJSON(dbsFile) - const questionDbs = loadJSON(dataFiles, publicDir) + const questionDbs: Array = loadJSON(dataFiles, publicDir) let version = '' let rootRedirectURL = '' let motd = '' @@ -268,6 +268,7 @@ function GetApp(): ModuleType { return { path: qdb.path.replace(publicDir, ''), name: qdb.name, + locked: qdb.locked, } }) ) @@ -873,6 +874,12 @@ function GetApp(): ModuleType { return loadedNewDb } + function dbExists(location, qdbs: Array) { + return qdbs.some((qdb) => { + return qdb.name === location + }) + } + app.post('/isAdding', function(req: Request, res: any) { logger.LogReq(req) const user: User = req.session.user @@ -897,7 +904,21 @@ function GetApp(): ModuleType { }, []) 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) diff --git a/src/types/basicTypes.ts b/src/types/basicTypes.ts index 470fce3..47a38ee 100644 --- a/src/types/basicTypes.ts +++ b/src/types/basicTypes.ts @@ -20,6 +20,7 @@ export interface Subject { export interface DataFile { path: string name: string + locked?: Boolean shouldSearch: | string | { diff --git a/src/utils/actions.ts b/src/utils/actions.ts index 73d9593..83401e7 100755 --- a/src/utils/actions.ts +++ b/src/utils/actions.ts @@ -306,6 +306,10 @@ export function shouldSaveDataFile( df: DataFile, recievedData: RecievedData ): Boolean { + if (df.locked) { + return false + } + if (df.shouldSave.version) { const { compare, val } = df.shouldSave.version if (compare === 'equals') { diff --git a/submodules/qmining-page b/submodules/qmining-page index aae9433..fbf0c40 160000 --- a/submodules/qmining-page +++ b/submodules/qmining-page @@ -1 +1 @@ -Subproject commit aae943336ab052e61f61e20d2c3dd0b45a263183 +Subproject commit fbf0c40fbb70d712402baf3aa9294093f66a89ab