summary refs log tree commit diff
path: root/src/routes/attachments.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-30 01:44:46 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-30 01:44:46 +0200
commite87bebc3a3bd3b9408aca527b374f703c980070b (patch)
treef2a813d8bd86a427f4731ef453c522eaeac52b6f /src/routes/attachments.ts
parent:sparkles: avatars (diff)
downloadserver-e87bebc3a3bd3b9408aca527b374f703c980070b.tar.xz
:sparkles: avatars + attachments
Diffstat (limited to '')
-rw-r--r--src/routes/attachments.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/routes/attachments.ts b/src/routes/attachments.ts

index 3bbced31..e99b8d87 100644 --- a/src/routes/attachments.ts +++ b/src/routes/attachments.ts
@@ -4,10 +4,14 @@ import { storage } from "../util/Storage"; import FileType from "file-type"; import { HTTPError } from "lambert-server"; import { multer } from "../Server"; +import imageSize from "image-size"; const router = Router(); router.post("/:channel_id", multer.single("file"), async (req, res) => { + if (req.headers.signature !== Config.get().security.requestSignature) + throw new HTTPError("Invalid request signature"); + const { buffer, mimetype, size, originalname, fieldname } = req.file; const { channel_id } = req.params; const filename = originalname.replaceAll(" ", "_").replace(/[^a-zA-Z0-9._]+/g, ""); @@ -17,6 +21,15 @@ router.post("/:channel_id", multer.single("file"), async (req, res) => { const endpoint = Config.get().cdn.endpoint || "http://localhost:3003"; await storage.set(path, buffer); + var width; + var height; + if (mimetype.includes("image")) { + const dimensions = imageSize(buffer); + if (dimensions) { + width = dimensions.width; + height = dimensions.height; + } + } const file = { id, @@ -24,6 +37,8 @@ router.post("/:channel_id", multer.single("file"), async (req, res) => { filename: filename, size, url: `${endpoint}/${path}`, + width, + height, }; return res.json(file); @@ -42,6 +57,9 @@ router.get("/:channel_id/:id/:filename", async (req, res) => { }); router.delete("/:channel_id/:id/:filename", async (req, res) => { + if (req.headers.signature !== Config.get().security.requestSignature) + throw new HTTPError("Invalid request signature"); + const { channel_id, id, filename } = req.params; const path = `attachments/${channel_id}/${id}/${filename}`;