From 3bba7882fa153915a2b25c1bed267693f65fbb1a Mon Sep 17 00:00:00 2001 From: Rory& Date: Tue, 23 Sep 2025 23:36:55 +0200 Subject: [PATCH] Try to handle new attachment style in message handler --- src/api/util/handlers/Message.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts index 0977b1db..b5a5bc98 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts @@ -290,6 +290,37 @@ export async function handleMessage(opts: MessageOptions): Promise { // TODO: check and put it all in the body + if(message.attachments?.some(att => "uploaded_filename" in att)) { + message.attachments = await Promise.all(message.attachments.map(async att => { + if("uploaded_filename" in att) { + const cloneResponse = await fetch(`${Config.get().cdn.endpointPrivate}/attachments/${att.uploaded_filename}/clone_to_message/${message.id}`, { + method: "POST", + headers: { + "X-Signature": Config.get().security.requestSignature || "", + }, + }); + if(!cloneResponse.ok) { + console.error(`[Message] Failed to clone attachment ${att.uploaded_filename} to message ${message.id}`); + throw new HTTPError("Failed to process attachment: " + await cloneResponse.text(), 500); + } + + const cloneRespBody = await cloneResponse.json() as { success: boolean, new_path: string }; + + return Attachment.create({ + id: att.id, + filename: att.filename, + url: `${Config.get().cdn.endpointPublic}/${cloneRespBody.new_path}`, + proxy_url: `${Config.get().cdn.endpointPublic}/${cloneRespBody.new_path}`, + size: att.size, + height: att.height, + width: att.width, + content_type: att.content_type, + }); + } + return att; + })); + } + return message; }