summary refs log tree commit diff
path: root/src/api/util
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-09-23 23:36:55 +0200
committerRory& <root@rory.gay>2025-09-29 18:38:06 +0200
commit3bba7882fa153915a2b25c1bed267693f65fbb1a (patch)
tree8b582a941ff8751ae956d745088d47565a8dabce /src/api/util
parentUpdate message schema to handle cloud attachments (diff)
downloadserver-ts-3bba7882fa153915a2b25c1bed267693f65fbb1a.tar.xz
Try to handle new attachment style in message handler
Diffstat (limited to 'src/api/util')
-rw-r--r--src/api/util/handlers/Message.ts31
1 files changed, 31 insertions, 0 deletions
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<Message> { // 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; }