Compare commits

...
Author SHA1 Message Date
spark 8fcf62f8be fix(app): never block the upload queue on local preview/cache (BIT-167)
ci / rust (pull_request) Successful in 4m22s
ci / typescript (pull_request) Successful in 8m43s
Shots sat on "queued" when IndexedDB event cache or EXIF preview stalled before enqueue. Push to the wire immediately with the open pin, enrich routing in the background, and clear a leftover offline pause when new files arrive.
2026-11-03 20:40:41 +00:00
spark 1ed6d144d3 fix(app): USB auto-pull keeps the open event when EXIF is missing (BIT-166) (#166)
ci / rust (push) Successful in 4m4s
ci / typescript (push) Successful in 8m2s
No EXIF on the preview kept the open pin so Sub-21 auto-pull no longer lands in Sem evento.
2026-11-03 18:47:30 +00:00
spark 2a839d8305 fix(app): USB auto-pull keeps the open event when EXIF is missing (BIT-166)
ci / rust (pull_request) Successful in 4m6s
ci / typescript (pull_request) Successful in 8m26s
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.
2026-11-03 18:31:04 +00:00
spark f20dea883e fix(ingest): route by capture time, not leftover open-event pin (BIT-165) (#165)
ci / rust (push) Successful in 3m56s
ci / typescript (push) Successful in 7m25s
Pin only wins inside its ingest window; overlapping windows pick closest startsAt; no capture keeps the named folder.
2026-11-03 17:20:53 +00:00
7 changed files with 75 additions and 48 deletions

No files matched your search

+5 -5
View File
@@ -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);
});
+2 -3
View File
@@ -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 = "";
+2 -3
View File
@@ -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" }]));
});
+2 -2
View File
@@ -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--;
+49 -23
View File
@@ -183,18 +183,19 @@ export function useUploadQueue(api: ApiClient, orgId: string) {
const next = queue.current.shift()!;
running.current++;
void (async () => {
const { item, file, eventId, original, sha256, onSettled } = next;
const { item, file, original, onSettled } = next;
let final: UploadStatus = "failed";
let filed: PhotoSummary | undefined;
let waiting = false;
update(item.id, { status: "uploading", error: undefined });
try {
let lastTick = 0;
// Read eventId/sha at send time so a late EXIF route on `next` still wins if it finished first.
const res = await sendResumable(
api,
orgId,
file,
eventId,
next.eventId,
(p) => {
const now = Date.now();
if (now - lastTick > 150 || p === 1) {
@@ -234,7 +235,7 @@ export function useUploadQueue(api: ApiClient, orgId: string) {
} finally {
if (!waiting) {
if (final === "done" || final === "duplicate") {
settleLocalUpload(orgId, sha256, filed);
settleLocalUpload(orgId, next.sha256, filed);
void offlineQueue(orgId).flush(api);
}
onSettled?.(final, filed);
@@ -250,6 +251,10 @@ export function useUploadQueue(api: ApiClient, orgId: string) {
const add = useCallback(
/** `onSettled` is called once per accepted file, after it is sent (or definitely failed). */
(files: Iterable<File>, eventId?: string, onSettled?: (file: File, status: UploadStatus, photo?: PhotoSummary) => void, original?: DesktopOrigin) => {
// A previous offline pause must not leave new shots stuck on "queued" after the VPN is back.
if (paused.current) {
paused.current = false;
}
const added: UploadItem[] = [];
for (const file of files) {
const item: UploadItem = { id: crypto.randomUUID(), name: file.name, size: file.size, status: "queued", progress: 0 };
@@ -259,29 +264,50 @@ export function useUploadQueue(api: ApiClient, orgId: string) {
continue;
}
added.push(item);
// Preview in the grid before the bytes leave this computer (USB, drop, FTP share this path).
// Event from EXIF + window (not the open folder alone), so a morning studio card does not land on the afternoon training.
// Preview / EXIF routing must not block the wire: a hung IndexedDB cache left the bar at "queued" forever.
// Enqueue at once with the open pin; enrich sha + routed event while the queue runs (or before the first byte).
const entry: {
item: UploadItem;
file: File;
eventId: string | undefined;
original?: DesktopOrigin;
sha256?: string | null;
onSettled?: (status: UploadStatus, photo?: PhotoSummary) => void;
} = {
item,
file,
eventId,
...(original && { original }),
sha256: null,
...(onSettled && { onSettled: (status: UploadStatus, photo?: PhotoSummary) => onSettled(file, status, photo) }),
};
queue.current.push(entry);
void (async () => {
const cached = orgId ? await cache.events(orgId) : null;
const shown = await showLocalJpeg({
file,
eventId,
origin: original,
orgId,
events: cached?.events,
});
queue.current.push({
item,
file,
eventId: shown?.eventId ?? eventId,
...(original && { original }),
sha256: shown?.sha256 ?? null,
...(onSettled && { onSettled: (status: UploadStatus, photo?: PhotoSummary) => onSettled(file, status, photo) }),
});
pump();
try {
const cached = orgId
? await Promise.race([
cache.events(orgId),
new Promise<null>((resolve) => setTimeout(() => resolve(null), 800)),
])
: null;
const shown = await showLocalJpeg({
file,
eventId,
origin: original,
orgId,
events: cached?.events,
});
if (!shown) return;
entry.sha256 = shown.sha256;
// Prefer EXIF routing when it names an event; otherwise keep the open pin already on the entry.
if (shown.eventId) entry.eventId = shown.eventId;
} catch {
/* preview optional — upload already queued */
}
})();
}
setItems((list) => [...list.filter((i) => i.status !== "done" && i.status !== "duplicate"), ...added]);
setItems((list) => list.filter((i) => i.status !== "done" && i.status !== "duplicate").concat(added));
pump();
},
[orgId, pump],
);
+9 -9
View File
@@ -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);
+6 -3
View File
@@ -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", () => {