fedimbed: components v2 testing with bluesky

This commit is contained in:
Cynthia Foxwell 2025-04-18 14:06:37 -06:00
parent c51a3be091
commit 4f0f9afbb7
Signed by: Cynosphere
SSH key fingerprint: SHA256:H3SM8ufP/uxqLwKSH7xY89TDnbR9uOHzjLoBr0tlajk

View file

@ -357,7 +357,7 @@ async function blueskyQuoteEmbed(quote) {
timestamp: quote.value.createdAt,
};
if (quote.author.handle.endsWith(".ap.brid.gy")) {
/*if (quote.author.handle.endsWith(".ap.brid.gy")) {
const handle = quote.author.handle.replace(".ap.brid.gy", "");
const split = handle.split(".");
@ -398,7 +398,7 @@ async function blueskyQuoteEmbed(quote) {
mainEmbed.color = color;
mainEmbed.thumbnail.url = authorData?.icon?.url ?? quote.author.avatar;
}
}
}*/
if (quote.value.facets?.length > 0) {
mainEmbed.description = processBlueskyFacets(mainEmbed.description, quote.value.facets);
@ -529,26 +529,82 @@ async function bluesky(msg, url, spoiler = false) {
}
}
const videos = [];
const embeds = [];
let sendWait = false;
const warnings = [];
if (hidden) {
warnings.push(":warning: Post marked as hidden");
}
if (adult) {
if (channelNsfw || !msg.guildID) {
warnings.push(`:warning: Post contains adult content: ${Array.from(new Set(tags)).join(", ")}`);
} else {
return {
response: {
content: "Not embedding post due to adult content in SFW channel",
},
};
}
}
const mainEmbed = {
color: PLATFORM_COLORS.bluesky,
url,
title: `${post.author.displayName} (@${post.author.handle})`,
description: post.record.text,
thumbnail: {
url: post.author.avatar,
},
footer: {
text: `${getStatsBluesky(post)}\nBluesky`,
icon_url: "https://bsky.app/static/apple-touch-icon.png",
},
timestamp: post.record.createdAt,
const videos = [];
const images = [];
//const embeds = [];
//let sendWait = false;
const warningText = {
type: 10,
content: `## ${warnings.join("\n## ")}`,
};
if (post.author.handle.endsWith(".ap.brid.gy")) {
const container = {
type: 17,
accent_color: PLATFORM_COLORS.bluesky,
components: [],
spoiler,
};
let context = "";
if (data.thread.parent) {
const reply = data.thread.parent.post;
context = `### <:i:1308640078825787412> Replying to: [${reply.author.displayName} (@${
reply.author.handle
})](https://bsky.app/profile/${reply.author.did}/post/${reply.uri.substring(reply.uri.lastIndexOf("/") + 1)})`;
}
const header = {
type: 9,
components: [
{
type: 10,
content:
`${context}\n## ${post.author.displayName}\n[@${post.author.handle}](https://bsky.app/profile/${post.author.did})`.trim(),
},
],
accessory: {
type: 11,
media: {
url: post.author.avatar,
},
},
};
container.components.push(header);
const postContent = {
type: 10,
content:
post.record.facets?.length ?? 0 > 0
? processBlueskyFacets(post.record.text, post.record.facets)
: post.record.text,
};
container.components.push(postContent);
const footer = {
type: 10,
content: `${getStatsBluesky(post)}\n-# Bluesky \u2022 <t:${Math.floor(
new Date(post.record.createdAt).getTime() / 1000
)}:F>`,
};
/*if (post.author.handle.endsWith(".ap.brid.gy")) {
const handle = post.author.handle.replace(".ap.brid.gy", "");
const split = handle.split(".");
@ -589,29 +645,12 @@ async function bluesky(msg, url, spoiler = false) {
mainEmbed.color = color;
mainEmbed.thumbnail.url = authorData?.icon?.url ?? post.author.avatar;
}
}
if (post.record.facets?.length > 0) {
mainEmbed.description = processBlueskyFacets(mainEmbed.description, post.record.facets);
}
if (data.thread.parent) {
const reply = data.thread.parent.post;
mainEmbed.author = {
name: `Replying to: ${reply.author.displayName} (@${reply.author.handle})`,
icon_url: "https://cdn.discordapp.com/emojis/1308640078825787412.png",
url: `https://bsky.app/profile/${reply.author.handle}/post/${reply.uri.substring(
reply.uri.lastIndexOf("/") + 1
)}`,
};
}
}*/
if (post.embed) {
switch (post.embed.$type) {
case "app.bsky.embed.images#view": {
embeds.push(
...post.embed.images.map((image) => ({...mainEmbed, image: {url: image.fullsize, description: image.alt}}))
);
images.push(post.embed.images.map((image) => ({media: {url: image.fullsize}, description: image.alt})));
break;
}
case "app.bsky.embed.video#view": {
@ -619,13 +658,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}`;
const contentType = await fetch(videoUrl, {
method: "HEAD",
}).then((res) => res.headers.get("Content-Type"));
videos.push({url: videoUrl, desc: post.embed.alt, type: contentType});
embeds.push({...mainEmbed, fields: [{name: "\u200b", value: `[Video Link](${videoUrl})`}]});
videos.push({media: {url: videoUrl}, description: post.embed.alt});
break;
}
case "app.bsky.embed.record#view": {
@ -635,7 +668,7 @@ async function bluesky(msg, url, spoiler = false) {
if (quoteData.videos.length > 0) videos.push(...quoteData.videos);
embeds.push(mainEmbed, ...quoteData.embeds);
//embeds.push(mainEmbed, ...quoteData.embeds);
if (quoteData.adult) adult = true;
if (quoteData.hidden) hidden = true;
@ -644,16 +677,11 @@ async function bluesky(msg, url, spoiler = false) {
break;
}
case "app.bsky.embed.recordWithMedia#view": {
/*case "app.bsky.embed.recordWithMedia#view": {
hasQuote = true;
if (post.embed.media.$type === "app.bsky.embed.images#view") {
embeds.push(
...post.embed.media.images.map((image) => ({
...mainEmbed,
image: {url: image.fullsize, description: image.alt},
}))
);
images.push(post.embed.media.images.map((image) => ({media:{url: image.fullsize}, description: image.alt})));
} 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;
@ -689,28 +717,20 @@ async function bluesky(msg, url, spoiler = false) {
if (quoteData.tags.length > 0) tags.push(...quoteData.tags);
break;
}
}*/
case "app.bsky.embed.external#view": {
if (post.embed.external.uri.includes("tenor.com")) {
const url = new URL(post.embed.external.uri);
url.searchParams.delete("hh");
url.searchParams.delete("ww");
embeds.push({...mainEmbed, image: {url: url.toString()}});
} else {
embeds.push(mainEmbed);
images.push({media: {url: url.toString()}});
}
break;
}
default: {
embeds.push(mainEmbed);
break;
}
}
} else {
embeds.push(mainEmbed);
}
if (videos.length > 0) {
/*if (videos.length > 0) {
sendWait = true;
if (msg instanceof Message) await msg.addReaction("\uD83D\uDCE4");
}
@ -748,31 +768,25 @@ async function bluesky(msg, url, spoiler = false) {
});
}
}
}
}*/
const warnings = [];
if (hidden) {
warnings.push(":warning: Post marked as hidden");
}
if (adult) {
if (channelNsfw || !msg.guildID) {
warnings.push(`:warning: Post contains adult content: ${Array.from(new Set(tags)).join(", ")}`);
} else {
return {
response: {
content: "Not embedding post due to adult content in SFW channel",
},
};
}
container.components.push({
type: 12,
items: images,
});
for (const video of videos) {
container.components.push({
type: 12,
items: [video],
});
}
container.components.push(footer);
if (quoteOnly && !hasQuote) return {};
return {
response: {
content: `${warnings.length > 0 ? warnings.join("\n") + "\n" : ""}${spoiler ? `|| ${url} ||` : ""}`,
embeds,
attachments: files,
components: [warnings.length > 0 ? warningText : false, container].filter((x) => !!x),
allowedMentions: {
repliedUser: false,
},
@ -780,7 +794,6 @@ async function bluesky(msg, url, spoiler = false) {
messageID: msg.id,
},
},
sendWait,
};
}