From 37f2224ad2dbe1618f85c069b11866e17249ac4f Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Fri, 18 Apr 2025 14:34:25 -0600 Subject: [PATCH] fedimbed.bluesky: description hates zero width strings bruh --- src/modules/fedimbed.js | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index 4073a7a..bc90416 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -370,7 +370,12 @@ async function blueskyQuoteEmbed(quote) { const embed = quote.embeds[0]; switch (embed.$type) { case "app.bsky.embed.images#view": { - images.push(...embed.images.map((image) => ({media: {url: image.fullsize}, description: image.alt}))); + images.push( + ...embed.images.map((image) => ({ + media: {url: image.fullsize}, + description: image.alt.length > 0 ? image.alt : null, + })) + ); break; } case "app.bsky.embed.video#view": { @@ -378,18 +383,23 @@ async function blueskyQuoteEmbed(quote) { const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint; const videoUrl = `${domain}/xrpc/com.atproto.sync.getBlob?did=${quote.author.did}&cid=${embed.cid}`; - videos.push({media: {url: videoUrl}, description: embed.alt}); + videos.push({media: {url: videoUrl}, description: embed.alt.length > 0 ? embed.alt : null}); break; } case "app.bsky.embed.recordWithMedia#view": { if (embed.media.$type === "app.bsky.embed.images#view") { - images.push(...embed.media.images.map((image) => ({media: {url: image.fullsize}, description: image.alt}))); + images.push( + ...embed.media.images.map((image) => ({ + media: {url: image.fullsize}, + description: image.alt.length > 0 ? image.alt : null, + })) + ); } else if (embed.media.$type === "app.bsky.embed.video#view") { const lookup = await fetch(`https://plc.directory/${quote.author.did}`).then((res) => res.json()); const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint; const videoUrl = `${domain}/xrpc/com.atproto.sync.getBlob?did=${quote.author.did}&cid=${embed.media.cid}`; - videos.push({media: {url: videoUrl}, description: embed.alt}); + videos.push({media: {url: videoUrl}, description: embed.alt.length > 0 ? embed.alt : null}); } break; } @@ -497,7 +507,12 @@ async function bluesky(msg, url, spoiler = false) { if (post.embed) { switch (post.embed.$type) { case "app.bsky.embed.images#view": { - images.push(post.embed.images.map((image) => ({media: {url: image.fullsize}, description: image.alt}))); + images.push( + post.embed.images.map((image) => ({ + media: {url: image.fullsize}, + description: image.alt.length > 0 ? image.alt : null, + })) + ); break; } case "app.bsky.embed.video#view": { @@ -505,7 +520,7 @@ async function bluesky(msg, url, spoiler = false) { const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint; const videoUrl = `${domain}/xrpc/com.atproto.sync.getBlob?did=${post.author.did}&cid=${post.embed.cid}`; - videos.push({media: {url: videoUrl}, description: post.embed.alt}); + videos.push({media: {url: videoUrl}, description: post.embed.alt.length > 0 ? post.embed.alt : null}); break; } case "app.bsky.embed.record#view": { @@ -524,13 +539,18 @@ async function bluesky(msg, url, spoiler = false) { hasQuote = true; if (post.embed.media.$type === "app.bsky.embed.images#view") { - images.push(post.embed.media.images.map((image) => ({media: {url: image.fullsize}, description: image.alt}))); + images.push( + post.embed.media.images.map((image) => ({ + media: {url: image.fullsize}, + description: image.alt.length > 0 ? image.alt : null, + })) + ); } else if (post.embed.media.$type === "app.bsky.embed.video#view") { const lookup = await fetch(`https://plc.directory/${post.author.did}`).then((res) => res.json()); const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint; const videoUrl = `${domain}/xrpc/com.atproto.sync.getBlob?did=${post.author.did}&cid=${post.embed.media.cid}`; - videos.push({media: {url: videoUrl}, description: post.embed.alt}); + videos.push({media: {url: videoUrl}, description: post.embed.alt.length > 0 ? post.embed.alt : null}); } else if (post.embed.media.$type === "app.bsky.embed.external#view") { if (post.embed.media.external.uri.includes("tenor.com")) { const url = new URL(post.embed.media.external.uri);