Resume paused scrapes from their cursor

This commit is contained in:
Fisto
2026-09-17 00:14:57 +02:00
parent 089bca0d4f
commit 0664b54241
10 changed files with 110 additions and 0 deletions
+9
View File
@@ -836,6 +836,15 @@ function buildServer(): McpServer {
async ({ scrapeId }) => jsonText(media.getScrape(scrapeId))
);
server.registerTool(
"resume_media_scrape",
{
description: "Continue a paused media scrape from its cursor.",
inputSchema: { scrapeId: z.string().describe("Scrape ID") }
},
async ({ scrapeId }) => jsonText(await media.resumeScrape(scrapeId))
);
server.registerTool(
"stop_media_scrape",
{
+22
View File
@@ -384,6 +384,28 @@ export class MediaService {
this.engine.stop(id);
}
/** Continue a paused scrape from its cursor with the same backend family. */
async resumeScrape(scrapeId: string): Promise<ScrapeMeta | null> {
const meta = this.engine.get(scrapeId);
if (!meta) return null;
let backend: ScrapeBackend;
if (meta.backend === "slopbot" && meta.guildId) {
const available = await this.ensureSlopbot();
const inGuild = this.bot?.guilds.cache.has(meta.guildId) ?? false;
const fetcher = this.botFetcher;
if (!available || !inGuild || !fetcher) {
throw new Error("slopbot is not connected to that guild");
}
backend = new SlopbotBackend(fetcher);
} else {
backend = this.puppetBackend();
}
this.deps.log?.(`resuming scrape ${scrapeId} from cursor ${meta.cursor ?? "start"}`);
return this.engine.resume(scrapeId, backend);
}
listScrapes(): ScrapeMeta[] {
return this.engine.list();
}
+12
View File
@@ -980,6 +980,18 @@ export function startWebUi(deps: WebUiDeps): WebUiHandle {
})
);
app.post(
"/api/media/scrape/resume",
wrap(async (req, res) => {
const id = String(req.body?.id ?? "");
if (!id) throw new HttpError(400, "id is required");
const scrape = await deps.media.resumeScrape(id);
deps.getPuppet()?.appendAction({ type: "media", action: "resume", scrapeId: id });
res.json({ ok: true, result: scrape });
})
);
app.post(
"/api/media/scrape/stop",
wrap(async (req, res) => {