// photos' events. The tool runtime imports this once the broker is bound. It watches the library and // announces newly added assets. // // Emits (novox/hq ADR 0041/0042): // module.photos.item.added — a new asset appeared in the library // // New assets are found by diffing the recent-assets slice by asset id. Primed silently on the first // look, so a restart does not re-announce the whole recent list as freshly added. import { emit } from "@novox/mesh-sdk/events"; import { PhotosClient } from "./client.js"; const photos = PhotosClient.fromEnv(); const seen = new Set(); let primed = false; async function pollRecent(): Promise { const items = await photos.getRecentAssets(50); for (const asset of items) { if (!seen.has(asset.id)) { if (primed) { await emit("module.photos.item.added", { id: asset.id, fileName: asset.fileName, kind: asset.type, createdAt: asset.createdAt, }); } seen.add(asset.id); } } primed = true; } const run = (): void => void pollRecent().catch((err) => console.error(`[photos] ${err}`)); setInterval(run, 60_000); run(); console.log("[photos] watching for newly added assets");