From 6f031dbc935ed0393caffe4b326fca035c20c2f6 Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 8 Dec 2023 20:50:20 +0000 Subject: WORKAROUND: Ignore client-requested file extension for role icons --- src/cdn/routes/role-icons.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/cdn/routes/role-icons.ts b/src/cdn/routes/role-icons.ts index c7fb6e1a..8040405a 100644 --- a/src/cdn/routes/role-icons.ts +++ b/src/cdn/routes/role-icons.ts @@ -93,9 +93,26 @@ router.get("/:role_id", async (req: Request, res: Response) => { router.get("/:role_id/:hash", async (req: Request, res: Response) => { const { role_id, hash } = req.params; //hash = hash.split(".")[0]; // remove .file extension - const path = `role-icons/${role_id}/${hash}`; + const requested_extension = hash.split(".")[1]; + const role_icon_hash = hash.split(".")[0]; + let file: Buffer | null = null; + + const extensions_to_try = [ + requested_extension, + "png", + "jpg", + "jpeg", + "webp", + "svg", + ]; + + for (let i = 0; i < extensions_to_try.length; i++) { + file = await storage.get( + `role-icons/${role_id}/${role_icon_hash}.${extensions_to_try[i]}`, + ); + if (file) break; + } - const file = await storage.get(path); if (!file) throw new HTTPError("not found", 404); const type = await FileType.fromBuffer(file); -- cgit 1.4.1