Wire the media archive into the daemon: command, service, and API

This commit is contained in:
Fisto
2026-09-16 08:08:12 +02:00
parent 91782f0b80
commit 8b7b5b675d
13 changed files with 421 additions and 18 deletions
+25
View File
@@ -0,0 +1,25 @@
/*
* The puppet scrape backend: history pages over the validated core bridge.
*/
import type { FetchPage, ScrapeBackend } from "./engine.js";
import type { CoreMessage } from "./types.js";
/** The core `message.fetch` call the daemon injects. */
export type CoreFetch = (
channelId: string,
limit: number,
options?: { before?: string; after?: string }
) => Promise<{ messages?: unknown[] }>;
export class PuppetBackend implements ScrapeBackend {
readonly name = "puppet" as const;
constructor(private readonly fetchMessages: CoreFetch) {}
async fetchPage(channelId: string, before: string | null, limit: number): Promise<FetchPage> {
const result = await this.fetchMessages(channelId, limit, before ? { before } : {});
const messages = (result?.messages ?? []) as CoreMessage[];
return { messages };
}
}
+14
View File
@@ -9,6 +9,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { ScrapeEngine, type FetchPage, type ScrapeBackend } from "../src/engine.js";
import { extractMedia } from "../src/extract.js";
import { PuppetBackend } from "../src/puppet-backend.js";
import { dirSizeBytes, listScrapes, ScrapeStore } from "../src/store.js";
import type { CoreAttachment, CoreMessage } from "../src/types.js";
@@ -258,6 +259,19 @@ void (async () => {
assert.equal(meta?.pages, 1);
});
await test("puppet backend passes before and limit to the core", async () => {
const calls: Array<Record<string, unknown>> = [];
const backend = new PuppetBackend(async (channelId, limit, options) => {
calls.push({ channelId, limit, ...options });
return { messages: [message("50")] };
});
const page = await backend.fetchPage("123", "60", 5);
assert.equal(page.messages.length, 1);
assert.equal(page.messages[0].id, "50");
assert.deepEqual(calls[0], { channelId: "123", limit: 5, before: "60" });
});
rmSync(root, { recursive: true, force: true });
if (failures > 0) {