Fix crash
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 20s

This commit is contained in:
Mylloon 2024-10-14 22:40:03 +02:00
parent c74a04ed41
commit f47d62faad
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -12,8 +12,8 @@ export const handleAttachments = (
} else {
// Contains more than one image and/or other files
// We are currently losing a link to a file if the link is too long,
// but we can't do much about it
// We are currently losing a link to a file if the link is too long
// We could truncate the filename ?
const maxFieldValueLength = 1024;
const files = attachments
.map((file) => `[${file.name}](${file.url})`)
@ -25,8 +25,7 @@ export const handleAttachments = (
files.forEach((file, idx) => {
const fieldValue = currentField.length > 0 ? `${currentField}, ${file}` : file;
// TODO: There is a bug when there is ONE field, it crashes
if (fieldValue.length > maxFieldValueLength || idx === files.length - 1) {
if (fieldValue.length > maxFieldValueLength) {
multiple = multiple === 0 && idx !== files.length - 1 ? 1 : multiple + 1;
fields.push({
name:
@ -41,6 +40,15 @@ export const handleAttachments = (
}
});
if (currentField.length > 0) {
fields.push({
name:
loc.get(attachments.size > 1 && multiple ? "e_attachements" : "e_attachement") +
(multiple ? ` (${multiple + 1})` : ""),
value: currentField,
});
}
embed.addFields(fields);
}
};