From 2a839d8305769c8e9136cec6c88b9d67577f71ac Mon Sep 17 00:00:00 2001 From: spark Date: Tue, 3 Nov 2026 18:31:04 +0000 Subject: [PATCH] fix(app): USB auto-pull keeps the open event when EXIF is missing (BIT-166) BIT-165 sent previews without DateTimeOriginal to Sem evento even after auto-pull had already matched the card clock to the event window. Keep the pin when there is no capture time; with EXIF, the window check still blocks leftover morning pins. --- apps/app/src/library/LocalFtp.test.tsx | 10 +++++----- apps/app/src/library/LocalFtp.tsx | 5 ++--- apps/app/src/library/UsbCamera.test.tsx | 5 ++--- apps/app/src/library/UsbCamera.tsx | 4 ++-- apps/app/src/offline/local.ts | 18 +++++++++--------- apps/app/src/offline/offline.test.ts | 9 ++++++--- 6 files changed, 26 insertions(+), 25 deletions(-) diff --git a/apps/app/src/library/LocalFtp.test.tsx b/apps/app/src/library/LocalFtp.test.tsx index 9b724cd..3ce2ea9 100644 --- a/apps/app/src/library/LocalFtp.test.tsx +++ b/apps/app/src/library/LocalFtp.test.tsx @@ -81,14 +81,14 @@ describe("local FTP feed", () => { // Each shows as soon as it arrives. The one the server has leaves; the failed one stays so it can be edited. await waitFor(() => expect(localPhotos.list().map((p) => p.name)).toEqual(["B.JPG"])); // Working locally (the default): previews go up, each with the fingerprint of its original. - // Stub previews have no EXIF DateTimeOriginal → no event invented from the open pin alone. + // Stub previews have no EXIF: the open pin still names the event (same as the server). expect(added).toEqual([ - { name: "A.JPG", eventId: undefined, size: "preview of /x/FTP/A.JPG".length, sha: "sha-/x/FTP/A.JPG" }, - { name: "B.JPG", eventId: undefined, size: "preview of /x/FTP/B.JPG".length, sha: "sha-/x/FTP/B.JPG" }, + { name: "A.JPG", eventId: "ev1", size: "preview of /x/FTP/A.JPG".length, sha: "sha-/x/FTP/A.JPG" }, + { name: "B.JPG", eventId: "ev1", size: "preview of /x/FTP/B.JPG".length, sha: "sha-/x/FTP/B.JPG" }, ]); await waitFor(() => expect(result.current.counts).toEqual({ received: 2, sent: 1, failed: 1 })); - // Only the one the server has moves out; without a known event (no EXIF) the work-folder name stays empty. - expect(shell.sent).toEqual([{ path: "/x/FTP/A.JPG", event: "", date: "" }]); + // Only the one the server has moves to the event's work folder; the failed one stays in ingest. + expect(shell.sent).toEqual([{ path: "/x/FTP/A.JPG", event: "ABC x Benfica", date: "2026-10-12" }]); for (const photo of localPhotos.list()) localPhotos.remove(photo.id); }); diff --git a/apps/app/src/library/LocalFtp.tsx b/apps/app/src/library/LocalFtp.tsx index d15d516..eb538e8 100644 --- a/apps/app/src/library/LocalFtp.tsx +++ b/apps/app/src/library/LocalFtp.tsx @@ -165,9 +165,8 @@ export function useLocalFtp(add: Add, enabled: boolean, invoke: Invoke = tauriIn const cached = orgId ? await cache.events(orgId) : null; const events = cached?.events ?? []; const capturedAt = lisbonInstant(exifDateTime(preview)); - // A pin on a game already put away, or left over from the previous match, does not take the next photos. - const pinnedId = to && (!cached || events.some((e) => e.id === to.id && !e.archivedAt)) ? to.id : null; - const eventId = eventForArrival(pinnedId, events, capturedAt); + // Open FTP target always; eventForArrival drops an archived leftover and keeps shots inside the window. + const eventId = eventForArrival(to?.id ?? null, events, capturedAt); const filed = events.find((e) => e.id === eventId); if (!localPhotos.bySha(info.sha256)) { let url = ""; diff --git a/apps/app/src/library/UsbCamera.test.tsx b/apps/app/src/library/UsbCamera.test.tsx index f8fa9ff..676f631 100644 --- a/apps/app/src/library/UsbCamera.test.tsx +++ b/apps/app/src/library/UsbCamera.test.tsx @@ -63,9 +63,8 @@ describe("usb tether", () => { } }; renderHook(() => useUsbCamera(add, true, { id: "ev1", title: "Portugal x Suíça", date: "2026-11-04" }, invoke)); - // Preview has no EXIF DateTimeOriginal: without a capture time the open pin must not invent an event - // (that mis-filed morning studio cards into the afternoon training). - await waitFor(() => expect(added).toEqual([{ name: "IMG_0001.JPG", eventId: undefined }])); + // Preview has no EXIF: keep the open pin (auto-pull already used the card clock for the window). + await waitFor(() => expect(added).toEqual([{ name: "IMG_0001.JPG", eventId: "ev1" }])); await waitFor(() => expect(sent).toEqual([{ path: "/ingest/.usb/IMG_0001.JPG", event: "Portugal x Suíça", date: "2026-11-04" }])); }); diff --git a/apps/app/src/library/UsbCamera.tsx b/apps/app/src/library/UsbCamera.tsx index 817c52b..39991f8 100644 --- a/apps/app/src/library/UsbCamera.tsx +++ b/apps/app/src/library/UsbCamera.tsx @@ -101,8 +101,8 @@ export function useUsbCamera(add: Add, enabled: boolean, target: FtpTarget | nul const cached = orgIdRef.current ? await cache.events(orgIdRef.current) : null; const events = cached?.events ?? []; const capturedAt = lisbonInstant(exifDateTime(bytes)); - const pinnedId = to && (!cached || events.some((e) => e.id === to.id && !e.archivedAt)) ? to.id : null; - const eventId = eventForArrival(pinnedId, events, capturedAt); + // Always the open USB target — never drop a live pull into Sem evento because the agenda cache is stale. + const eventId = eventForArrival(to?.id ?? null, events, capturedAt); const filed = events.find((e) => e.id === eventId); add([file], eventId ?? undefined, (_file, result) => { inFlight.current--; diff --git a/apps/app/src/offline/local.ts b/apps/app/src/offline/local.ts index d0f9292..797e237 100644 --- a/apps/app/src/offline/local.ts +++ b/apps/app/src/offline/local.ts @@ -95,20 +95,20 @@ export function routeLocally(events: RoutedEvent[], at: string | null): string | } /** - * Where a photo arrives on this computer. The pin (FTP target / open event) wins only while the capture sits - * inside that event's window — leftover pins from the morning studio must not swallow the afternoon training - * (or the other way around). No capture time → inbox; never invent "now" to keep the pin. + * Where a photo arrives on this computer. With a capture time, the pin (FTP target / open event) wins only + * inside that event's window — leftover pins from the morning studio must not swallow the afternoon training. + * Without a capture time, keep the pin (same as the server): USB auto-pull already filtered by the window via + * the card clock, and inventing "now" is what we must not do. */ export function eventForArrival(pinnedId: string | null, events: RoutedEvent[], at: string | null): string | null { - if (!at) return null; + if (!at) return pinnedId; if (!pinnedId) return routeLocally(events, at); - const pinned = events.find((e) => e.id === pinnedId && !e.archivedAt); + const pinned = events.find((e) => e.id === pinnedId); if (!pinned) { - // Agenda not loaded yet: keep the open pin so live FTP still lands somewhere; a stale id with a warm - // cache falls through to the clock instead. - if (!events.length) return pinnedId; - return routeLocally(events, at); + // Agenda cache miss: keep the open pin so USB/FTP does not dump live shots into Sem evento. + return pinnedId; } + if (pinned.archivedAt) return routeLocally(events, at); const t = Date.parse(at); if (Date.parse(pinned.ingestFrom) <= t && t <= Date.parse(pinned.ingestUntil)) return pinnedId; return routeLocally(events, at); diff --git a/apps/app/src/offline/offline.test.ts b/apps/app/src/offline/offline.test.ts index 9d7a0f0..f365433 100644 --- a/apps/app/src/offline/offline.test.ts +++ b/apps/app/src/offline/offline.test.ts @@ -123,9 +123,12 @@ describe("photos arriving on this computer", () => { // Yesterday's pin only holds photos taken inside it. The next morning goes to that morning's event. expect(eventForArrival("braga", events, at)).toBe("braga"); expect(eventForArrival("braga", events, "2026-10-10T15:30:00Z")).toBe("other"); - // No capture time: inbox — do not keep a leftover pin (that put morning studio shots into the afternoon training). - expect(eventForArrival("braga", events, null)).toBeNull(); - expect(eventForArrival("missing", events, "2026-10-10T15:30:00Z")).toBe("other"); + // No capture time: keep the pin (USB already filtered by the card clock; server keeps the named folder too). + expect(eventForArrival("braga", events, null)).toBe("braga"); + expect(eventForArrival(null, events, null)).toBeNull(); + // Cache miss for the pin id: keep it (do not dump into Sem evento); archived pins fall through to the clock. + expect(eventForArrival("missing", events, "2026-10-10T15:30:00Z")).toBe("missing"); + expect(eventForArrival("braga", [{ ...events[0]!, archivedAt: "2026-10-10T00:00:00Z" }, events[1]!], "2026-10-10T15:30:00Z")).toBe("other"); }); it("when two ingest windows overlap, files the photo in the event whose start is closest to the capture", () => { -- 2.47.3