Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5794660694 | ||
|
|
0a845f8bc6 | ||
|
|
56c115933c | ||
|
|
63b021cec8 | ||
|
|
28f08bc5bc | ||
|
|
7f44cba460 |
No files matched your search
@@ -175,6 +175,7 @@ export class ZerozeroTransport implements Transport {
|
||||
const account = await this.client.login();
|
||||
const author = meta?.author?.trim() || account.name || "PhotoReport";
|
||||
const imageId = await this.client.upload(gameId, fileName, data, author);
|
||||
await this.client.publish(gameId, imageId);
|
||||
return `${gameId}/${imageId}`;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,45 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { TransportError } from "./transports.js";
|
||||
import { ZerozeroClient } from "./zerozero.js";
|
||||
|
||||
/**
|
||||
* A desk that is already willing to sign the client in, and answers photo-sync however the test says.
|
||||
* Login is the real OAuth dance; only the publish routes vary.
|
||||
*/
|
||||
function desk(publish: (pathname: string) => Response): typeof fetch {
|
||||
return async (input, init) => {
|
||||
const url = new URL(String(input));
|
||||
const method = init?.method ?? "GET";
|
||||
const cookie = new Headers(init?.headers).get("cookie") ?? "";
|
||||
const has = (name: string) => cookie.split(/;\s*/).some((part) => part.startsWith(`${name}=`));
|
||||
if (url.hostname === "www.zerozero.pt" && url.pathname === "/oauth.php") {
|
||||
if (has("zzuser")) {
|
||||
return new Response(null, {
|
||||
status: 302,
|
||||
headers: { location: "https://fotos.zerozero.pt/api/auth/callback?code=c&state=s" },
|
||||
});
|
||||
}
|
||||
return new Response("login", { status: 200, headers: { "set-cookie": "PHPSESSID=s; Domain=.zerozero.pt" } });
|
||||
}
|
||||
if (url.hostname === "www.zerozero.pt" && url.pathname === "/ax_login.php" && method === "POST") {
|
||||
return new Response(JSON.stringify({ status: true }), { headers: { "set-cookie": "zzuser=1; Domain=.zerozero.pt" } });
|
||||
}
|
||||
if (url.pathname === "/api/auth/login") {
|
||||
return Response.json({ authURL: "https://www.zerozero.pt/oauth.php?response_type=code&state=s" });
|
||||
}
|
||||
if (url.pathname === "/api/auth/callback") {
|
||||
return new Response(null, { status: 302, headers: { location: "https://fotos.zerozero.pt/", "set-cookie": "desk=ok; Path=/" } });
|
||||
}
|
||||
if (url.pathname === "/api/auth/me") {
|
||||
if (!has("desk")) return Response.json({ error: "unauthorized" }, { status: 401 });
|
||||
return Response.json({ role: "photographer", photographer_name: "Kapta+" });
|
||||
}
|
||||
if (url.pathname === "/") return new Response("desk", { status: 200 });
|
||||
if (method === "POST" && url.pathname.startsWith("/api/photo-sync/")) return publish(url.pathname);
|
||||
return new Response("no", { status: 404 });
|
||||
};
|
||||
}
|
||||
|
||||
describe("zerozero remove", () => {
|
||||
it("never asks the desk to delete a \"synced-\" placeholder (a real image is taken back: test/delivery.test.ts)", async () => {
|
||||
const calls: string[] = [];
|
||||
@@ -14,3 +53,109 @@ describe("zerozero remove", () => {
|
||||
expect(calls).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("zerozero publish", () => {
|
||||
it("publishes the one photo that was just uploaded", async () => {
|
||||
const calls: string[] = [];
|
||||
const client = new ZerozeroClient(
|
||||
{ username: "kapta", password: "zz-pass" },
|
||||
desk((pathname) => {
|
||||
calls.push(pathname);
|
||||
return Response.json({ synced: 1, failed: 0, failures: [] });
|
||||
}),
|
||||
);
|
||||
await client.publish("12627743", "img-9");
|
||||
expect(calls).toEqual(["/api/photo-sync/img-9"]);
|
||||
});
|
||||
|
||||
it("publishes the game when the account cannot publish one photo", async () => {
|
||||
const calls: string[] = [];
|
||||
const client = new ZerozeroClient(
|
||||
{ username: "kapta", password: "zz-pass" },
|
||||
desk((pathname) => {
|
||||
calls.push(pathname);
|
||||
if (pathname.startsWith("/api/photo-sync/match/")) return Response.json({ synced: 1, failed: 0, failures: [] });
|
||||
return Response.json({ error: "forbidden" }, { status: 403 });
|
||||
}),
|
||||
);
|
||||
await client.publish("12627743", "img-9");
|
||||
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 () => {
|
||||
const calls: string[] = [];
|
||||
const client = new ZerozeroClient(
|
||||
{ username: "kapta", password: "zz-pass" },
|
||||
desk((pathname) => {
|
||||
calls.push(pathname);
|
||||
if (pathname === "/api/photo-sync/match/12627743") return Response.json({ synced: 1, failed: 0, failures: [] });
|
||||
return new Response("missing", { status: 404 });
|
||||
}),
|
||||
);
|
||||
await client.publish("12627743", "img-9");
|
||||
expect(calls).toEqual(["/api/photo-sync/img-9", "/api/photo-sync/match/12627743"]);
|
||||
});
|
||||
|
||||
it("publishes the game when the desk already had the file and there is no image id", async () => {
|
||||
const calls: string[] = [];
|
||||
const client = new ZerozeroClient(
|
||||
{ username: "kapta", password: "zz-pass" },
|
||||
desk((pathname) => {
|
||||
calls.push(pathname);
|
||||
return Response.json({ synced: 0, failed: 0, failures: [] });
|
||||
}),
|
||||
);
|
||||
await client.publish("12627743", "synced-PS_jogo_1.jpg");
|
||||
expect(calls).toEqual(["/api/photo-sync/match/12627743"]);
|
||||
});
|
||||
|
||||
it("retries when the desk reports that this photo did not publish", async () => {
|
||||
const client = new ZerozeroClient(
|
||||
{ username: "kapta", password: "zz-pass" },
|
||||
desk(() => Response.json({ synced: 0, failed: 1, failures: [{ id: "img-9", error: "desk busy" }] })),
|
||||
);
|
||||
const err = await client.publish("12627743", "img-9").then(
|
||||
() => null,
|
||||
(error: unknown) => error,
|
||||
);
|
||||
expect(err).toBeInstanceOf(TransportError);
|
||||
expect((err as TransportError).message).toBe("zerozero publish: desk busy");
|
||||
expect((err as TransportError).transient).toBe(true);
|
||||
});
|
||||
|
||||
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: "Insufficient permissions" }, { status: 403 });
|
||||
}),
|
||||
);
|
||||
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",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -11,12 +11,16 @@ import { TransportError } from "./transports.js";
|
||||
* Lisbon time).
|
||||
* - Upload: tus 1.0 at `/api/upload?match_id=<id>`, metadata `match_id`, `artist` (the author shown with the photo)
|
||||
* and the file name. The image's id is the upload's id; `DELETE /api/images/<id>` takes it back.
|
||||
* - Publish: the upload only lands on the desk. The public game shows it after `POST /api/photo-sync/<image id>`
|
||||
* (the desk's "send now"). When that route is missing, `POST /api/photo-sync/match/<id>` publishes the game.
|
||||
*/
|
||||
|
||||
export const ZEROZERO_URL = "https://fotos.zerozero.pt";
|
||||
const LOGIN_SITE = "https://www.zerozero.pt";
|
||||
const CHUNK = 5 * 1024 * 1024;
|
||||
const TIMEOUT_MS = 60_000;
|
||||
/** Publishing pushes the file onwards to the public game, which is slower than one tus chunk. */
|
||||
const PUBLISH_TIMEOUT_MS = 180_000;
|
||||
|
||||
export interface ZerozeroGame {
|
||||
id: string;
|
||||
@@ -104,7 +108,7 @@ export class ZerozeroClient {
|
||||
) {}
|
||||
|
||||
/** One request with the jar's cookies; redirects followed by hand so every hop's cookies are kept. */
|
||||
private async request(url: string, init: RequestInit = {}, hops = 10): Promise<{ res: Response; url: string }> {
|
||||
private async request(url: string, init: RequestInit = {}, hops = 10, timeoutMs = TIMEOUT_MS): Promise<{ res: Response; url: string }> {
|
||||
let current = url;
|
||||
let options = init;
|
||||
for (let i = 0; i <= hops; i++) {
|
||||
@@ -114,7 +118,7 @@ export class ZerozeroClient {
|
||||
if (!headers.has("user-agent")) headers.set("user-agent", "PhotoReport/2 (delivery)");
|
||||
let res: Response;
|
||||
try {
|
||||
res = await this.fetchImpl(current, { ...options, headers, redirect: "manual", signal: AbortSignal.timeout(TIMEOUT_MS) });
|
||||
res = await this.fetchImpl(current, { ...options, headers, redirect: "manual", signal: AbortSignal.timeout(timeoutMs) });
|
||||
} catch (err) {
|
||||
throw new TransportError(`zerozero: ${fetchFailure(err)}`, true);
|
||||
}
|
||||
@@ -263,6 +267,78 @@ export class ZerozeroClient {
|
||||
return new URL(url).pathname.split("/").filter(Boolean).pop()!;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts an uploaded photo on the public game. The desk keeps it first (`sync_status` pending); without this call
|
||||
* it never leaves the photographer's page. One photo when the desk allows it, otherwise the whole game.
|
||||
* `synced-<file name>` is not an image id (the desk already had the file), so the game is published.
|
||||
*/
|
||||
async publish(gameId: string, imageId: string): Promise<void> {
|
||||
const placeholder = imageId.startsWith("synced-");
|
||||
if (!placeholder) {
|
||||
const one = await this.postApi(`/photo-sync/${encodeURIComponent(imageId)}`, PUBLISH_TIMEOUT_MS);
|
||||
// 404/405: this desk has no single-photo publish. 403: this account may still publish the game.
|
||||
if (one.status !== 404 && one.status !== 405 && one.status !== 403) {
|
||||
this.assertPublished(one, imageId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
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();
|
||||
// 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) {
|
||||
try {
|
||||
body = JSON.parse(text) as unknown;
|
||||
} catch {
|
||||
body = null;
|
||||
}
|
||||
}
|
||||
return { status: res.status, body };
|
||||
}
|
||||
|
||||
private assertPublished(result: { status: number; body: unknown }, imageId: string | null): void {
|
||||
if (result.status >= 200 && result.status < 300) {
|
||||
assertSyncBody(result.body, imageId);
|
||||
return;
|
||||
}
|
||||
const detail = errorText(result.body);
|
||||
const transient = result.status >= 500 || result.status === 429 || result.status === 404;
|
||||
let message = `zerozero publish: ${result.status}`;
|
||||
if (detail) message = `${message} ${detail}`;
|
||||
throw new TransportError(message, transient);
|
||||
}
|
||||
|
||||
/** Takes an uploaded image back. Already gone (or no longer this account's to remove) is not an error. */
|
||||
async remove(imageId: string): Promise<void> {
|
||||
// "synced-<file name>" (from `upload`, when the desk already had the file) is not a real image id: there was
|
||||
@@ -275,6 +351,31 @@ export class ZerozeroClient {
|
||||
}
|
||||
}
|
||||
|
||||
function errorText(body: unknown): string | null {
|
||||
if (!body || typeof body !== "object") return null;
|
||||
const error = (body as { error?: unknown }).error;
|
||||
if (typeof error !== "string" || !error) return null;
|
||||
return error.replace(/\s+/g, " ").slice(0, 180);
|
||||
}
|
||||
|
||||
function assertSyncBody(body: unknown, imageId: string | null): void {
|
||||
if (!body || typeof body !== "object") return;
|
||||
const record = body as { sync_status?: unknown; syncStatus?: unknown; failures?: unknown; error?: unknown };
|
||||
const status = record.sync_status ?? record.syncStatus;
|
||||
if (status === "failed") {
|
||||
const message = typeof record.error === "string" && record.error ? record.error : "the desk could not publish the photo";
|
||||
throw new TransportError(`zerozero publish: ${message}`, true);
|
||||
}
|
||||
if (!imageId || !Array.isArray(record.failures)) return;
|
||||
for (const failure of record.failures) {
|
||||
if (!failure || typeof failure !== "object") continue;
|
||||
const row = failure as { id?: unknown; error?: unknown };
|
||||
if (row.id !== imageId) continue;
|
||||
const message = typeof row.error === "string" && row.error ? row.error : "the desk could not publish the photo";
|
||||
throw new TransportError(`zerozero publish: ${message}`, true);
|
||||
}
|
||||
}
|
||||
|
||||
function toGame(r: Record<string, unknown> | null | undefined): ZerozeroGame | null {
|
||||
if (!r) return null;
|
||||
const s = (v: unknown) => (typeof v === "string" || typeof v === "number" ? String(v) : null);
|
||||
|
||||
@@ -75,6 +75,8 @@ class FakeNextcloud {
|
||||
class FakeZerozero {
|
||||
logins = 0;
|
||||
removed: string[] = [];
|
||||
/** Paths of POST /api/photo-sync/… after each upload (the public game, not only the desk). */
|
||||
syncs: string[] = [];
|
||||
uploads = new Map<string, { gameId: string; meta: Record<string, string>; data: Buffer; length: number }>();
|
||||
password = "zz-pass";
|
||||
|
||||
@@ -129,6 +131,10 @@ class FakeZerozero {
|
||||
this.uploads.set(id, { gameId: url.searchParams.get("match_id")!, meta, data: Buffer.alloc(0), length: Number(h.get("upload-length")) });
|
||||
return new Response(null, { status: 201, headers: { location: `/upload/${id}` } });
|
||||
}
|
||||
if (method === "POST" && url.pathname.startsWith("/api/photo-sync/")) {
|
||||
this.syncs.push(url.pathname);
|
||||
return Response.json({ synced: 1, failed: 0, failures: [] });
|
||||
}
|
||||
const gone = /^\/api\/images\/(.+)$/.exec(url.pathname);
|
||||
if (gone && method === "DELETE") {
|
||||
this.removed.push(gone[1]!);
|
||||
@@ -622,6 +628,8 @@ describe("delivery", () => {
|
||||
expect(first.meta).toMatchObject({ match_id: "12627747", artist: "Peter Spark / Kapta+", filename: "PS_SC Torreense x Sunderland_1.jpg", filetype: "image/jpeg" });
|
||||
expect(first.data.length).toBe(first.length);
|
||||
expect((await sharp(first.data).metadata()).width).toBe(3000);
|
||||
// The desk upload is not the public game: each photo is published there before the delivery is done.
|
||||
expect(zz.syncs).toEqual(["/api/photo-sync/img-1", "/api/photo-sync/img-2"]);
|
||||
// Signed in once for the whole batch.
|
||||
expect(zz.logins).toBe(1);
|
||||
|
||||
@@ -644,6 +652,7 @@ describe("delivery", () => {
|
||||
expect(zz.removed).toEqual([itemA.remotePath!.split("/")[1]]);
|
||||
// Same name ({n} kept), shown once in the game.
|
||||
expect(zz.uploads.get(resent.remotePath!.split("/")[1]!)!.meta.filename).toBe(zz.uploads.get(itemA.remotePath!.split("/")[1]!)!.meta.filename);
|
||||
expect(zz.syncs.at(-1)).toBe(`/api/photo-sync/${resent.remotePath!.split("/")[1]}`);
|
||||
expect(await delivery.queueEdited()).toBe(0);
|
||||
|
||||
// A reject that bypassed the library PATCH (flag flipped in the DB) is still taken back on the next sweep.
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
|
||||
|
||||
@@ -474,9 +474,14 @@ The same queue also delivers to SFTP, FTP/FTPS and Dropbox (`delivery/transports
|
||||
- **ZeroZero** (`fotos.zerozero.pt`, `delivery/zerozero.ts`): the photographer's zerozero.pt account. The server
|
||||
signs in through zerozero.pt's OAuth (`/api/auth/login` → `oauth.php` → `ax_login.php` → `/api/auth/callback`,
|
||||
cookies kept in a small jar), and uploads with tus to `/api/upload?match_id=<game>` with the file name and the
|
||||
author (`artist`: the photographer's name from the IPTC creator). 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>`
|
||||
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 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).
|
||||
|
||||
Each target also has Photo Mechanic's uploader output options: fit-in-box size, JPEG quality, output
|
||||
|
||||
Reference in new issue
Block a user