Add the media MCP tools and live-verified slopbot path

This commit is contained in:
Fisto
2026-09-16 09:54:22 +02:00
parent c81ae0d0fe
commit d483a2fa47
9 changed files with 179 additions and 17 deletions
+20 -2
View File
@@ -15,6 +15,7 @@ import {
scrapeDir,
resolveDbRoot,
type MediaKind,
type MediaRow,
type ScrapeBackend,
type ScrapeMeta
} from "../../media-scrape/src/index.js";
@@ -160,7 +161,7 @@ export class MediaService {
try {
const store = new ScrapeStore(dir);
try {
const sums = store.sumBytesByKind();
const sums = store.storedBytesByKind();
for (const kind of Object.keys(byKind) as MediaKind[]) byKind[kind] += sums[kind];
} finally {
store.close();
@@ -279,8 +280,24 @@ export class MediaService {
};
}
/** One media row inside a scrape, with its scrape and channel for context. */
getMediaItem(scrapeId: string, itemId: number): (MediaRow & { scrapeId: string; channelId: string }) | null {
const meta = this.engine.get(scrapeId);
if (!meta) return null;
const store = new ScrapeStore(scrapeDir(this.rootDir, scrapeId));
try {
const row = store.getMedia(itemId);
return row ? { ...row, scrapeId, channelId: meta.channelId } : null;
} finally {
store.close();
}
}
/** Read media rows across every scrape, newest scrape first. */
queryMedia(options: { kind?: MediaKind; limit?: number; offset?: number } = {}): MediaItemResult[] {
queryMedia(
options: { kind?: MediaKind; scrapeId?: string; limit?: number; offset?: number } = {}
): MediaItemResult[] {
const limit = Math.max(1, Math.min(options.limit ?? 60, 500));
const offset = Math.max(0, options.offset ?? 0);
const results: MediaItemResult[] = [];
@@ -288,6 +305,7 @@ export class MediaService {
for (const meta of this.engine.list()) {
if (meta.state === "deleted") continue;
if (options.scrapeId && meta.id !== options.scrapeId) continue;
const store = new ScrapeStore(scrapeDir(this.rootDir, meta.id));
try {