summary refs log tree commit diff
path: root/src/cdn/routes
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2022-09-17 19:38:54 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2022-09-17 19:38:54 +0200
commit15b79052c88ce30a713c6f942cedf01211b50a5f (patch)
treecc444dce096a314e7fa2700a07858039d7ee8a61 /src/cdn/routes
parentAdd register ratelimit (diff)
downloadserver-15b79052c88ce30a713c6f942cedf01211b50a5f.tar.xz
Partially refactor code to use localization
Diffstat (limited to '')
-rw-r--r--src/cdn/routes/attachments.ts8
-rw-r--r--src/cdn/routes/avatars.ts10
-rw-r--r--src/cdn/routes/external.ts4
-rw-r--r--src/cdn/routes/guild-profiles.ts10
-rw-r--r--src/cdn/routes/role-icons.ts10
5 files changed, 21 insertions, 21 deletions
diff --git a/src/cdn/routes/attachments.ts b/src/cdn/routes/attachments.ts
index 013f03d8..bf74bd73 100644
--- a/src/cdn/routes/attachments.ts
+++ b/src/cdn/routes/attachments.ts
@@ -10,8 +10,8 @@ const router = Router();
 const SANITIZED_CONTENT_TYPE = ["text/html", "text/mhtml", "multipart/related", "application/xhtml+xml"];
 
 router.post("/:channel_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("file missing");
+	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 { channel_id } = req.params;
@@ -49,7 +49,7 @@ router.get("/:channel_id/:id/:filename", async (req: Request, res: Response) =>
 	const { channel_id, id, filename } = req.params;
 
 	const file = await storage.get(`attachments/${channel_id}/${id}/${filename}`);
-	if (!file) throw new HTTPError("File not found");
+	if (!file) throw new HTTPError(req.t("common:notfound.FILE"));
 	const type = await FileType.fromBuffer(file);
 	let content_type = type?.mime || "application/octet-stream";
 
@@ -64,7 +64,7 @@ router.get("/:channel_id/:id/:filename", async (req: Request, res: Response) =>
 });
 
 router.delete("/:channel_id/:id/:filename", 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 { channel_id, id, filename } = req.params;
 	const path = `attachments/${channel_id}/${id}/${filename}`;
diff --git a/src/cdn/routes/avatars.ts b/src/cdn/routes/avatars.ts
index fa26938f..1bd91942 100644
--- a/src/cdn/routes/avatars.ts
+++ b/src/cdn/routes/avatars.ts
@@ -17,8 +17,8 @@ const ALLOWED_MIME_TYPES = [...ANIMATED_MIME_TYPES, ...STATIC_MIME_TYPES];
 const router = Router();
 
 router.post("/:user_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 { user_id } = req.params;
 
@@ -47,7 +47,7 @@ router.get("/:user_id", async (req: Request, res: Response) => {
 	const path = `avatars/${user_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);
@@ -62,7 +62,7 @@ router.get("/:user_id/:hash", async (req: Request, res: Response) => {
 	const path = `avatars/${user_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);
@@ -72,7 +72,7 @@ router.get("/:user_id/:hash", async (req: Request, res: Response) => {
 });
 
 router.delete("/:user_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 { user_id, id } = req.params;
 	const path = `avatars/${user_id}/${id}`;
 
diff --git a/src/cdn/routes/external.ts b/src/cdn/routes/external.ts
index 7ccf9b8a..cd25268f 100644
--- a/src/cdn/routes/external.ts
+++ b/src/cdn/routes/external.ts
@@ -19,7 +19,7 @@ const DEFAULT_FETCH_OPTIONS: any = {
 };
 
 router.post("/", 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"));
 
 	if (!req.body) throw new HTTPError("Invalid Body");
 
@@ -44,7 +44,7 @@ router.get("/:id", async (req: Request, res: Response) => {
 	const { id } = req.params;
 
 	const file = await storage.get(`/external/${id}`);
-	if (!file) throw new HTTPError("File not found");
+	if (!file) throw new HTTPError(req.t("common:notfound.FILE"));
 	const result = await FileType.fromBuffer(file);
 
 	res.set("Content-Type", result?.mime);
diff --git a/src/cdn/routes/guild-profiles.ts b/src/cdn/routes/guild-profiles.ts
index 32c05ad9..9fc3b80f 100644
--- a/src/cdn/routes/guild-profiles.ts
+++ b/src/cdn/routes/guild-profiles.ts
@@ -17,8 +17,8 @@ const ALLOWED_MIME_TYPES = [...ANIMATED_MIME_TYPES, ...STATIC_MIME_TYPES];
 const router = Router();
 
 router.post("/", 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 { guild_id, user_id } = req.params;
 
@@ -47,7 +47,7 @@ router.get("/", async (req: Request, res: Response) => {
 	const path = `guilds/${guild_id}/users/${user_id}/avatars`;
 
 	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);
@@ -62,7 +62,7 @@ router.get("/:hash", async (req: Request, res: Response) => {
 	const path = `guilds/${guild_id}/users/${user_id}/avatars/${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);
@@ -72,7 +72,7 @@ router.get("/:hash", async (req: Request, res: Response) => {
 });
 
 router.delete("/: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 { guild_id, user_id, id } = req.params;
 	const path = `guilds/${guild_id}/users/${user_id}/avatars/${id}`;
 
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}`;