fedimbed: limmy support

This commit is contained in:
Cynthia Foxwell 2023-09-22 20:50:19 -06:00
parent 690a8f8765
commit a0c037b6e9

View file

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