save one image at once
MODIFY
src/integration/car/CarIntegration.ts
src/integration/car/CarIntegration.ts
@@ -26,8 +26,10 @@ export default abstract class CarIntegration {
externalCar.createdOn = new Date();
// Get image
externalCar.image = await this.getCarCatalogThumb(externalCar);
+ for (const imageURL of externalCar.imageURLs) {
// Get images
- externalCar.images = await this.getCarCatalogImages(externalCar);
+ // externalCar.images = await this.getCarCatalogImages(externalCar, imageURL);
+ }
// Create the Hash
externalCar.imagesHash = (externalCar.imageURLs.length > 0 && externalCar.imageURLs.length === externalCar.images.length && externalCar.image) ?
Cypher.hash(externalCar.imageURLs.toString()) : null;
@@ -35,7 +37,7 @@ export default abstract class CarIntegration {
externalCar.id = await CarStorage.saveCarCatalog(externalCar, true);
actionsDone.inSuccess++;
// Log
- Logging.logDebug({
+ await Logging.logDebug({
tenantID: Constants.DEFAULT_TENANT,
source: Constants.CENTRAL_SERVER,
action: ServerAction.SYNCHRONIZE_CAR_CATALOGS,
@@ -52,9 +54,15 @@ export default abstract class CarIntegration {
// Get image
externalCar.image = await this.getCarCatalogThumb(externalCar);
// Get images
- externalCar.images = await this.getCarCatalogImages(externalCar);
+ let i = 0;
+ for (const imageURL of externalCar.imageURLs) {
+ // Get images
+ const image = await this.getCarCatalogImages(externalCar, imageURL);
+ await CarStorage.saveCarImages(externalCar.id, [image]);
+ i++;
+ }
// Create the Hash
- externalCar.imagesHash = (externalCar.imageURLs.length > 0 && externalCar.imageURLs.length === externalCar.images.length && externalCar.image) ?
+ externalCar.imagesHash = (externalCar.imageURLs.length > 0 && externalCar.imageURLs.length === i && externalCar.image) ?
Cypher.hash(externalCar.imageURLs.toString()) : null;
// Save
await CarStorage.saveCarCatalog(externalCar, true);
@@ -66,7 +74,7 @@ export default abstract class CarIntegration {
}
actionsDone.inSuccess++;
// Log
- Logging.logDebug({
+ await Logging.logDebug({
tenantID: Constants.DEFAULT_TENANT,
source: Constants.CENTRAL_SERVER,
action: ServerAction.SYNCHRONIZE_CAR_CATALOGS,
@@ -76,7 +84,7 @@ export default abstract class CarIntegration {
}
} catch (error) {
actionsDone.inError++;
- Logging.logError({
+ await Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
source: Constants.CENTRAL_SERVER,
action: ServerAction.SYNCHRONIZE_CAR_CATALOGS,
@@ -87,7 +95,7 @@ export default abstract class CarIntegration {
}
}
// Log
- Logging.logActionsResponse(Constants.DEFAULT_TENANT, ServerAction.SYNCHRONIZE_CAR_CATALOGS,
+ await Logging.logActionsResponse(Constants.DEFAULT_TENANT, ServerAction.SYNCHRONIZE_CAR_CATALOGS,
MODULE_NAME, 'synchronizeCarCatalogs', actionsDone,
'{{inSuccess}} car(s) were successfully synchronized',
'{{inError}} car(s) failed to be synchronized',
@@ -101,5 +109,5 @@ export default abstract class CarIntegration {
public abstract getCarCatalogThumb(carCatalog: CarCatalog): Promise<string>;
- public abstract getCarCatalogImages(carCatalog: CarCatalog): Promise<string[]>;
+ public abstract getCarCatalogImages(carCatalog: CarCatalog, imageURL: string): Promise<string>;
}

MODIFY
src/integration/car/ev-database/EVDatabaseCarIntegration.ts
src/integration/car/ev-database/EVDatabaseCarIntegration.ts
@@ -22,7 +22,7 @@ export default class EVDatabaseCarIntegration extends CarIntegration {
public async getCarCatalogs(): Promise<CarCatalog[]> {
const evDatabaseConfig = Configuration.getEVDatabaseConfig();
if (!evDatabaseConfig) {
- Logging.logWarning({
+ await Logging.logWarning({
tenantID: Constants.DEFAULT_TENANT,
source: Constants.CENTRAL_SERVER,
message: 'No configuration is provided to access the EVDatabase system, skipping',
@@ -219,7 +219,7 @@ export default class EVDatabaseCarIntegration extends CarIntegration {
const base64Image = Buffer.from(response.data).toString('base64');
image = 'data:' + response.headers['content-type'] + ';base64,' + base64Image;
} catch (error) {
- Logging.logError({
+ await Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
source: Constants.CENTRAL_SERVER,
action: ServerAction.SYNCHRONIZE_CAR_CATALOGS,
@@ -232,17 +232,18 @@ export default class EVDatabaseCarIntegration extends CarIntegration {
return image;
}
- public async getCarCatalogImages(carCatalog: CarCatalog): Promise<string[]> {
+ public async getCarCatalogImages(carCatalog: CarCatalog, imageURL:string): Promise<string> {
const images: string[] = [];
// Retrieve all images
- for (const imageURL of carCatalog.imageURLs) {
+ // for (const imageURL of carCatalog.imageURLs) {
try {
const response = await this.axiosInstance.get(imageURL, { responseType: 'arraybuffer' });
const base64Image = Buffer.from(response.data).toString('base64');
const encodedImage = 'data:' + response.headers['content-type'] + ';base64,' + base64Image;
images.push(encodedImage);
+ return encodedImage;
} catch (error) {
- Logging.logError({
+ await Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
source: Constants.CENTRAL_SERVER,
action: ServerAction.SYNCHRONIZE_CAR_CATALOGS,
@@ -251,8 +252,8 @@ export default class EVDatabaseCarIntegration extends CarIntegration {
detailedMessages: { error: error.message, stack: error.stack }
});
}
- }
- return images;
+ // }
+ // return images;
}
private convertToThumbImage(image: string): string {

MODIFY
src/migration/tasks/ResetCarCatalogsHashTask.ts
src/migration/tasks/ResetCarCatalogsHashTask.ts
@@ -39,7 +39,7 @@ export default class ResetCarCatalogsHashTask extends MigrationTask {
}
getVersion(): string {
- return '1.0';
+ return '2.5';
}
isAsynchronous(): boolean {

save one image at once