diff --git a/src/modules/api/api.ts b/src/modules/api/api.ts index 21589dc..89d70a1 100644 --- a/src/modules/api/api.ts +++ b/src/modules/api/api.ts @@ -101,7 +101,6 @@ function GetApp(): ModuleType { const savedQuestionsDir = publicDir + 'savedQuestions' const recivedFiles = publicDir + 'recivedfiles' const uloadFiles = publicDir + 'f' - const dataFiles: Array = utils.ReadJSON(dbsFile) const motdFile = publicDir + 'motd' const userSpecificMotdFile = publicDir + 'userSpecificMotd.json' @@ -149,6 +148,7 @@ function GetApp(): ModuleType { }) ) + const dataFiles: Array = utils.ReadJSON(dbsFile) const questionDbs = loadJSON(dataFiles, publicDir) let version = '' let rootRedirectURL = '' @@ -265,10 +265,10 @@ function GetApp(): ModuleType { logger.LogReq(req) res.json( - dataFiles.map((df) => { + questionDbs.map((qdb) => { return { - path: df.path, - name: df.name, + path: qdb.path.replace(publicDir, ''), + name: qdb.name, } }) ) @@ -915,7 +915,6 @@ function GetApp(): ModuleType { }) function getNewQdb(location, maxIndex) { - // TODO: should check if location is a not empty string logger.Log( `No suitable questiondbs found for ${location}, creating a new one...` ) @@ -956,7 +955,6 @@ function GetApp(): ModuleType { utils.WriteFile('[]', loadedNewDb.path) questionDbs.push(loadedNewDb) - // TODO: problem: new dbs wont get to workers before trying to search with them. msgAllWorker({ newdb: loadedNewDb, type: 'newdb', @@ -970,7 +968,8 @@ function GetApp(): ModuleType { const user: User = req.session.user const dryRun = testUsers.includes(user.id) if (!req.body.location) { - res.json({ msg: 'invalid location parameter!' }) + logger.Log('\tbody.location is missing') + res.json({ msg: 'body.location is missing' }) return } @@ -1161,7 +1160,7 @@ function GetApp(): ModuleType { return new Promise((resolve) => { let searchIn = testUrl ? questionDbs.reduce((acc, qdb, i) => { - if (shouldSearchDataFile(qdb, testUrl)) { + if (shouldSearchDataFile(qdb, testUrl, false)) { acc.push(i) } return acc @@ -1172,6 +1171,8 @@ function GetApp(): ModuleType { searchIn = 'all' } + // console.log(searchIn) + // searchIn could be [0], [1], ... to search every db in different thread. Put this into a // forEach(qdbs) to achieve this doALongTask({ @@ -1210,7 +1211,7 @@ function GetApp(): ModuleType { logger.Log('Search Data error!', logger.GetColor('redbg')) console.error(err) resolve({ - message: `There was an error processing the question: ${err.message}`, + mesage: `There was an error processing the question: ${err.message}`, result: [], recievedData: JSON.stringify(recievedData), success: false, diff --git a/src/utils/actions.ts b/src/utils/actions.ts index 8e98c7e..c938e68 100755 --- a/src/utils/actions.ts +++ b/src/utils/actions.ts @@ -278,8 +278,16 @@ function isQuestionValid(question: Question) { return true } -export function shouldSearchDataFile(df: DataFile, testUrl: string): Boolean { - if (typeof df.shouldSearch === 'string' && df.shouldSearch === 'always') { +export function shouldSearchDataFile( + df: DataFile, + testUrl: string, + trueIfAlways?: Boolean +): Boolean { + if ( + typeof df.shouldSearch === 'string' && + df.shouldSearch === 'always' && + trueIfAlways + ) { return true } @@ -329,7 +337,7 @@ export function loadJSON( dataDir: string ): Array { return dataFiles.reduce((acc, dataFile, index) => { - const dataPath = dataDir + '/' + dataFile.path + const dataPath = dataDir + dataFile.path if (!utils.FileExists(dataPath)) { utils.WriteFile(JSON.stringify([]), dataPath) diff --git a/submodules/qmining-page b/submodules/qmining-page index 0d679a6..6251456 160000 --- a/submodules/qmining-page +++ b/submodules/qmining-page @@ -1 +1 @@ -Subproject commit 0d679a611ad32ec5cf5f226df3007e26fbdaa085 +Subproject commit 6251456781998bfc4fad535ccdc9e90a56094001