From: Jérôme Benoit Date: Tue, 5 Mar 2024 11:19:19 +0000 (+0100) Subject: fix: get diagnostics is trying to upload the incorrect folder X-Git-Tag: v1.3.0~54 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0ddd246049162ae6adcbf20265f072854a9d258f;p=e-mobility-charging-stations-simulator.git fix: get diagnostics is trying to upload the incorrect folder use log configuration section to build the archive content closes #1006 Contributed-by: @nahueld Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 83230fb8..6d60d402 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -1,7 +1,7 @@ // Partial Copyright Jerome Benoit. 2021-2024. All Rights Reserved. import { createWriteStream, readdirSync } from 'node:fs' -import { dirname, join, resolve } from 'node:path' +import { dirname, extname, join, resolve } from 'node:path' import { URL, fileURLToPath } from 'node:url' import type { ValidateFunction } from 'ajv' @@ -32,6 +32,7 @@ import { OCPPError } from '../../../exception/index.js' import { type ChangeConfigurationRequest, type ChangeConfigurationResponse, + ConfigurationSection, ErrorType, type GenericResponse, GenericStatus, @@ -41,6 +42,7 @@ import { type GetDiagnosticsResponse, type IncomingRequestHandler, type JsonType, + type LogConfiguration, OCPP16AuthorizationStatus, OCPP16AvailabilityType, type OCPP16BootNotificationRequest, @@ -98,6 +100,7 @@ import { type UnlockConnectorResponse } from '../../../types/index.js' import { + Configuration, Constants, convertToDate, convertToInt, @@ -1465,9 +1468,14 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { if (uri.protocol.startsWith('ftp:')) { let ftpClient: Client | undefined try { + const logConfiguration = Configuration.getConfigurationSection( + ConfigurationSection.log + ) const logFiles = readdirSync(resolve(dirname(fileURLToPath(import.meta.url)), '../')) - .filter(file => file.endsWith('.log')) - .map(file => join('./', file)) + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + .filter(file => file.endsWith(extname(logConfiguration.file!))) + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + .map(file => join(dirname(logConfiguration.file!), file)) const diagnosticsArchive = `${chargingStation.stationInfo?.chargingStationId}_logs.tar.gz` create({ gzip: true }, logFiles).pipe(createWriteStream(diagnosticsArchive)) ftpClient = new Client()