fedimbed: basic video and audio file support
This commit is contained in:
parent
680891f264
commit
b8fab6ec4f
1 changed files with 65 additions and 13 deletions
|
@ -69,7 +69,9 @@ async function processUrl(msg, url) {
|
|||
.replace("gotosocial", "GoToSocial")
|
||||
.replace(/^(.)/, (_, c) => c.toUpperCase());
|
||||
|
||||
const attachments = [];
|
||||
const images = [];
|
||||
const videos = [];
|
||||
const audios = [];
|
||||
let content, cw, author, timestamp;
|
||||
|
||||
// Fetch post
|
||||
|
@ -172,7 +174,9 @@ async function processUrl(msg, url) {
|
|||
postData2.content;
|
||||
author = {
|
||||
name: postData2.account.display_name,
|
||||
handle: postData2.account.fqn ?? `${postData2.account.username}@${urlObj.hostname}`,
|
||||
handle:
|
||||
postData2.account.fqn ??
|
||||
`${postData2.account.username}@${urlObj.hostname}`,
|
||||
url: postData2.account.url,
|
||||
avatar: postData2.account.avatar,
|
||||
};
|
||||
|
@ -190,10 +194,22 @@ async function processUrl(msg, url) {
|
|||
cw = postData.summary;
|
||||
timestamp = postData.published;
|
||||
for (const attachment of postData.attachment) {
|
||||
attachments.push({
|
||||
url: attachment.url,
|
||||
desc: attachment.name,
|
||||
});
|
||||
if (attachment.mediaType.startsWith("video/")) {
|
||||
videos.push({
|
||||
url: attachment.url,
|
||||
desc: attachment.name,
|
||||
});
|
||||
} else if (attachment.mediaType.startsWith("image/")) {
|
||||
images.push({
|
||||
url: attachment.url,
|
||||
desc: attachment.name,
|
||||
});
|
||||
} else if (attachment.mediaType.startsWith("audio/")) {
|
||||
audios.push({
|
||||
url: attachment.url,
|
||||
desc: attachment.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Author data is not sent with the post with AS2
|
||||
|
@ -240,7 +256,7 @@ async function processUrl(msg, url) {
|
|||
|
||||
let desc = "";
|
||||
let MAX_LENGTH = 3999;
|
||||
if (cw != "" && attachments.length == 0) {
|
||||
if (cw != "" && (images.length == 0 || videos.length == 0)) {
|
||||
desc += "\u26a0 " + cw + "\n\n||" + content + "||";
|
||||
MAX_LENGTH -= 8 - cw.length;
|
||||
} else {
|
||||
|
@ -270,26 +286,62 @@ async function processUrl(msg, url) {
|
|||
},
|
||||
fields: [],
|
||||
};
|
||||
if (attachments.length > 0) {
|
||||
if (attachments.length > 1) {
|
||||
if (images.length > 0) {
|
||||
if (images.length > 1) {
|
||||
baseEmbed.fields.push({
|
||||
name: "Images",
|
||||
value: attachments
|
||||
value: images
|
||||
.map((attachment, index) => `[Image ${index + 1}](${attachment.url})`)
|
||||
.join(" | "),
|
||||
inline: true,
|
||||
});
|
||||
} else {
|
||||
baseEmbed.fields.push({
|
||||
name: "Image",
|
||||
value: `[Click for image](${attachments[0].url})`,
|
||||
value: `[Click for image](${images[0].url})`,
|
||||
inline: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (videos.length > 0) {
|
||||
if (videos.length > 1) {
|
||||
baseEmbed.fields.push({
|
||||
name: "Videos",
|
||||
value: videos
|
||||
.map((attachment, index) => `[Video ${index + 1}](${attachment.url})`)
|
||||
.join(" | "),
|
||||
inline: true,
|
||||
});
|
||||
} else {
|
||||
baseEmbed.fields.push({
|
||||
name: "Video",
|
||||
value: `[Click for video](${videos[0].url})`,
|
||||
inline: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (audios.length > 0) {
|
||||
if (audios.length > 1) {
|
||||
baseEmbed.fields.push({
|
||||
name: "Audios",
|
||||
value: audios
|
||||
.map((attachment, index) => `[Audio ${index + 1}](${attachment.url})`)
|
||||
.join(" | "),
|
||||
inline: true,
|
||||
});
|
||||
} else {
|
||||
baseEmbed.fields.push({
|
||||
name: "Audio",
|
||||
value: `[Click for audio](${audios[0].url})`,
|
||||
inline: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const embeds = [];
|
||||
|
||||
if (attachments.length > 0) {
|
||||
for (const attachment of attachments) {
|
||||
if (images.length > 0) {
|
||||
for (const attachment of images) {
|
||||
const embed = Object.assign({}, baseEmbed);
|
||||
embed.image = {
|
||||
url: attachment.url,
|
||||
|
|
Loading…
Reference in a new issue