Compare commits

...
Author SHA1 Message Date
spark 5794660694 Stop an expired event pin from filing later shots into its folder.
When the pin is gone from the agenda and its ingest window has closed, arrivals follow the capture time instead of the old event.
2026-11-26 22:39:55 +00:00
spark 0a845f8bc6 Sign in to ZeroZero again when publish returns 403.
ci / rust (pull_request) Successful in 6m44s
ci / typescript (pull_request) Successful in 12m48s
A stale desk session answers Insufficient permissions instead of 401. One fresh login is tried before that refusal is accepted.
2026-11-26 22:20:55 +00:00
spark 56c115933c Do not fail a ZeroZero delivery when the account cannot publish.
ci / rust (pull_request) Successful in 4m10s
ci / typescript (pull_request) Successful in 11m13s
A photographer login may upload and still get 403 on photo-sync. The file is already on the desk, so that refusal is not a failed delivery.
2026-11-26 22:07:12 +00:00
7 changed files with 129 additions and 24 deletions

No files matched your search

+28 -10
View File
@@ -79,7 +79,25 @@ describe("zerozero publish", () => {
}),
);
await client.publish("12627743", "img-9");
expect(calls).toEqual(["/api/photo-sync/img-9", "/api/photo-sync/match/12627743"]);
expect(calls).toEqual(["/api/photo-sync/img-9", "/api/photo-sync/img-9", "/api/photo-sync/match/12627743"]);
});
it("signs in again when publish answers insufficient permissions", async () => {
const calls: string[] = [];
let refused = false;
const client = new ZerozeroClient(
{ username: "kapta", password: "zz-pass" },
desk((pathname) => {
calls.push(pathname);
if (!refused && pathname === "/api/photo-sync/img-9") {
refused = true;
return Response.json({ error: "Insufficient permissions" }, { status: 403 });
}
return Response.json({ synced: 1, failed: 0, failures: [] });
}),
);
await client.publish("12627743", "img-9");
expect(calls).toEqual(["/api/photo-sync/img-9", "/api/photo-sync/img-9"]);
});
it("publishes the whole game when the desk has no single-photo publish", async () => {
@@ -123,21 +141,21 @@ describe("zerozero publish", () => {
expect((err as TransportError).transient).toBe(true);
});
it("does not retry when neither publish route accepts the account", async () => {
it("keeps the upload when the account is not allowed to publish", async () => {
const calls: string[] = [];
const client = new ZerozeroClient(
{ username: "kapta", password: "zz-pass" },
desk((pathname) => {
calls.push(pathname);
return Response.json({ error: "forbidden" }, { status: 403 });
return Response.json({ error: "Insufficient permissions" }, { status: 403 });
}),
);
const err = await client.publish("12627743", "img-9").then(
() => null,
(error: unknown) => error,
);
expect(err).toBeInstanceOf(TransportError);
expect((err as TransportError).transient).toBe(false);
expect(calls).toEqual(["/api/photo-sync/img-9", "/api/photo-sync/match/12627743"]);
await client.publish("12627743", "img-9");
expect(calls).toEqual([
"/api/photo-sync/img-9",
"/api/photo-sync/img-9",
"/api/photo-sync/match/12627743",
"/api/photo-sync/match/12627743",
]);
});
});
+21 -1
View File
@@ -283,18 +283,38 @@ export class ZerozeroClient {
}
}
const match = await this.postApi(`/photo-sync/match/${encodeURIComponent(gameId)}`, PUBLISH_TIMEOUT_MS);
// A photographer account may upload but not publish ("Insufficient permissions"). The file is already on
// the desk; failing the delivery here only blocks the queue. The desk publishes those itself.
if (match.status === 403) return;
const ours = placeholder ? null : imageId;
this.assertPublished(match, ours);
}
private async postApi(path: string, timeoutMs: number, retry = true): Promise<{ status: number; body: unknown }> {
await this.login();
const { res } = await this.request(`${this.base}/api${path}`, { method: "POST" }, 10, timeoutMs);
// The desk's own client posts JSON. An empty object is what "send now" sends when it has no extra fields.
const { res } = await this.request(
`${this.base}/api${path}`,
{
method: "POST",
headers: { "content-type": "application/json", accept: "application/json" },
body: "{}",
},
10,
timeoutMs,
);
// 401: logged out. 403 "Insufficient permissions": the cookie is still sent, but the session is no longer
// the photographer. One fresh sign-in. The same refusal after that is the account, not a stale login.
if (res.status === 401 && retry) {
this.account = null;
this.jar.clear();
return this.postApi(path, timeoutMs, false);
}
if (res.status === 403 && retry) {
this.account = null;
this.jar.clear();
return this.postApi(path, timeoutMs, false);
}
const text = await res.text();
let body: unknown = null;
if (text) {
+12 -3
View File
@@ -3,7 +3,7 @@ import type { EventSummary } from "@photoreport/sdk";
import { useAuth } from "../auth.js";
import { planLocalAutopilot } from "../offline/autopilot.js";
import { cache } from "../offline/cache.js";
import { eventForArrival, exifDateTime, exifLens, lisbonInstant, localPhoto, localPhotos } from "../offline/local.js";
import { eventForArrival, exifDateTime, exifLens, lisbonDay, lisbonInstant, localPhoto, localPhotos } from "../offline/local.js";
import { localId, offlineQueue } from "../offline/queue.js";
import { useCallback, useEffect, useRef, useState } from "react";
import { t } from "../i18n.js";
@@ -89,6 +89,12 @@ type Add = (
export const eventLabel = (e: Pick<EventSummary, "title" | "home" | "away">) => e.title || [e.home, e.away].filter(Boolean).join(" x ");
/** The pin's own ingest window, when the agenda no longer lists that event. */
export function pinWindow(to: FtpTarget | null): { ingestFrom: string; ingestUntil: string } | null {
if (!to?.ingestFrom || !to.ingestUntil) return null;
return { ingestFrom: to.ingestFrom, ingestUntil: to.ingestUntil };
}
function savedTarget(): FtpTarget | null {
try {
const v = JSON.parse(prefs.get("ftp.target") ?? "null") as FtpTarget | null;
@@ -177,7 +183,7 @@ export function useLocalFtp(add: Add, enabled: boolean, invoke: Invoke = tauriIn
const events = cached?.events ?? [];
const capturedAt = lisbonInstant(exifDateTime(preview));
// Open FTP target always; eventForArrival drops an archived leftover and keeps shots inside the window.
const eventId = eventForArrival(to?.id ?? null, events, capturedAt);
const eventId = eventForArrival(to?.id ?? null, events, capturedAt, pinWindow(to));
const filed = events.find((e) => e.id === eventId);
if (!localPhotos.bySha(info.sha256)) {
let url = "";
@@ -239,9 +245,12 @@ export function useLocalFtp(add: Add, enabled: boolean, invoke: Invoke = tauriIn
sentEvent = eventLabel(filed);
sentDate = filed.startsAt.slice(0, 10);
} else if (to && eventId === to.id) {
// The pin is not in the cached list (no capture time, or this computer has not seen the event).
// The pin is not in the cached list and its window still covers this shot.
sentEvent = to.title;
sentDate = to.date;
} else if (capturedAt) {
// No event for this time: file under the shoot day (Desktop/2026/20261126), not the expired pin.
sentDate = lisbonDay(capturedAt);
}
invoke("ftp_sent", { path: f.path, event: sentEvent, date: sentDate })
.then(() => {
+16 -5
View File
@@ -2,10 +2,10 @@ import type { EventSummary } from "@photoreport/sdk";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { t } from "../i18n.js";
import { cache } from "../offline/cache.js";
import { eventForArrival, exifDateTime, lisbonInstant } from "../offline/local.js";
import { eventForArrival, exifDateTime, lisbonDay, lisbonInstant } from "../offline/local.js";
import { retryPhotoFile } from "../desktop/lightroomSidecar.js";
import { asArrayBuffer, prefs } from "../platform.js";
import { type FtpTarget, type IncomingFile, type Invoke, eventLabel } from "./LocalFtp.js";
import { type FtpTarget, type IncomingFile, type Invoke, eventLabel, pinWindow } from "./LocalFtp.js";
import type { PreviewOf, UploadStatus } from "./uploads.js";
/** What the desktop shell reports for a PTP body on the USB cable (`camera.rs`). */
@@ -103,16 +103,27 @@ export function useUsbCamera(add: Add, enabled: boolean, target: FtpTarget | nul
const events = cached?.events ?? [];
const capturedAt = lisbonInstant(exifDateTime(bytes));
// 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 eventId = eventForArrival(to?.id ?? null, events, capturedAt, pinWindow(to));
const filed = events.find((e) => e.id === eventId);
let sentEvent = "";
let sentDate = "";
if (filed) {
sentEvent = eventLabel(filed);
sentDate = filed.startsAt.slice(0, 10);
} else if (to && eventId === to.id) {
sentEvent = to.title;
sentDate = to.date;
} else if (capturedAt) {
sentDate = lisbonDay(capturedAt);
}
add([file], eventId ?? undefined, (_file, result) => {
inFlight.current--;
if (result === "done" || result === "duplicate") {
setCounts((c) => ({ ...c, sent: c.sent + 1 }));
invoke("ftp_sent", {
path: f.path,
event: filed ? eventLabel(filed) : (to?.title ?? ""),
date: filed ? filed.startsAt.slice(0, 10) : (to?.date ?? ""),
event: sentEvent,
date: sentDate,
})
.then(() => {
retryPhotoFile(original.sha256);
+29 -3
View File
@@ -102,6 +102,16 @@ function readTiff(v: DataView, start: number, end: number): { date: string | nul
};
}
/** Lisbon calendar day of an ISO instant, "YYYY-MM-DD" (the work-folder date). */
export function lisbonDay(iso: string): string {
return new Intl.DateTimeFormat("en-CA", {
timeZone: "Europe/Lisbon",
year: "numeric",
month: "2-digit",
day: "2-digit",
}).format(new Date(iso));
}
/** "2026:10:09 20:26:47" (Lisbon wall time, as the API reads it) to an ISO instant. */
export function lisbonInstant(exif: string | null): string | null {
const m = exif?.match(/^(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})/);
@@ -137,19 +147,35 @@ export function routeLocally(events: RoutedEvent[], at: string | null): string |
return bestEventForCapture(events, at)?.id ?? null;
}
function windowCovers(window: { ingestFrom: string; ingestUntil: string } | null | undefined, at: string): boolean {
if (!window) return true;
const t = Date.parse(at);
const from = Date.parse(window.ingestFrom);
const until = Date.parse(window.ingestUntil);
if (!Number.isFinite(t) || !Number.isFinite(from) || !Number.isFinite(until)) return true;
return from <= t && t <= until;
}
/**
* 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.
* A pin missing from the agenda is kept only while its own window still covers the shot. An expired pin
* (the event dropped off the list) must not keep filing the next day into that folder.
*/
export function eventForArrival(pinnedId: string | null, events: RoutedEvent[], at: string | null): string | null {
export function eventForArrival(
pinnedId: string | null,
events: RoutedEvent[],
at: string | null,
pinWindow?: { ingestFrom: string; ingestUntil: string } | null,
): string | null {
if (!at) return pinnedId;
if (!pinnedId) return routeLocally(events, at);
const pinned = events.find((e) => e.id === pinnedId);
if (!pinned) {
// Agenda cache miss: keep the open pin so USB/FTP does not dump live shots into Sem evento.
return pinnedId;
if (windowCovers(pinWindow, at)) return pinnedId;
return routeLocally(events, at);
}
if (pinned.archivedAt) return routeLocally(events, at);
const t = Date.parse(at);
+20 -1
View File
@@ -150,8 +150,27 @@ describe("photos arriving on this computer", () => {
// 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.
// Cache miss for the pin id: keep it while its window is unknown or still open.
expect(eventForArrival("missing", events, "2026-10-10T15:30:00Z")).toBe("missing");
expect(
eventForArrival("missing", events, "2026-10-09T19:26:47.000Z", {
ingestFrom: "2026-10-09T17:15:00Z",
ingestUntil: "2026-10-09T23:15:00Z",
}),
).toBe("missing");
// The pin left the agenda and its window has closed: file by the clock, not into that old folder.
expect(
eventForArrival("studio", events, "2026-11-26T20:20:00Z", {
ingestFrom: "2026-11-24T11:08:00.000Z",
ingestUntil: "2026-11-24T17:08:00.000Z",
}),
).toBeNull();
expect(
eventForArrival("studio", events, "2026-10-10T15:30:00Z", {
ingestFrom: "2026-10-09T17:15:00Z",
ingestUntil: "2026-10-09T23:15:00Z",
}),
).toBe("other");
expect(eventForArrival("braga", [{ ...events[0]!, archivedAt: "2026-10-10T00:00:00Z" }, events[1]!], "2026-10-10T15:30:00Z")).toBe("other");
});
+3 -1
View File
@@ -477,7 +477,9 @@ The same queue also delivers to SFTP, FTP/FTPS and Dropbox (`delivery/transports
author (`artist`: the photographer's name from the IPTC creator). The upload only reaches the photographer's
desk. The public game shows the photo after publish: `POST /api/photo-sync/<image id>`, or
`POST /api/photo-sync/match/<game>` when the desk has no single-image publish (the same call as
"Sincronizar com zerozero"). A delivery is done only after that call succeeds. The "folder" is the game:
"Sincronizar com zerozero"). A 403 signs in again once (a stale session uses that status, not 401). The same
refusal after the new login still counts as delivered: the file is on the desk. Any other publish failure fails
the delivery. The "folder" is the game:
chosen for the event by pasting the game's link (kept in `events.zerozero_game_id`), or found among the desk's
upcoming games by both teams and kick-off within 3 hours. The delivered item's remote path is `<game>/<image id>`
(`DELETE /api/images/<id>` takes it back).