X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FAuthorizedTagsCache.ts;h=332b3a983a8b8760ef33668639ec09b3aaf24d9c;hb=b8cede3a125c147591da708b8b012254f98ecb07;hp=8c95660d07130155f495ec3d1fa7d017dbab1ca6;hpb=130783a74f495abcb198b7f01abe19dab4f7fb47;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/AuthorizedTagsCache.ts b/src/charging-station/AuthorizedTagsCache.ts index 8c95660d..332b3a98 100644 --- a/src/charging-station/AuthorizedTagsCache.ts +++ b/src/charging-station/AuthorizedTagsCache.ts @@ -1,11 +1,9 @@ import fs from 'node:fs'; -import { FileType } from '../types/FileType'; -import FileUtils from '../utils/FileUtils'; -import logger from '../utils/Logger'; -import Utils from '../utils/Utils'; +import { FileType } from '../types'; +import { FileUtils, Utils, logger } from '../utils'; -export default class AuthorizedTagsCache { +export class AuthorizedTagsCache { private static instance: AuthorizedTagsCache | null = null; private readonly tagsCaches: Map; private readonly FSWatchers: Map; @@ -30,12 +28,12 @@ export default class AuthorizedTagsCache { this.FSWatchers.set( file, FileUtils.watchJsonFile( - this.logPrefix(file), - FileType.Authorization, file, - null, + FileType.Authorization, + this.logPrefix(file), + undefined, (event, filename) => { - if (!Utils.isEmptyString(filename) && event === 'change') { + if (Utils.isNotEmptyString(filename) && event === 'change') { try { logger.debug( `${this.logPrefix(file)} ${FileType.Authorization} file have changed, reload` @@ -44,10 +42,10 @@ export default class AuthorizedTagsCache { this.deleteFSWatcher(file); } catch (error) { FileUtils.handleFileException( - this.logPrefix(file), - FileType.Authorization, file, + FileType.Authorization, error as NodeJS.ErrnoException, + this.logPrefix(file), { throwError: false, } @@ -94,10 +92,10 @@ export default class AuthorizedTagsCache { authorizedTags = JSON.parse(fs.readFileSync(file, 'utf8')) as string[]; } catch (error) { FileUtils.handleFileException( - this.logPrefix(file), - FileType.Authorization, file, - error as NodeJS.ErrnoException + FileType.Authorization, + error as NodeJS.ErrnoException, + this.logPrefix(file) ); } } else { @@ -106,7 +104,7 @@ export default class AuthorizedTagsCache { return authorizedTags; } - private logPrefix(file: string): string { + private logPrefix = (file: string): string => { return Utils.logPrefix(` Authorized tags cache for authorization file '${file}' |`); - } + }; }