summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorPablo Stebler <pablo@stebler.xyz>2026-02-24 00:01:52 +0100
committerRory& <root@rory.gay>2026-02-25 07:14:30 +0100
commit013c8d8e7aec0c7d0cf8363d8d7be5e3abb97297 (patch)
tree81f43af60123d9c3ea400b221d4e8267abeb0721 /src/api
parentMerge remote-tracking branch 'mathium05/refineSearch' (diff)
downloadserver-ts-013c8d8e7aec0c7d0cf8363d8d7be5e3abb97297.tar.xz
Add support for attachment:// urls
Closes #1551.
Diffstat (limited to 'src/api')
-rw-r--r--src/api/util/handlers/Message.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts

index 85fb81f8..0c58ff83 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts
@@ -474,6 +474,53 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { } } + const attachmentIndices = new Map( + message.attachments?.map((attachment, index) => { + return [`attachment://${attachment.filename}`, index]; + }), + ); + const attachmentsToRemove = new Set<number>(); + function fetchAttachment(url: string | undefined): Attachment | undefined { + if (url == undefined) { + return undefined; + } + const index = attachmentIndices.get(url); + if (index === undefined) { + return undefined; + } + const attachment = message.attachments?.[index]; + if (attachment === undefined) { + return undefined; + } + attachmentsToRemove.add(index); + return attachment; + } + for (const embed of message.embeds) { + const footer = embed.footer; + const footerAttachment = fetchAttachment(footer?.icon_url); + if (footerAttachment !== undefined) { + footer!.icon_url = footerAttachment.url; + footer!.proxy_icon_url = footerAttachment.proxy_url; + } + + const image = embed.image; + const imageAttachment = fetchAttachment(image?.url); + if (imageAttachment !== undefined) { + image!.url = imageAttachment.url; + image!.proxy_url = imageAttachment.proxy_url; + } + + const author = embed.author; + const authorAttachment = fetchAttachment(author?.icon_url); + if (authorAttachment !== undefined) { + author!.icon_url = authorAttachment.url; + author!.proxy_icon_url = authorAttachment.proxy_url; + } + } + message.attachments = message.attachments?.filter((_, index) => { + return !attachmentsToRemove.has(index); + }); + // TODO: check and put it all in the body return message;