Cache preview frames for Discord video attachments

This commit is contained in:
Fisto
2026-09-16 23:40:46 +02:00
parent 3da0da0ca7
commit caf9b7db3a
6 changed files with 34 additions and 13 deletions
+10 -2
View File
@@ -522,6 +522,10 @@ void (async () => {
"https://media.discordapp.net/attachments/1/2/pic.png?width=320&height=320&format=webp"
);
assert.equal(previewUrlFor({ url: "https://www.youtube.com/watch?v=x", kind: "video" }), null);
assert.equal(
previewUrlFor({ url: "https://cdn.discordapp.com/attachments/1/2/clip.mp4?ex=abc", kind: "video" }),
"https://media.discordapp.net/attachments/1/2/clip.mp4?ex=abc&width=320&height=320&format=webp"
);
assert.equal(
previewUrlFor({
url: "https://www.youtube.com/watch?v=x",
@@ -599,7 +603,10 @@ void (async () => {
{
messages: [
message("600", {
attachments: [attachment({ filename: "prev.png", contentType: "image/png" })],
attachments: [
attachment({ filename: "prev.png", contentType: "image/png" }),
attachment({ filename: "clip.mp4", contentType: "video/mp4" })
],
embeds: [
{
type: "video",
@@ -643,9 +650,10 @@ void (async () => {
const meta = engine.get(started.id);
assert.equal(meta?.state, "done");
assert.equal(meta?.previewed, 2);
assert.equal(meta?.previewed, 3);
assert.equal(fetched.some(url => url.includes("ytimg.com")), true);
assert.equal(fetched.some(url => url.includes("youtube.com/watch")), false);
assert.equal(fetched.some(url => url.includes("clip.mp4") && url.includes("format=webp")), true);
const store = new ScrapeStore(join(root, started.id));
const row = store.queryMedia({ kind: "image" })[0];