fedimbed.bluesky: fix videos from PDSes

This commit is contained in:
Cynthia Foxwell 2024-11-09 10:52:11 -07:00
parent 8884a60798
commit 8f732b49bf

View file

@ -147,9 +147,10 @@ async function blueskyQuoteEmbed(quote) {
break; break;
} }
case "app.bsky.embed.video#view": { case "app.bsky.embed.video#view": {
const videoUrl = `https://bsky.social/xrpc/com.atproto.sync.getBlob?did=${encodeURIComponent( const lookup = await fetch(`https://plc.directory/${quote.author.did}`).then((res) => res.json());
quote.author.did const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint;
)}&cid=${embed.cid}`; const videoUrl = `${domain}/xrpc/com.atproto.sync.getBlob?did=${quote.author.did}&cid=${embed.cid}`;
const contentType = await fetch(videoUrl, { const contentType = await fetch(videoUrl, {
method: "HEAD", method: "HEAD",
}).then((res) => res.headers.get("Content-Type")); }).then((res) => res.headers.get("Content-Type"));
@ -163,9 +164,10 @@ async function blueskyQuoteEmbed(quote) {
if (embed.media.$type === "app.bsky.embed.images#view") { if (embed.media.$type === "app.bsky.embed.images#view") {
embeds.push(...embed.media.images.map((image) => ({...mainEmbed, image: {url: image.fullsize}}))); embeds.push(...embed.media.images.map((image) => ({...mainEmbed, image: {url: image.fullsize}})));
} else if (embed.media.$type === "app.bsky.embed.video#view") { } else if (embed.media.$type === "app.bsky.embed.video#view") {
const videoUrl = `https://bsky.social/xrpc/com.atproto.sync.getBlob?did=${encodeURIComponent( const lookup = await fetch(`https://plc.directory/${quote.author.did}`).then((res) => res.json());
quote.author.did const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint;
)}&cid=${embed.media.cid}`; const videoUrl = `${domain}/xrpc/com.atproto.sync.getBlob?did=${quote.author.did}&cid=${embed.cid}`;
const contentType = await fetch(videoUrl, { const contentType = await fetch(videoUrl, {
method: "HEAD", method: "HEAD",
}).then((res) => res.headers.get("Content-Type")); }).then((res) => res.headers.get("Content-Type"));
@ -253,9 +255,10 @@ async function bluesky(msg, url, spoiler = false) {
break; break;
} }
case "app.bsky.embed.video#view": { case "app.bsky.embed.video#view": {
const videoUrl = `https://bsky.social/xrpc/com.atproto.sync.getBlob?did=${encodeURIComponent( const lookup = await fetch(`https://plc.directory/${post.author.did}`).then((res) => res.json());
post.author.did const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint;
)}&cid=${post.embed.cid}`; const videoUrl = `${domain}/xrpc/com.atproto.sync.getBlob?did=${post.author.did}&cid=${post.embed.cid}`;
const contentType = await fetch(videoUrl, { const contentType = await fetch(videoUrl, {
method: "HEAD", method: "HEAD",
}).then((res) => res.headers.get("Content-Type")); }).then((res) => res.headers.get("Content-Type"));
@ -278,9 +281,10 @@ async function bluesky(msg, url, spoiler = false) {
if (post.embed.media.$type === "app.bsky.embed.images#view") { if (post.embed.media.$type === "app.bsky.embed.images#view") {
embeds.push(...post.embed.media.images.map((image) => ({...mainEmbed, image: {url: image.fullsize}}))); embeds.push(...post.embed.media.images.map((image) => ({...mainEmbed, image: {url: image.fullsize}})));
} else if (post.embed.media.$type === "app.bsky.embed.video#view") { } else if (post.embed.media.$type === "app.bsky.embed.video#view") {
const videoUrl = `https://bsky.social/xrpc/com.atproto.sync.getBlob?did=${encodeURIComponent( const lookup = await fetch(`https://plc.directory/${post.author.did}`).then((res) => res.json());
post.author.did const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint;
)}&cid=${post.embed.media.cid}`; const videoUrl = `${domain}/xrpc/com.atproto.sync.getBlob?did=${post.author.did}&cid=${post.embed.cid}`;
const contentType = await fetch(videoUrl, { const contentType = await fetch(videoUrl, {
method: "HEAD", method: "HEAD",
}).then((res) => res.headers.get("Content-Type")); }).then((res) => res.headers.get("Content-Type"));