From 59859177150c058d789cb04eee6c953f6818ac6d Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 10 Oct 2021 14:09:18 +0200 Subject: :bug: fix cdn route not working without hash --- cdn/src/routes/avatars.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'cdn/src/routes/avatars.ts') diff --git a/cdn/src/routes/avatars.ts b/cdn/src/routes/avatars.ts index 3d5e7d77..2a4a0ffe 100644 --- a/cdn/src/routes/avatars.ts +++ b/cdn/src/routes/avatars.ts @@ -58,6 +58,21 @@ router.post( } ); +router.get("/:user_id", async (req: Request, res: Response) => { + var { user_id } = req.params; + user_id = user_id.split(".")[0]; // remove .file extension + const path = `avatars/${user_id}`; + + const file = await storage.get(path); + if (!file) throw new HTTPError("not found", 404); + const type = await FileType.fromBuffer(file); + + res.set("Content-Type", type?.mime); + res.set("Cache-Control", "public, max-age=31536000"); + + return res.send(file); +}); + router.get("/:user_id/:hash", async (req: Request, res: Response) => { var { user_id, hash } = req.params; hash = hash.split(".")[0]; // remove .file extension -- cgit 1.4.1