fedimbed: attempt to fallback media type when uploading

This commit is contained in:
Cynthia Foxwell 2023-01-06 11:21:32 -07:00
parent 44779f7a23
commit a5dfd6395a

View file

@ -465,7 +465,11 @@ async function processUrl(msg, url) {
.then((buf) => Buffer.from(buf)); .then((buf) => Buffer.from(buf));
files.push({ files.push({
name: attachment.type.replace("/", "."), name:
attachment.type.indexOf("/") > -1
? attachment.type.replace("/", ".")
: attachment.type +
(url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp4"),
contents: file, contents: file,
}); });
} }
@ -492,11 +496,15 @@ async function processUrl(msg, url) {
.then((buf) => Buffer.from(buf)); .then((buf) => Buffer.from(buf));
files.push({ files.push({
name: attachment.type name:
.replace("/", ".") attachment.type.indexOf("/") > -1
.replace("mpeg", "mp3") ? attachment.type
.replace("vnd.wave", "wav") .replace("/", ".")
.replace("x-wav", "wav"), .replace("mpeg", "mp3")
.replace("vnd.wave", "wav")
.replace("x-wav", "wav")
: attachment.type +
(url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp3"),
contents: file, contents: file,
}); });
} }