diff --git a/bin/www.js b/bin/www.js index dc131992..c92ceed7 100644 --- a/bin/www.js +++ b/bin/www.js @@ -14,7 +14,8 @@ const debug = Debug(`${DEBUG_NAMESPACE}:www:${process.pid}`); await initializeDatabase(); const directoryName = path.dirname(fileURLToPath(import.meta.url)); const processCount = Math.min(getConfigProperty('application.maximumProcesses'), os.cpus().length); -process.title = `${getConfigProperty('application.applicationName')} (Primary)`; +const applicationName = getConfigProperty('application.applicationName'); +process.title = `${applicationName} (Primary)`; debug(`Primary pid: ${process.pid}`); debug(`Primary title: ${process.title}`); debug(`Launching ${processCount} processes`); @@ -48,16 +49,16 @@ if (ntfyStartupConfig !== undefined) { const topic = ntfyStartupConfig.topic; const server = ntfyStartupConfig.server; const ntfyStartupMessage = { - topic, - title: getConfigProperty('application.applicationName'), message: 'Application Started', - tags: ['arrow_up'] + tags: ['arrow_up'], + title: applicationName, + topic }; const ntfyShutdownMessage = { - topic, - title: getConfigProperty('application.applicationName'), message: 'Application Shut Down', - tags: ['arrow_down'] + tags: ['arrow_down'], + title: applicationName, + topic }; if (server !== undefined) { ntfyStartupMessage.server = server; diff --git a/bin/www.ts b/bin/www.ts index 4d90f3b1..36c640f2 100644 --- a/bin/www.ts +++ b/bin/www.ts @@ -25,7 +25,9 @@ const processCount = Math.min( os.cpus().length ) -process.title = `${getConfigProperty('application.applicationName')} (Primary)` +const applicationName = getConfigProperty('application.applicationName') + +process.title = `${applicationName} (Primary)` debug(`Primary pid: ${process.pid}`) debug(`Primary title: ${process.title}`) @@ -71,17 +73,17 @@ if (ntfyStartupConfig !== undefined) { const server = ntfyStartupConfig.server const ntfyStartupMessage: NtfyMessageOptions = { - topic, - title: getConfigProperty('application.applicationName'), message: 'Application Started', - tags: ['arrow_up'] + tags: ['arrow_up'], + title: applicationName, + topic } const ntfyShutdownMessage: NtfyMessageOptions = { - topic, - title: getConfigProperty('application.applicationName'), message: 'Application Shut Down', - tags: ['arrow_down'] + tags: ['arrow_down'], + title: applicationName, + topic } if (server !== undefined) { diff --git a/data/config.testing.js b/data/config.testing.js index 3b58c65e..3b414e43 100644 --- a/data/config.testing.js +++ b/data/config.testing.js @@ -3,10 +3,10 @@ export const config = { ...cemeteryConfig }; config.application.useTestDatabases = true; config.session.doKeepAlive = true; config.users = { - testing: ['*testView', '*testUpdate', '*testAdmin'], canLogin: ['*testView', '*testUpdate', '*testAdmin'], canUpdate: ['*testUpdate'], - isAdmin: ['*testAdmin'] + isAdmin: ['*testAdmin'], + testing: ['*testView', '*testUpdate', '*testAdmin'] }; config.settings.publicInternalPath = 'public-internal'; config.settings.dynamicsGP.integrationIsEnabled = false; diff --git a/data/config.testing.ts b/data/config.testing.ts index 7d9d8d9d..984205bc 100644 --- a/data/config.testing.ts +++ b/data/config.testing.ts @@ -9,10 +9,10 @@ config.application.useTestDatabases = true config.session.doKeepAlive = true config.users = { - testing: ['*testView', '*testUpdate', '*testAdmin'], canLogin: ['*testView', '*testUpdate', '*testAdmin'], canUpdate: ['*testUpdate'], - isAdmin: ['*testAdmin'] + isAdmin: ['*testAdmin'], + testing: ['*testView', '*testUpdate', '*testAdmin'] } config.settings.publicInternalPath = 'public-internal' diff --git a/helpers/functions.api.js b/helpers/functions.api.js index b9c1b4d8..fe7fb7e1 100644 --- a/helpers/functions.api.js +++ b/helpers/functions.api.js @@ -6,9 +6,7 @@ const debug = Debug(`${DEBUG_NAMESPACE}:functions.api`); const apiKeyPath = 'data/apiKeys.json'; let apiKeys; export async function getApiKey(userName) { - if (apiKeys === undefined) { - await loadApiKeys(); - } + apiKeys ??= await loadApiKeys(); if (!Object.hasOwn(apiKeys, userName)) { await regenerateApiKey(userName); } @@ -18,9 +16,7 @@ export async function getApiKeyFromUser(user) { return await getApiKey(user.userName); } export async function getUserNameFromApiKey(apiKey) { - if (apiKeys === undefined) { - await loadApiKeys(); - } + apiKeys ??= await loadApiKeys(); for (const [userName, currentApiKey] of Object.entries(apiKeys)) { if (apiKey === currentApiKey) { return userName; @@ -29,6 +25,7 @@ export async function getUserNameFromApiKey(apiKey) { return undefined; } export async function regenerateApiKey(userName) { + apiKeys ??= await loadApiKeys(); apiKeys[userName] = generateApiKey(userName); await saveApiKeys(); } @@ -44,6 +41,7 @@ async function loadApiKeys() { debug(error); apiKeys = {}; } + return apiKeys; } async function saveApiKeys() { try { diff --git a/helpers/functions.api.ts b/helpers/functions.api.ts index 6244879b..8fe45c00 100644 --- a/helpers/functions.api.ts +++ b/helpers/functions.api.ts @@ -11,9 +11,7 @@ const apiKeyPath = 'data/apiKeys.json' let apiKeys: Record | undefined export async function getApiKey(userName: string): Promise { - if (apiKeys === undefined) { - await loadApiKeys() - } + apiKeys ??= await loadApiKeys() if (!Object.hasOwn(apiKeys, userName)) { await regenerateApiKey(userName) @@ -29,9 +27,7 @@ export async function getApiKeyFromUser(user: User): Promise { export async function getUserNameFromApiKey( apiKey: string ): Promise { - if (apiKeys === undefined) { - await loadApiKeys() - } + apiKeys ??= await loadApiKeys() for (const [userName, currentApiKey] of Object.entries(apiKeys)) { if (apiKey === currentApiKey) { @@ -43,6 +39,7 @@ export async function getUserNameFromApiKey( } export async function regenerateApiKey(userName: string): Promise { + apiKeys ??= await loadApiKeys() apiKeys[userName] = generateApiKey(userName) await saveApiKeys() } @@ -51,7 +48,7 @@ function generateApiKey(apiKeyPrefix: string): string { return `${apiKeyPrefix}-${randomUUID()}-${Date.now().toString()}` } -async function loadApiKeys(): Promise { +async function loadApiKeys(): Promise> { try { const fileData = await fs.readFile(apiKeyPath, 'utf8') apiKeys = JSON.parse(fileData) as Record @@ -59,6 +56,8 @@ async function loadApiKeys(): Promise { debug(error) apiKeys = {} } + + return apiKeys } async function saveApiKeys(): Promise {