mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
new db update fix
This commit is contained in:
parent
ce573a63ab
commit
002865ed4a
3 changed files with 22 additions and 13 deletions
|
@ -101,7 +101,6 @@ function GetApp(): ModuleType {
|
|||
const savedQuestionsDir = publicDir + 'savedQuestions'
|
||||
const recivedFiles = publicDir + 'recivedfiles'
|
||||
const uloadFiles = publicDir + 'f'
|
||||
const dataFiles: Array<DataFile> = utils.ReadJSON(dbsFile)
|
||||
const motdFile = publicDir + 'motd'
|
||||
const userSpecificMotdFile = publicDir + 'userSpecificMotd.json'
|
||||
|
||||
|
@ -149,6 +148,7 @@ function GetApp(): ModuleType {
|
|||
})
|
||||
)
|
||||
|
||||
const dataFiles: Array<DataFile> = 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,
|
||||
|
|
|
@ -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<QuestionDb> {
|
||||
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)
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 0d679a611ad32ec5cf5f226df3007e26fbdaa085
|
||||
Subproject commit 6251456781998bfc4fad535ccdc9e90a56094001
|
Loading…
Add table
Add a link
Reference in a new issue