From 15b79052c88ce30a713c6f942cedf01211b50a5f Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sat, 17 Sep 2022 19:38:54 +0200 Subject: Partially refactor code to use localization --- src/cdn/routes/role-icons.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/cdn/routes/role-icons.ts') diff --git a/src/cdn/routes/role-icons.ts b/src/cdn/routes/role-icons.ts index 768e194f..4449f9d1 100644 --- a/src/cdn/routes/role-icons.ts +++ b/src/cdn/routes/role-icons.ts @@ -17,8 +17,8 @@ const ALLOWED_MIME_TYPES = [...STATIC_MIME_TYPES]; const router = Router(); router.post("/:role_id", multer.single("file"), async (req: Request, res: Response) => { - if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature"); - if (!req.file) throw new HTTPError("Missing file"); + if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); + if (!req.file) throw new HTTPError(req.t("common:body.MISSING_FILE")); const { buffer, mimetype, size, originalname, fieldname } = req.file; const { role_id } = req.params; @@ -46,7 +46,7 @@ router.get("/:role_id", async (req: Request, res: Response) => { const path = `role-icons/${role_id}`; const file = await storage.get(path); - if (!file) throw new HTTPError("not found", 404); + if (!file) throw new HTTPError(req.t("common:notfound.FILE"), 404); const type = await FileType.fromBuffer(file); res.set("Content-Type", type?.mime); @@ -61,7 +61,7 @@ router.get("/:role_id/:hash", async (req: Request, res: Response) => { const path = `role-icons/${role_id}/${hash}`; const file = await storage.get(path); - if (!file) throw new HTTPError("not found", 404); + if (!file) throw new HTTPError(req.t("common:notfound.FILE"), 404); const type = await FileType.fromBuffer(file); res.set("Content-Type", type?.mime); @@ -71,7 +71,7 @@ router.get("/:role_id/:hash", async (req: Request, res: Response) => { }); router.delete("/:role_id/:id", async (req: Request, res: Response) => { - if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature"); + if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError(req.t("common:body.INVALID_REQUEST_SIGNATURE")); const { role_id, id } = req.params; const path = `role-icons/${role_id}/${id}`; -- cgit 1.4.1