fedimbed: fix attachments for mastoapi
This commit is contained in:
parent
4b6ebea322
commit
5ab26c461f
1 changed files with 38 additions and 6 deletions
|
@ -182,10 +182,34 @@ async function processUrl(msg, url) {
|
||||||
};
|
};
|
||||||
timestamp = postData2.created_at;
|
timestamp = postData2.created_at;
|
||||||
for (const attachment of postData2.media_attachments) {
|
for (const attachment of postData2.media_attachments) {
|
||||||
attachments.push({
|
const fileType =
|
||||||
url: attachment.url,
|
attachment.pleroma?.mime_type ??
|
||||||
desc: attachment.description,
|
attachment.type +
|
||||||
});
|
(url.match(/\.([a-z0-9]{3,4})$/)?.[0] ??
|
||||||
|
attachment.type == "image"
|
||||||
|
? "png"
|
||||||
|
: attachment.type == "video"
|
||||||
|
? "mp4"
|
||||||
|
: "mpeg");
|
||||||
|
if (attachment.type == "image") {
|
||||||
|
images.push({
|
||||||
|
url: attachment.url,
|
||||||
|
desc: attachment.description,
|
||||||
|
type: fileType,
|
||||||
|
});
|
||||||
|
} else if (attachment.type == "video") {
|
||||||
|
videos.push({
|
||||||
|
url: attachment.url,
|
||||||
|
desc: attachment.description,
|
||||||
|
type: fileType,
|
||||||
|
});
|
||||||
|
} else if (attachment.type == "audio") {
|
||||||
|
audios.push({
|
||||||
|
url: attachment.url,
|
||||||
|
desc: attachment.description,
|
||||||
|
type: fileType,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,7 +285,12 @@ async function processUrl(msg, url) {
|
||||||
|
|
||||||
let desc = "";
|
let desc = "";
|
||||||
let MAX_LENGTH = 3999;
|
let MAX_LENGTH = 3999;
|
||||||
if (cw != "" && (images.length == 0 && videos.length == 0 && audios.length == 0)) {
|
if (
|
||||||
|
cw != "" &&
|
||||||
|
images.length == 0 &&
|
||||||
|
videos.length == 0 &&
|
||||||
|
audios.length == 0
|
||||||
|
) {
|
||||||
desc += "\u26a0 " + cw + "\n\n||" + content + "||";
|
desc += "\u26a0 " + cw + "\n\n||" + content + "||";
|
||||||
MAX_LENGTH -= 8 - cw.length;
|
MAX_LENGTH -= 8 - cw.length;
|
||||||
} else {
|
} else {
|
||||||
|
@ -427,7 +456,10 @@ async function processUrl(msg, url) {
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
|
|
||||||
await msg.channel.createMessage({
|
await msg.channel.createMessage({
|
||||||
content: cw && (images.length > 0 || videos.length > 0 || audios.length > 0) ? `:warning: ${cw} || ${url} ||` : "",
|
content:
|
||||||
|
cw && (images.length > 0 || videos.length > 0 || audios.length > 0)
|
||||||
|
? `:warning: ${cw} || ${url} ||`
|
||||||
|
: "",
|
||||||
embeds,
|
embeds,
|
||||||
files,
|
files,
|
||||||
allowedMentions: {
|
allowedMentions: {
|
||||||
|
|
Loading…
Reference in a new issue