searxng, icecast, photos: full nox modules (ADR 0044/0046)
searxng: a search tool — tools-only, a stateless search has nothing to observe. icecast: status tool, emits stream.started/.stopped by diffing live mountpoints. photos: status/albums/recent tools, emits item.added (immich-shaped API, coded defensively since the stub ships a placeholder image — flagged in the code). Typecheck; manifests parse.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// 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 0046/0047):
|
||||
// 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<string>();
|
||||
let primed = false;
|
||||
|
||||
async function pollRecent(): Promise<void> {
|
||||
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");
|
||||
Reference in New Issue
Block a user