Resolve thumbnail-less embeds, including Discord CDN unfurls

This commit is contained in:
Fisto
2026-09-17 09:07:07 +02:00
parent c6a16a63f7
commit a7db9cb200
5 changed files with 87 additions and 5 deletions
+62
View File
@@ -612,6 +612,68 @@ void (async () => {
assert.equal(calls.some(url => url.includes("youtube.com/watch")), false);
});
await test("pendingPreviews includes embeds without a stored thumbnail", () => {
const dir = join(root, "pending-embeds");
mkdirSync(dir, { recursive: true });
const store = new ScrapeStore(dir);
store.insertPage([
message("670", {
embeds: [
{
type: "video",
url: "https://cdn.discordapp.com/attachments/1/2/clip.mp4",
title: null,
provider: "cdn.discordapp.com",
videoUrl: "https://cdn.discordapp.com/attachments/1/2/clip.mp4",
imageUrl: null,
thumbnailUrl: null
}
]
})
]);
assert.equal(store.pendingPreviews(10, false).length, 0);
assert.equal(store.pendingPreviews(10, true).length, 1);
store.close();
});
await test("CDN attachment embeds resolve through the Discord proxy", async () => {
const resolved = await resolveEmbedPreview({
url: "https://cdn.discordapp.com/attachments/1/2/clip.mp4",
source: "embed",
preview_url: null
});
assert.ok(resolved);
const parsed = new URL(String(resolved));
assert.equal(parsed.hostname, "media.discordapp.net");
assert.equal(parsed.searchParams.get("width"), "320");
assert.equal(parsed.searchParams.get("format"), "webp");
});
await test("the og:image fallback never reads media bytes", async () => {
const seen: string[] = [];
const resolved = await resolveEmbedPreview(
{
url: "https://example.com/clip.mp4",
source: "embed",
preview_url: null
},
{
fetchImpl: async (input: any) => {
seen.push(String(input));
return new Response("binary", {
status: 200,
headers: { "content-type": "video/mp4" }
});
}
}
);
assert.equal(resolved, null);
assert.equal(seen.length, 1);
});
await test("engine caches previews in links mode, including embed thumbnails", async () => {
const backend = new FakeBackend([
{