From 261c7033a1008b1b7ae59c6cde0bcedc6322194d Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Sat, 7 Jun 2025 11:27:22 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Updated=20the=20EXIF=20=E2=80=8B?= =?UTF-8?q?=E2=80=8Bservice=20to=20simplify=20EXIF=20=E2=80=8B=E2=80=8Bdat?= =?UTF-8?q?a=20handling.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/services/exif/exif.service.ts | 56 +++------------------------ 1 file changed, 6 insertions(+), 50 deletions(-) diff --git a/src/app/services/exif/exif.service.ts b/src/app/services/exif/exif.service.ts index 6f87745..7629ee7 100644 --- a/src/app/services/exif/exif.service.ts +++ b/src/app/services/exif/exif.service.ts @@ -5,35 +5,10 @@ import * as exifr from 'exifr'; providedIn: 'root', }) export class ExifService { - private getExifData(file: File): Promise { - return exifr.parse(file); - } - - async getAllExifData(file: File): Promise { - try { - return await this.getExifData(file); - } catch (error) { - console.error('Error reading EXIF data:', error); - return; - } - } - async getOrientation(file: File): Promise { try { - const exifData = await this.getExifData(file); - return exifData.Orientation; + return await exifr.orientation(file); } catch (error) { - console.error('Error reading EXIF data:', error); - return undefined; - } - } - - async getDeviceModel(file: File): Promise { - try { - const exifData = await this.getExifData(file); - return exifData.Model; - } catch (error) { - console.error('Error reading EXIF data:', error); return undefined; } } @@ -42,37 +17,18 @@ export class ExifService { file: File ): Promise<{ latitude?: number; longitude?: number }> { try { - const exifData = await this.getExifData(file); - return { - latitude: exifData.GPSLatitude - ? this.convertToDecimal(exifData.GPSLatitude, exifData.GPSLatitudeRef) - : undefined, - longitude: exifData.GPSLongitude - ? this.convertToDecimal( - exifData.GPSLongitude, - exifData.GPSLongitudeRef - ) - : undefined, - }; + return exifr.gps(file); } catch (error) { - console.error('Error reading EXIF data:', error); return {}; } } - async getDateTime(file: File): Promise { + async getDateTime(file: File): Promise { try { - const exifData = await this.getExifData(file); - return exifData.DateTime; + const data = await exifr.parse(file); + return data.DateTimeOriginal.toISOString(); } catch (error) { - console.error('Error reading EXIF data:', error); - return false; + return ''; } } - - private convertToDecimal(coordinate: number[], direction: string): number { - if (!coordinate || coordinate.length !== 3) return NaN; - const decimal = coordinate[0] + coordinate[1] / 60 + coordinate[2] / 3600; - return direction === 'S' || direction === 'W' ? -decimal : decimal; - } }