mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-09 20:22:47 +01:00
WORKAROUND: Ignore client-requested file extension for role icons
This commit is contained in:
parent
583d9ff407
commit
6f031dbc93
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user