summary refs log tree commit diff
path: root/src/cdn
diff options
context:
space:
mode:
Diffstat (limited to 'src/cdn')
-rw-r--r--src/cdn/routes/attachments.ts10
-rw-r--r--src/cdn/routes/avatars.ts12
-rw-r--r--src/cdn/routes/external.ts5
-rw-r--r--src/cdn/routes/guild-profiles.ts12
-rw-r--r--src/cdn/routes/role-icons.ts12
5 files changed, 30 insertions, 21 deletions
diff --git a/src/cdn/routes/attachments.ts b/src/cdn/routes/attachments.ts
index 013f03d8..530d3a8b 100644
--- a/src/cdn/routes/attachments.ts
+++ b/src/cdn/routes/attachments.ts
@@ -10,8 +10,9 @@ 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 +50,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 +65,8 @@ 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..2fa88987 100644
--- a/src/cdn/routes/avatars.ts
+++ b/src/cdn/routes/avatars.ts
@@ -17,8 +17,9 @@ 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 +48,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 +63,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 +73,8 @@ 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..43c4e505 100644
--- a/src/cdn/routes/external.ts
+++ b/src/cdn/routes/external.ts
@@ -19,7 +19,8 @@ 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 +45,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..4ae492ea 100644
--- a/src/cdn/routes/guild-profiles.ts
+++ b/src/cdn/routes/guild-profiles.ts
@@ -17,8 +17,9 @@ 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 +48,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 +63,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 +73,8 @@ 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..b0946eaa 100644
--- a/src/cdn/routes/role-icons.ts
+++ b/src/cdn/routes/role-icons.ts
@@ -17,8 +17,9 @@ 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 +47,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 +62,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 +72,8 @@ 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}`;