mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 17:26:24 +00:00
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:
@@ -310,6 +310,32 @@ describe('journeyStore', () => {
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it('FE-STORE-JOURNEY-013c: a converted HEIC sends the capture it held beside the file, a plain JPEG nothing (#3120)', async () => {
|
||||
useJourneyStore.setState({ current: buildJourneyDetail({ id: 50, entries: [buildEntry({ id: 100, photos: [] })] }) });
|
||||
const entrySpy = vi.spyOn(journeyApi, 'uploadPhotos').mockResolvedValue({ photos: [] } as never);
|
||||
const gallerySpy = vi.spyOn(journeyApi, 'uploadGalleryPhotos').mockResolvedValue({ photos: [] } as never);
|
||||
const converted = Object.assign(new File(['x'], 'IMG_1.jpg', { type: 'image/jpeg' }), {
|
||||
capture: { takenAt: '2026-05-30T13:52:19.000Z', lat: 64.1466, lng: -21.9426 },
|
||||
});
|
||||
const plain = new File(['x'], 'p.jpg', { type: 'image/jpeg' });
|
||||
|
||||
await useJourneyStore.getState().uploadPhotos(100, [converted]);
|
||||
await useJourneyStore.getState().uploadGalleryPhotos(50, [converted, plain]);
|
||||
|
||||
const sent = [entrySpy.mock.calls[0][1], ...gallerySpy.mock.calls.map(call => call[1])] as FormData[];
|
||||
const nameOf = (fd: FormData) => (fd.get('photos') as File).name;
|
||||
for (const fd of sent.filter(fd => nameOf(fd) === 'IMG_1.jpg')) {
|
||||
expect(fd.get('taken_at')).toBe('2026-05-30T13:52:19.000Z');
|
||||
expect(fd.get('lat')).toBe('64.1466000');
|
||||
expect(fd.get('lng')).toBe('-21.9426000');
|
||||
}
|
||||
expect(sent.filter(fd => nameOf(fd) === 'IMG_1.jpg')).toHaveLength(2);
|
||||
const plainSent = sent.find(fd => nameOf(fd) === 'p.jpg');
|
||||
expect(plainSent && [...plainSent.keys()]).toEqual(['photos']);
|
||||
entrySpy.mockRestore();
|
||||
gallerySpy.mockRestore();
|
||||
});
|
||||
|
||||
/*
|
||||
* A picture uploaded onto an entry is a gallery row as well: the entry only
|
||||
* holds a link to it. Studio's content browser reads the gallery, so without
|
||||
|
||||
@@ -2,6 +2,7 @@ import { create } from 'zustand'
|
||||
import { journeyApi } from '../api/client'
|
||||
import type { ProviderPhotosAdded } from '../api/providerPhotoBatches'
|
||||
import { uploadFilesResilient, type ResilientResult, type UploadProgress } from '../utils/uploadQueue'
|
||||
import { captureFields } from '../utils/photoCapture'
|
||||
import { captureVideoPoster, isVideoFile } from '../utils/videoPoster'
|
||||
|
||||
export interface Journey {
|
||||
@@ -380,6 +381,8 @@ export const useJourneyStore = create<JourneyState>((set, get) => ({
|
||||
data = await journeyApi.uploadEntryVideo(entryId, fd, opts)
|
||||
} else {
|
||||
fd.append('photos', file)
|
||||
// A converted HEIC's capture time and place, which its JPEG lost (#3120).
|
||||
for (const [name, value] of captureFields(file)) fd.append(name, value)
|
||||
data = await journeyApi.uploadPhotos(entryId, fd, opts)
|
||||
}
|
||||
const photos: JourneyPhoto[] = data.photos || []
|
||||
@@ -418,6 +421,7 @@ export const useJourneyStore = create<JourneyState>((set, get) => ({
|
||||
data = await journeyApi.uploadGalleryVideo(journeyId, fd, opts)
|
||||
} else {
|
||||
fd.append('photos', file)
|
||||
for (const [name, value] of captureFields(file)) fd.append(name, value)
|
||||
data = await journeyApi.uploadGalleryPhotos(journeyId, fd, opts)
|
||||
}
|
||||
const photos: GalleryPhoto[] = data.photos || []
|
||||
|
||||
Reference in New Issue
Block a user