diff --git a/apps/app/src/library/UsbCamera.test.tsx b/apps/app/src/library/UsbCamera.test.tsx index fe07002..d2d11c9 100644 --- a/apps/app/src/library/UsbCamera.test.tsx +++ b/apps/app/src/library/UsbCamera.test.tsx @@ -2,6 +2,7 @@ import { render, renderHook, screen, waitFor } from "@testing-library/react"; import type { EventSummary } from "@photoreport/sdk"; import { describe, expect, it, vi } from "vitest"; import type { Invoke } from "./LocalFtp.js"; +import { prefs } from "../platform.js"; import type { UploadStatus } from "./uploads.js"; import { UsbCameraButton, type UsbStatus, inEventWindow, useUsbCamera, withSidecars } from "./UsbCamera.js"; @@ -86,6 +87,21 @@ describe("usb tether", () => { expect(withSidecars(["IMG_0002.JPG"], camera.files)).toEqual(["IMG_0002.JPG"]); }); + it("does not crash auto-ingest when the shell status omits files", async () => { + vi.spyOn(prefs, "get").mockReturnValue("1"); + const invoke = vi.fn(async (cmd: string) => { + if (cmd === "camera_status") return { supported: true, tether: true, devices: [] } as unknown as UsbStatus; + if (cmd === "camera_take") return []; + return null; + }) as unknown as Invoke; + const add = () => {}; + const { result } = renderHook(() => + useUsbCamera(add, true, { id: "ev1", title: "Portugal x Suíça", date: "2026-11-04", ingestFrom: "2026-11-04T18:00:00Z", ingestUntil: "2026-11-04T23:00:00Z" }, invoke), + ); + await waitFor(() => expect(result.current.status?.tether).toBe(true)); + vi.restoreAllMocks(); + }); + it("only treats shots inside the event ingest window as auto-eligible", () => { const from = "2026-11-03T18:00:00.000Z"; const until = "2026-11-03T23:00:00.000Z"; diff --git a/apps/app/src/library/UsbCamera.tsx b/apps/app/src/library/UsbCamera.tsx index 16e5c77..933b668 100644 --- a/apps/app/src/library/UsbCamera.tsx +++ b/apps/app/src/library/UsbCamera.tsx @@ -174,12 +174,13 @@ export function useUsbCamera(add: Add, enabled: boolean, target: FtpTarget | nul // New tethered shots inside the event window only — never the rest of the card / other days. useEffect(() => { if (!autoIngest || !status?.tether || !target?.ingestFrom || !target.ingestUntil) return; - const due = status.files.filter( + const files = status.files ?? []; + const due = files.filter( (f) => /\.jpe?g$/i.test(f.name) && f.isNew && !f.imported && inEventWindow(f, target.ingestFrom, target.ingestUntil) && !autoAsked.current.has(f.name), ); if (!due.length) return; for (const f of due) autoAsked.current.add(f.name); - void importFiles(withSidecars(due.map((f) => f.name), status.files)); + void importFiles(withSidecars(due.map((f) => f.name), files)); }, [autoIngest, status, target, importFiles]); return { status, outdated, counts, setTether, syncClock, importFiles, refresh, autoIngest, setAutoIngest };