files improvements

This commit is contained in:
mrfry 2023-04-10 20:27:00 +02:00
parent 994fe70d95
commit 8647088faf
6 changed files with 46 additions and 27 deletions

View file

@ -125,11 +125,6 @@ function GetApp(): ModuleType {
ftw.action()
})
ftw.action()
} else {
logger.Log(
`File ${ftw.fname} does not exists to watch!`,
logger.GetColor('redbg')
)
}
})
}

View file

@ -106,11 +106,6 @@ function GetApp(): ModuleType {
logger.Log(`Donate URL changed: ${newData.replace(/\/n/g, '')}`)
loadDonateURL()
})
} else {
logger.Log(
`Couldnt read links file! (${linksFile})`,
logger.GetColor('redbg')
)
}
// --------------------------------------------------------------

View file

@ -259,6 +259,7 @@ Object.keys(modules).forEach(function (key) {
)
app.use(module.route, module.app)
} catch (err) {
logger.Log(`Error setting up submodule: ${module.name}`, 'redbg')
console.error(err)
}
})

View file

@ -5,6 +5,7 @@ import {
PeersInfoSchema,
ModulesSchema,
SelfInfoSchema,
LinksSchema,
} from '../types/typeSchemas'
import logger from './logger'
import utils from './utils'
@ -15,8 +16,9 @@ type FileDescriptor = {
path: string
schema?: Schema
defaultValue?: string
shouldBe?: string
description?: string
errorIfMissing?: boolean
warningIfMissing?: boolean
}
export const validateFiles = (): boolean => {
@ -29,16 +31,24 @@ export const validateFiles = (): boolean => {
fileExists = true
}
if (file.shouldBe && !fileExists) {
if (file.errorIfMissing && !fileExists) {
const errMsg = [`File "${file.path}" does not exist! (${key})`]
if (file.shouldBe) {
errMsg.push(`Should be: ${file.shouldBe}`)
if (file.description) {
errMsg.push(`Should be: ${file.description}`)
}
logger.Log(errMsg.join(' '), 'redbg')
everythingValid = false
return
}
if (file.warningIfMissing && !fileExists) {
const warningMsg = [`File "${file.path}" does not exist! (${key})`]
if (file.description) {
warningMsg.push(`Should be: ${file.description}`)
}
logger.Log(warningMsg.join(' '), 'yellowbg')
}
if (file.schema && fileExists) {
const val = utils.ReadJSON(file.path)
if (!isJsonValidAndLogError(val, file.schema, file.path)) {
@ -71,43 +81,51 @@ export const files = {
// --------------------------------------------------------------------------------
serverPath: {
path: 'dist/server.js',
shouldBe:
errorIfMissing: true,
description:
'server main entry file, created after running "npm run build"',
},
qminingPageDir: {
path: 'submodules/qmining-page',
shouldBe:
errorIfMissing: true,
description:
'qmining page submodule directory, created by pulling submodules / setup script',
},
qminingIndexPath: {
path: 'nextStatic/qminingPagePublic/index.html',
shouldBe:
errorIfMissing: true,
description:
'qmining page-s build index.html, created by "npm run build" in qmining page submodule dir',
},
dataEditorPageDir: {
path: 'submodules/qmining-data-editor',
shouldBe:
errorIfMissing: true,
description:
'qmining data editor page submodule directory, created by pulling submodules / setup script',
},
dataEditorIndexPath: {
path: 'nextStatic/dataEditorPublic/index.html',
shouldBe:
errorIfMissing: true,
description:
'qmining data editor-s build index.html, created by "npm run build" in qmining data editor submodule dir',
},
moodleTestUserscriptDir: {
path: 'submodules/moodle-test-userscript',
shouldBe:
errorIfMissing: true,
description:
'moodle test userscript submodule directory, created by pulling submodules / setup script',
},
moodleTestUserscriptPath: {
path: 'submodules/moodle-test-userscript/stable.user.js',
shouldBe:
errorIfMissing: true,
description:
'moodle test userscript file, created by pulling submodules / setup script',
},
domainFile: {
path: 'data/domain',
shouldBe:
errorIfMissing: true,
description:
'server domain for cookies and stuff, for ex.: "frylabs.net", no "http://" and things like that, just the domain',
},
// --------------------------------------------------------------------------------
@ -156,10 +174,12 @@ export const files = {
rootRedirectToFile: {
path: 'data/apiRootRedirectTo',
description: 'url to redirect users trying to acces root api path',
warningIfMissing: true,
},
modulesFile: {
path: './src/modules.json',
shouldBe: 'module files for server',
errorIfMissing: true,
description: 'module files for server',
schema: ModulesSchema,
},
extraModulesFile: {
@ -169,14 +189,16 @@ export const files = {
},
statExcludeFile: {
path: './data/statExclude.json',
shouldBe:
errorIfMissing: true,
description:
'array of strings which if included in requests url-s then the request itself is not counted in stats',
defaultValue: JSON.stringify([]),
schema: { type: 'array', items: { type: 'string' } },
},
usersDBPath: {
path: './data/dbs/users.db',
shouldBe: 'users sqlite db file',
errorIfMissing: true,
description: 'users sqlite db file',
},
// --------------------------------------------------------------------------------
@ -189,6 +211,12 @@ export const files = {
description:
'test users, recieved data from them wont get added to question dbs',
},
linksFile: {
path: 'data/links.json',
schema: LinksSchema,
description: 'file containing links, for ex.: patreon and paypal',
warningIfMissing: true,
},
// --------------------------------------------------------------------------------
// log files

@ -1 +1 @@
Subproject commit e17bbe6402ab366e1a6ab022b4194b02646bf0d3
Subproject commit 89edf8609922d6bb4054fca4f9712a9efbbce9f0

@ -1 +1 @@
Subproject commit d94bf74663f070b1565c9d98c99a3b6c92483b50
Subproject commit 509aff7cdd5b619568e7c433b85a56fd4ef3399b