🐛 fix cdn route not working without hash

This commit is contained in:
Flam3rboy
2021-10-10 14:09:18 +02:00
parent 2908544b27
commit 63da3c0da4
2 changed files with 26 additions and 3 deletions
+15
View File
@@ -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