Skip to content

Commit

Permalink
WORKAROUND: Ignore client-requested file extension for role icons
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArcaneBrony committed Dec 8, 2023
1 parent 583d9ff commit 6f031db
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/cdn/routes/role-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 6f031db

Please sign in to comment.