Refactored firmware download route
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
}
}
},
- "/api/chargingstations/firmware/{id}": {
+ "/api/chargingstations/firmware/download": {
"get": {
"security": [
{
"description": "Get Charging Station firmware",
"parameters": [
{
- "in": "path",
- "name": "id",
+ "in": "query",
+ "name": "FileName",
"description": "Firmware ID",
"required": true,
"schema": {

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -968,7 +968,7 @@ export default class ChargingStationService {
public static async handleGetFirmware(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
const filteredRequest = ChargingStationSecurity.filterChargingStationGetFirmwareRequest(req.query);
- if (!filteredRequest.ID) {
+ if (!filteredRequest.FileName) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
@@ -978,10 +978,10 @@ export default class ChargingStationService {
});
}
// Open a download stream and pipe it in the response
- const bucketStream = ChargingStationStorage.getChargingStationFirmware(filteredRequest.ID);
+ const bucketStream = ChargingStationStorage.getChargingStationFirmware(filteredRequest.FileName);
// Set headers
res.setHeader('Content-Type', 'application/octet-stream');
- res.setHeader('Content-Disposition', 'attachment; filename=' + filteredRequest.ID);
+ res.setHeader('Content-Disposition', 'attachment; filename=' + filteredRequest.FileName);
// Write chunks
bucketStream.on('data', (chunk) => {
res.write(chunk);
@@ -991,7 +991,7 @@ export default class ChargingStationService {
Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
action: action,
- message: `Firmware '${filteredRequest.ID}' has not been found!`,
+ message: `Firmware '${filteredRequest.FileName}' has not been found!`,
module: MODULE_NAME, method: 'handleGetFirmware',
detailedMessages: { error: error.message, stack: error.stack },
});
@@ -1002,7 +1002,7 @@ export default class ChargingStationService {
Logging.logInfo({
tenantID: Constants.DEFAULT_TENANT,
action: action,
- message: `Firmware '${filteredRequest.ID}' has been downloaded with success`,
+ message: `Firmware '${filteredRequest.FileName}' has been downloaded with success`,
module: MODULE_NAME, method: 'handleGetFirmware',
});
res.end();

MODIFY
src/server/rest/v1/service/security/ChargingStationSecurity.ts
src/server/rest/v1/service/security/ChargingStationSecurity.ts
@@ -281,7 +281,7 @@ export default class ChargingStationSecurity {
public static filterChargingStationGetFirmwareRequest(request: any): HttpChargingStationGetFirmwareRequest {
return {
- ID: sanitize(request.ID),
+ FileName: sanitize(request.FileName),
};
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -417,7 +417,7 @@ export enum ServerRoute {
REST_CHARGING_STATIONS_FIRMWARE_UPDATE = 'chargingstations/firmware/update',
REST_CHARGING_STATIONS_CHANGE_AVAILABILITY = 'chargingstations/availability/change',
- REST_CHARGING_STATIONS_DOWNLOAD_FIRMWARE = 'chargingstations/firmware/:id',
+ REST_CHARGING_STATIONS_DOWNLOAD_FIRMWARE = 'chargingstations/firmware/download',
REST_CHARGING_STATIONS_QRCODE_GENERATE = 'chargingstations/:id/connectors/:connectorId/qrcode/generate',
REST_CHARGING_STATIONS_QRCODE_DOWNLOAD = 'chargingstations/:id/connectors/:connectorId/qrcode/download',

MODIFY
src/types/requests/HttpChargingStationRequest.ts
src/types/requests/HttpChargingStationRequest.ts
@@ -102,5 +102,5 @@ export interface HttpIsAuthorizedRequest {
}
export interface HttpChargingStationGetFirmwareRequest {
- ID: string;
+ FileName: string;
}

Refactored firmware download route