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()
}) })
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, '')}`) logger.Log(`Donate URL changed: ${newData.replace(/\/n/g, '')}`)
loadDonateURL() 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) app.use(module.route, module.app)
} catch (err) { } catch (err) {
logger.Log(`Error setting up submodule: ${module.name}`, 'redbg')
console.error(err) console.error(err)
} }
}) })

View file

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

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

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