summary refs log tree commit diff
path: root/src/cdn
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-09-28 20:09:38 +0200
committerRory& <root@rory.gay>2025-09-29 18:38:06 +0200
commitf20dff80eff002d39a662eedb538a486ec6be76b (patch)
tree0be8808e019043de757849bcc0e3a225087d98b7 /src/cdn
parentLogging of empty messages (diff)
downloadserver-ts-f20dff80eff002d39a662eedb538a486ec6be76b.tar.xz
Make cloud uploads work
Diffstat (limited to 'src/cdn')
-rw-r--r--src/cdn/routes/attachments.ts15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/cdn/routes/attachments.ts b/src/cdn/routes/attachments.ts

index 23ca141ad..4c65bbb28 100644 --- a/src/cdn/routes/attachments.ts +++ b/src/cdn/routes/attachments.ts
@@ -150,7 +150,14 @@ router.put("/:channel_id/:batch_id/:attachment_id/:filename", multer.single("fil const path = `attachments/${channel_id}/${batch_id}/${attachment_id}/${filename}`; await storage.set(path, buffer); - if (att.userOriginalContentType?.includes("image")) { + + let mimeType = att.userOriginalContentType; + if (att.userOriginalContentType === null) { + const ft = await FileType.fromBuffer(buffer); + mimeType = att.contentType = ft?.mime || "application/octet-stream"; + } + + if (mimeType?.includes("image")) { const dimensions = imageSize(buffer); if (dimensions) { att.width = dimensions.width; @@ -168,6 +175,7 @@ router.put("/:channel_id/:batch_id/:attachment_id/:filename", multer.single("fil router.delete("/:channel_id/:batch_id/:attachment_id/:filename", async (req: Request, res: Response) => { if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature"); + console.log("[Cloud Delete] Deleting attachment", req.params); const { channel_id, batch_id, attachment_id, filename } = req.params; const path = `attachments/${channel_id}/${batch_id}/${attachment_id}/${filename}`; @@ -191,10 +199,11 @@ router.delete("/:channel_id/:batch_id/:attachment_id/:filename", async (req: Req router.post("/:channel_id/:batch_id/:attachment_id/:filename/clone_to_message/:message_id", async (req: Request, res: Response) => { if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature"); + console.log("[Cloud Clone] Cloning attachment to message", req.params); - const { channel_id, batch_id, attachment_id, filename } = req.params; + const { channel_id, batch_id, attachment_id, filename, message_id } = req.params; const path = `attachments/${channel_id}/${batch_id}/${attachment_id}/${filename}`; - const newPath = `attachments/${channel_id}/${filename}`; + const newPath = `attachments/${channel_id}/${message_id}/${filename}`; const att = await CloudAttachment.findOne({ where: {