From 8647088fafa59d78a025b9bf0f22698e9a24f9c0 Mon Sep 17 00:00:00 2001 From: mrfry Date: Mon, 10 Apr 2023 20:27:00 +0200 Subject: [PATCH] files improvements --- src/modules/api/api.ts | 5 --- src/modules/qmining/qmining.ts | 5 --- src/server.ts | 1 + src/utils/files.ts | 58 +++++++++++++++++++++++++--------- submodules/qmining-data-editor | 2 +- submodules/qmining-page | 2 +- 6 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/modules/api/api.ts b/src/modules/api/api.ts index 8087c12..c4fece5 100644 --- a/src/modules/api/api.ts +++ b/src/modules/api/api.ts @@ -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') - ) } }) } diff --git a/src/modules/qmining/qmining.ts b/src/modules/qmining/qmining.ts index aa35106..190f9e7 100644 --- a/src/modules/qmining/qmining.ts +++ b/src/modules/qmining/qmining.ts @@ -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') - ) } // -------------------------------------------------------------- diff --git a/src/server.ts b/src/server.ts index d104885..5631b83 100755 --- a/src/server.ts +++ b/src/server.ts @@ -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) } }) diff --git a/src/utils/files.ts b/src/utils/files.ts index 52cce06..ad1edfa 100644 --- a/src/utils/files.ts +++ b/src/utils/files.ts @@ -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 diff --git a/submodules/qmining-data-editor b/submodules/qmining-data-editor index e17bbe6..89edf86 160000 --- a/submodules/qmining-data-editor +++ b/submodules/qmining-data-editor @@ -1 +1 @@ -Subproject commit e17bbe6402ab366e1a6ab022b4194b02646bf0d3 +Subproject commit 89edf8609922d6bb4054fca4f9712a9efbbce9f0 diff --git a/submodules/qmining-page b/submodules/qmining-page index d94bf74..509aff7 160000 --- a/submodules/qmining-page +++ b/submodules/qmining-page @@ -1 +1 @@ -Subproject commit d94bf74663f070b1565c9d98c99a3b6c92483b50 +Subproject commit 509aff7cdd5b619568e7c433b85a56fd4ef3399b