Wire the media archive into the daemon: command, service, and API
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user