fedimbed.bluesky: cleaner quote video handling, take media from recordWithMedia on quotes
This commit is contained in:
parent
839f20e7d3
commit
8884a60798
1 changed files with 29 additions and 4 deletions
|
@ -120,8 +120,9 @@ async function signedFetch(url, options) {
|
||||||
return await fetch(url, options);
|
return await fetch(url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function blueskyQuoteEmbed(quote, videos) {
|
async function blueskyQuoteEmbed(quote) {
|
||||||
const embeds = [];
|
const embeds = [];
|
||||||
|
const videos = [];
|
||||||
|
|
||||||
const mainEmbed = {
|
const mainEmbed = {
|
||||||
color: PLATFORM_COLORS.bluesky,
|
color: PLATFORM_COLORS.bluesky,
|
||||||
|
@ -158,6 +159,23 @@ async function blueskyQuoteEmbed(quote, videos) {
|
||||||
embeds.push({...mainEmbed, fields: [{name: "\u200b", value: `[Video Link](${videoUrl})`}]});
|
embeds.push({...mainEmbed, fields: [{name: "\u200b", value: `[Video Link](${videoUrl})`}]});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "app.bsky.embed.recordWithMedia#view": {
|
||||||
|
if (embed.media.$type === "app.bsky.embed.images#view") {
|
||||||
|
embeds.push(...embed.media.images.map((image) => ({...mainEmbed, image: {url: image.fullsize}})));
|
||||||
|
} else if (embed.media.$type === "app.bsky.embed.video#view") {
|
||||||
|
const videoUrl = `https://bsky.social/xrpc/com.atproto.sync.getBlob?did=${encodeURIComponent(
|
||||||
|
quote.author.did
|
||||||
|
)}&cid=${embed.media.cid}`;
|
||||||
|
const contentType = await fetch(videoUrl, {
|
||||||
|
method: "HEAD",
|
||||||
|
}).then((res) => res.headers.get("Content-Type"));
|
||||||
|
|
||||||
|
videos.push({url: videoUrl, desc: embed.alt, type: contentType});
|
||||||
|
|
||||||
|
embeds.push({...mainEmbed, fields: [{name: "\u200b", value: `[Video Link](${videoUrl})`}]});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
embeds.push(mainEmbed);
|
embeds.push(mainEmbed);
|
||||||
break;
|
break;
|
||||||
|
@ -167,7 +185,7 @@ async function blueskyQuoteEmbed(quote, videos) {
|
||||||
embeds.push(mainEmbed);
|
embeds.push(mainEmbed);
|
||||||
}
|
}
|
||||||
|
|
||||||
return embeds;
|
return {embeds, videos};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bluesky(msg, url, spoiler = false) {
|
async function bluesky(msg, url, spoiler = false) {
|
||||||
|
@ -249,7 +267,11 @@ async function bluesky(msg, url, spoiler = false) {
|
||||||
}
|
}
|
||||||
case "app.bsky.embed.record#view": {
|
case "app.bsky.embed.record#view": {
|
||||||
const quote = post.embed.record;
|
const quote = post.embed.record;
|
||||||
embeds.push(mainEmbed, ...(await blueskyQuoteEmbed(quote, videos)));
|
const quoteData = await blueskyQuoteEmbed(quote);
|
||||||
|
|
||||||
|
if (quoteData.videos.length > 0) videos.push(...quoteData.videos);
|
||||||
|
|
||||||
|
embeds.push(mainEmbed, ...quoteData.embeds);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "app.bsky.embed.recordWithMedia#view": {
|
case "app.bsky.embed.recordWithMedia#view": {
|
||||||
|
@ -268,7 +290,10 @@ async function bluesky(msg, url, spoiler = false) {
|
||||||
embeds.push({...mainEmbed, fields: [{name: "\u200b", value: `[Video Link](${videoUrl})`}]});
|
embeds.push({...mainEmbed, fields: [{name: "\u200b", value: `[Video Link](${videoUrl})`}]});
|
||||||
}
|
}
|
||||||
|
|
||||||
embeds.push(...(await blueskyQuoteEmbed(post.embed.record.record, videos)));
|
const quoteData = await blueskyQuoteEmbed(post.embed.record.record);
|
||||||
|
if (quoteData.videos.length > 0) videos.push(...quoteData.videos);
|
||||||
|
embeds.push(...quoteData.embeds);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue