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