Add custom download destinations, confirmations, and the bot error feed

This commit is contained in:
Fisto
2026-09-16 11:53:59 +02:00
parent 973b9cff92
commit 42fd52b96b
14 changed files with 471 additions and 62 deletions
+73
View File
@@ -637,6 +637,79 @@ void (async () => {
assert.equal(existsSync(join(root, started.id, "thumbs", `${row.preview_hash}.webp`)), true);
});
await test("custom download destination keeps files off-archive and copies embed previews", async () => {
const dest = join(root, "custom-dest");
mkdirSync(dest, { recursive: true });
const backend = new FakeBackend([
{
messages: [
message("702", {
attachments: [attachment({ filename: "offsite.png", contentType: "image/png" })],
embeds: [
{
type: "video",
url: "https://www.youtube.com/watch?v=x",
title: null,
provider: "YouTube",
videoUrl: "https://www.youtube.com/embed/x",
imageUrl: null,
thumbnailUrl: "https://i.ytimg.com/vi/x/hqdefault.jpg"
}
]
})
]
}
]);
const engine = new ScrapeEngine({
rootDir: root,
pageSize: 2,
pageMinMs: 0,
pageMaxMs: 0,
sleep: async () => {},
random: () => 0,
log: () => {},
previews: true,
download: {
fetchImpl: async () =>
new Response("bytes", { status: 200, headers: { "content-type": "image/png" } }),
minGapMs: 0,
maxGapMs: 0,
sleep: async () => {}
}
});
const started = await engine.start({
channelId: "130",
guildId: null,
mode: "download",
backend,
downloadDir: dest
});
await engine.processQueue();
const meta = engine.get(started.id);
assert.equal(meta?.downloadDir, dest);
assert.equal(meta?.downloaded, 1);
const store = new ScrapeStore(join(root, started.id));
const file = store.queryMedia({ kind: "image" })[0];
const filePath = file.file_path;
assert.ok(filePath && filePath.startsWith(dest));
assert.equal(existsSync(filePath), true);
assert.equal(existsSync(join(root, started.id, "media", filePath.split("/").pop() ?? "")), false);
const embed = store.queryMedia({ kind: "video" })[0];
assert.ok(embed.preview_hash);
assert.equal(
existsSync(join(dest, started.id, "thumbnails", `${embed.preview_hash}.webp`)),
true
);
assert.equal(existsSync(join(root, started.id, "thumbs", `${embed.preview_hash}.webp`)), true);
store.close();
});
await test("retention marks the oldest completed scrapes up to the limit", () => {
const scrapes = [
{ id: "old", state: "done", createdAt: "2026-09-01T00:00:00.000Z", bytes: 600 },