fix(journey): keep an iPhone photo's capture time and place through the HEIC conversion

The browser converts a HEIC to a JPEG before it uploads it, and that
JPEG carries no EXIF, so iPhone photos arrived without their capture
time and GPS. A small lazily loaded reader now takes DateTimeOriginal
with its offset and the GPS pair from the HEIC's Exif item before the
conversion, and journey photo uploads (gallery, entry, Studio) send them
as optional taken_at, lat and lng fields.

The server reads those fields leniently (an ISO instant between 1900
and tomorrow, a pair inside the globe that is not 0,0) and hands them to
the capture backfill only when the request carried one file. They fill
in only what the file's own EXIF lacks and go through the existing
COALESCE write, so a stored value is never replaced. Covers and place
images keep the plain conversion and never carry a location.
This commit is contained in:
Maurice
2026-11-30 14:38:56 +01:00
parent 555027f10f
commit 78c0f65de4
23 changed files with 931 additions and 33 deletions
+65
View File
@@ -1358,5 +1358,70 @@ describe('Journey upload parity', () => {
const row = await captureOf(res.body.photos[0].file_path);
expect(row).toEqual({ taken_at: '2026-05-30T13:52:19.000Z', lat: null, lng: null });
});
it('JOURNEY-P13: a converted HEIC without EXIF keeps the capture the client read from it (#3120)', async () => {
const { user } = await makeUser(orm);
const journey = await makeJourney(orm, user.id);
const res = await request(app)
.post(`/api/journeys/${journey.id}/gallery/photos`)
.set('Cookie', authCookie(user.id))
.field('taken_at', '2026-05-30T13:52:19.000Z')
.field('lat', '64.1466000')
.field('lng', '-21.9426000')
.attach('photos', jpegWithExif({}), { filename: 'IMG_0042.jpg', contentType: 'image/jpeg' });
expect(res.status).toBe(201);
const row = await captureOf(res.body.photos[0].file_path);
expect(row.taken_at).toBe('2026-05-30T13:52:19.000Z');
expect(row.lat).toBeCloseTo(64.1466, 5);
expect(row.lng).toBeCloseTo(-21.9426, 5);
});
it("JOURNEY-P14: an entry photo's own EXIF time wins over the hint, which only adds the place it lacks", async () => {
const { user } = await makeUser(orm);
const journey = await makeJourney(orm, user.id);
const entry = await makeJourneyEntry(orm, journey.id, user.id, { entry_date: '2026-05-30' });
const res = await request(app)
.post(`/api/journeys/entries/${entry.id}/photos`)
.set('Cookie', authCookie(user.id))
.field('taken_at', '2020-01-01T00:00:00.000Z')
.field('lat', '64.1466000')
.field('lng', '-21.9426000')
.attach('photos', jpegWithExif({ DateTimeOriginal: '2026:05:30 15:52:19', OffsetTimeOriginal: '+02:00' }), {
filename: 'IMG_0043.jpg',
contentType: 'image/jpeg',
});
expect(res.status).toBe(201);
const row = await captureOf(res.body.photos[0].file_path);
expect(row.taken_at).toBe('2026-05-30T13:52:19.000Z');
expect(row.lat).toBeCloseTo(64.1466, 5);
expect(row.lng).toBeCloseTo(-21.9426, 5);
});
it('JOURNEY-P15: a hint that is no real time or place is dropped, and the upload still goes through', async () => {
const { user } = await makeUser(orm);
const journey = await makeJourney(orm, user.id);
const res = await request(app)
.post(`/api/journeys/${journey.id}/gallery/photos`)
.set('Cookie', authCookie(user.id))
.field('taken_at', 'yesterday')
.field('lat', '0')
.field('lng', '0')
.attach('photos', jpegWithExif({}), { filename: 'IMG_0044.jpg', contentType: 'image/jpeg' });
expect(res.status).toBe(201);
// The backfill runs detached; give it the time it took the cases above.
await new Promise((resolve) => setTimeout(resolve, 200));
const photo = await findRow(orm, TrekPhotos, { file_path: res.body.photos[0].file_path });
expect({ taken_at: photo?.taken_at ?? null, lat: photo?.lat ?? null, lng: photo?.lng ?? null }).toEqual({
taken_at: null,
lat: null,
lng: null,
});
});
});
});