summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRory& <myrainbowdash949@gmail.com>2023-12-08 20:50:20 +0000
committerRory& <myrainbowdash949@gmail.com>2023-12-08 20:50:20 +0000
commit6f031dbc935ed0393caffe4b326fca035c20c2f6 (patch)
treec49822326d04749c23210f3acdc1de2222bad91e /src
parentFix reacting with custom emojis from same guild requiring USE_EXTERNAL_EMOJIS (diff)
downloadserver-6f031dbc935ed0393caffe4b326fca035c20c2f6.tar.xz
WORKAROUND: Ignore client-requested file extension for role icons
Diffstat (limited to 'src')
-rw-r--r--src/cdn/routes/role-icons.ts21
1 files 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);