From e8044a69a745aab08dfeea0bd9ec9dd7fe84cdd7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 12 May 2023 15:50:53 +0200 Subject: [PATCH] refactor: factor out performance records JSON file path building MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/utils/Configuration.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index cf4d2bca..6423e34c 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -94,10 +94,9 @@ export class Configuration { ...Configuration.getConfig()?.performanceStorage, ...(Configuration.getConfig()?.performanceStorage?.type === StorageType.JSON_FILE && Configuration.getConfig()?.performanceStorage?.uri && { - uri: `file://${path.join( - path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'), + uri: Configuration.buildPerformanceUriFilePath( new URL(Configuration.getConfig()?.performanceStorage?.uri).pathname - )}`, + ), }), }; } @@ -393,17 +392,22 @@ export class Configuration { private static getDefaultPerformanceStorageUri(storageType: StorageType) { switch (storageType) { case StorageType.JSON_FILE: - return `file://${path.join( - path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'), + return Configuration.buildPerformanceUriFilePath( Constants.DEFAULT_PERFORMANCE_RECORDS_FILENAME - )}`; + ); case StorageType.SQLITE: - return `file://${path.join( - path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'), + return Configuration.buildPerformanceUriFilePath( `${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db` - )}`; + ); default: throw new Error(`Performance storage URI is mandatory with storage type '${storageType}'`); } } + + private static buildPerformanceUriFilePath(file: string) { + return `file://${path.join( + path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'), + file + )}`; + } } -- 2.34.1