mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
78c0f65de4
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.
53 lines
2.0 KiB
TypeScript
53 lines
2.0 KiB
TypeScript
/**
|
|
* captureHintFrom: the capture time and place a client read from a HEIC before
|
|
* converting it (#3120), held to the rules the backfill holds a file's own EXIF
|
|
* to. Anything that is not a real time or place is dropped, never refused.
|
|
*/
|
|
import { captureHintFrom } from '../../../src/nest/journey/journey-capture-hint';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const NOW = Date.UTC(2026, 10, 30, 12, 0, 0);
|
|
|
|
describe('captureHintFrom', () => {
|
|
it('CHINT-001: reads an ISO instant and a pair of coordinates', () => {
|
|
const fields = { taken_at: '2026-05-30T15:52:19+02:00', lat: '64.1466000', lng: '-21.9426000' };
|
|
expect(captureHintFrom(fields, NOW)).toEqual({
|
|
takenAt: '2026-05-30T13:52:19.000Z',
|
|
lat: 64.1466,
|
|
lng: -21.9426,
|
|
});
|
|
});
|
|
|
|
it('CHINT-002: no fields, or nothing usable in them, is no hint', () => {
|
|
expect(captureHintFrom(undefined, NOW)).toBeNull();
|
|
expect(captureHintFrom({}, NOW)).toBeNull();
|
|
expect(captureHintFrom({ taken_at: 'yesterday', lat: 'north', lng: '2' }, NOW)).toBeNull();
|
|
});
|
|
|
|
it('CHINT-003: a time before 1900 or more than a day ahead is dropped, the place kept', () => {
|
|
for (const taken_at of ['1899-12-31T23:59:59Z', '2026-12-02T12:00:00Z', '2026-02-30T10:00:00Z']) {
|
|
expect(captureHintFrom({ taken_at, lat: '48.8584', lng: '2.2945' }, NOW)).toEqual({
|
|
takenAt: null,
|
|
lat: 48.8584,
|
|
lng: 2.2945,
|
|
});
|
|
}
|
|
expect(captureHintFrom({ taken_at: '2026-12-01T11:00:00Z' }, NOW)?.takenAt).toBe('2026-12-01T11:00:00.000Z');
|
|
});
|
|
|
|
it('CHINT-004: half a pair, a pair outside the globe, 0,0 or an exponent is no place, the time kept', () => {
|
|
const taken_at = '2026-05-30T13:52:19.000Z';
|
|
for (const [lat, lng] of [
|
|
['48.8584', undefined],
|
|
['91', '2.2945'],
|
|
['48.8584', '-180.5'],
|
|
['0', '0'],
|
|
['1e-7', '2'],
|
|
[' 48.8', '2'],
|
|
] as Array<[string | undefined, string | undefined]>) {
|
|
expect(captureHintFrom({ taken_at, lat, lng }, NOW)).toEqual({ takenAt: taken_at, lat: null, lng: null });
|
|
}
|
|
});
|
|
});
|