From f95f5cd56e1d863728e11d9cdc80e1b090c0da80 Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Tue, 10 Jun 2025 14:04:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20Enhanced=20error=20handling?= =?UTF-8?q?=20and=20improved=20asynchronous=20processing=20in=20EditPinPop?= =?UTF-8?q?up=20component.=20Updated=20EXIF=20data=20retrieval=20and=20fil?= =?UTF-8?q?e=20name=20extraction=20logic.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edit-pin-popup.component.ts | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/app/components/edit-pin-popup/edit-pin-popup.component.ts b/src/app/components/edit-pin-popup/edit-pin-popup.component.ts index 5fb1bab..81ce824 100644 --- a/src/app/components/edit-pin-popup/edit-pin-popup.component.ts +++ b/src/app/components/edit-pin-popup/edit-pin-popup.component.ts @@ -172,7 +172,7 @@ export class EditPinPopupComponent implements OnInit, OnDestroy { if (files.length > 0) { try { const data = await this.exifService.getLocation(files[0]); - if (data.latitude !== undefined && data.longitude !== undefined) { + if (data && data.latitude !== undefined && data.longitude !== undefined) { this.autocompleteService.getAddressFromCoordinates(data.latitude, data.longitude).subscribe((address) => { if (address) { this.form.get('location')?.setValue(address.display_name); @@ -198,7 +198,7 @@ export class EditPinPopupComponent implements OnInit, OnDestroy { }); if (this.form.valid) { - const uploadObservables = this.files.map(async (file) => { + const uploadObservables = await Promise.all(this.files.map(async (file) => { if(file.size === 0) { if(file.name.includes("|")) { return of({id: file.name.split("|")[1]}); @@ -208,10 +208,10 @@ export class EditPinPopupComponent implements OnInit, OnDestroy { } } - const pictureExifDate = await this.exifService.getDateTime(file); + let fileDate = await this.exifService.getDateTime(file); - return this.imageService.postImage(file, pictureExifDate).pipe( - catchError(error => { + return this.imageService.postImage(file, fileDate).pipe( + catchError(async error => { this.uploadError = file.name + ' : ' + error.error.detail || 'Erreur lors de l\'upload de l\'image'; if (this.dragDropComponent) { this.dragDropComponent.errorMessage = this.uploadError; @@ -219,9 +219,9 @@ export class EditPinPopupComponent implements OnInit, OnDestroy { return of(null); }) ) - }); - - forkJoin(uploadObservables).subscribe((responses) => { + })); + + forkJoin(uploadObservables).subscribe(async (responses) => { // Vérifier si toutes les réponses sont valides if (responses.some(response => response === null)) { return; // Ne pas continuer si une erreur s'est produite @@ -295,12 +295,6 @@ export class EditPinPopupComponent implements OnInit, OnDestroy { } getFileNames(): string[] { - return this.files.map(file => { - if(typeof file === 'string') { - return file; - } else { - return file.name.split("|")[0]; - } - }); + return this.files.map((file) => file.name ? file.name.split("|")[0] : ''); } }