fedimbed: limmy support

This commit is contained in:
Cynthia Foxwell 2023-09-22 20:50:19 -06:00
parent 690a8f8765
commit a0c037b6e9
1 changed files with 48 additions and 20 deletions

View File

@ -23,6 +23,7 @@ const PATH_REGEX = {
pleroma2: /^\/notice\/[A-Za-z0-9]+\/?/,
misskey: /^\/notes\/[a-z0-9]+\/?/,
gotosocial: /^\/@(.+?)\/statuses\/[0-9A-Z]+\/?/,
lemmy: /^\/post\/\d+\/?/,
};
const PLATFORM_COLORS = {
@ -33,6 +34,7 @@ const PLATFORM_COLORS = {
calckey: 0x31748f,
firefish: 0xf07a5b, // YCbCr interpolated color from the two logo colors
gotosocial: 0xff853e,
lemmy: 0x14854f,
};
const domainCache = new Map();
@ -116,6 +118,7 @@ async function processUrl(msg, url, spoiler = false) {
cw,
author,
timestamp,
title,
emotes = [];
// Fetch post
@ -370,27 +373,42 @@ async function processUrl(msg, url, spoiler = false) {
? postData.attachment
: [postData.attachment];
for (const attachment of attachments) {
if (attachment.mediaType.startsWith("video/")) {
videos.push({
url: attachment.url,
desc: attachment.name,
type: attachment.mediaType,
});
} else if (attachment.mediaType.startsWith("image/")) {
images.push({
url: attachment.url,
desc: attachment.name,
type: attachment.mediaType,
});
} else if (attachment.mediaType.startsWith("audio/")) {
audios.push({
url: attachment.url,
desc: attachment.name,
type: attachment.mediaType,
});
if (attachment.mediaType) {
if (attachment.mediaType.startsWith("video/")) {
videos.push({
url: attachment.url,
desc: attachment.name,
type: attachment.mediaType,
});
} else if (attachment.mediaType.startsWith("image/")) {
images.push({
url: attachment.url,
desc: attachment.name,
type: attachment.mediaType,
});
} else if (attachment.mediaType.startsWith("audio/")) {
audios.push({
url: attachment.url,
desc: attachment.name,
type: attachment.mediaType,
});
}
}
}
if (postData.image?.url) {
const imageUrl = new URL(postData.image?.url);
images.push({
url: postData.image?.url,
desc: "",
type:
"image/" +
imageUrl.pathname.substring(imageUrl.pathname.lastIndexOf(".") + 1),
});
}
if (postData.name) title = postData.name;
// Author data is not sent with the post with AS2
const authorData = await signedFetch(
postData.actor ?? postData.attributedTo,
@ -466,12 +484,22 @@ async function processUrl(msg, url, spoiler = false) {
}
}
const user = author.name
? `${author.name} (${author.handle})`
: author.handle;
const baseEmbed = {
color,
url,
timestamp,
description: desc,
title: `${author.name} (${author.handle})`,
title: title ?? user,
author: title
? {
name: user,
url: author.url,
}
: null,
footer: {
text: platformName,
},
@ -605,7 +633,7 @@ async function processUrl(msg, url, spoiler = false) {
.replace("/", ".")
.replace("mpeg", "mp3")
.replace("vnd.wave", "wav")
.replace("x-wav", "wav")
.replace("x-", "")
: attachment.type +
"." +
(url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp3")),