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/Server.ts8
-rw-r--r--src/cdn/routes/attachments.ts8
-rw-r--r--src/cdn/routes/avatars.ts4
-rw-r--r--src/cdn/routes/external.ts11
-rw-r--r--src/cdn/routes/guilds.ts2
-rw-r--r--src/cdn/routes/role-icons.ts2
-rw-r--r--src/cdn/start.ts2
-rw-r--r--src/cdn/util/S3Storage.ts2
-rw-r--r--src/cdn/util/Storage.ts6
9 files changed, 24 insertions, 21 deletions
diff --git a/src/cdn/Server.ts b/src/cdn/Server.ts
index 5b395589..f7e6dbdc 100644
--- a/src/cdn/Server.ts
+++ b/src/cdn/Server.ts
@@ -5,7 +5,7 @@ import avatarsRoute from "./routes/avatars";
 import iconsRoute from "./routes/role-icons";
 import bodyParser from "body-parser";
 
-export interface CDNServerOptions extends ServerOptions { }
+export interface CDNServerOptions extends ServerOptions {}
 
 export class CDNServer extends Server {
 	public declare options: CDNServerOptions;
@@ -22,15 +22,15 @@ export class CDNServer extends Server {
 			// TODO: use better CSP policy
 			res.set(
 				"Content-security-policy",
-				"default-src *  data: blob: filesystem: about: ws: wss: 'unsafe-inline' 'unsafe-eval'; script-src * data: blob: 'unsafe-inline' 'unsafe-eval'; connect-src * data: blob: 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src * data: blob: ; style-src * data: blob: 'unsafe-inline'; font-src * data: blob: 'unsafe-inline';"
+				"default-src *  data: blob: filesystem: about: ws: wss: 'unsafe-inline' 'unsafe-eval'; script-src * data: blob: 'unsafe-inline' 'unsafe-eval'; connect-src * data: blob: 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src * data: blob: ; style-src * data: blob: 'unsafe-inline'; font-src * data: blob: 'unsafe-inline';",
 			);
 			res.set(
 				"Access-Control-Allow-Headers",
-				req.header("Access-Control-Request-Headers") || "*"
+				req.header("Access-Control-Request-Headers") || "*",
 			);
 			res.set(
 				"Access-Control-Allow-Methods",
-				req.header("Access-Control-Request-Methods") || "*"
+				req.header("Access-Control-Request-Methods") || "*",
 			);
 			next();
 		});
diff --git a/src/cdn/routes/attachments.ts b/src/cdn/routes/attachments.ts
index ae50bc48..2a1b6f09 100644
--- a/src/cdn/routes/attachments.ts
+++ b/src/cdn/routes/attachments.ts
@@ -56,7 +56,7 @@ router.post(
 		};
 
 		return res.json(file);
-	}
+	},
 );
 
 router.get(
@@ -65,7 +65,7 @@ router.get(
 		const { channel_id, id, filename } = req.params;
 
 		const file = await storage.get(
-			`attachments/${channel_id}/${id}/${filename}`
+			`attachments/${channel_id}/${id}/${filename}`,
 		);
 		if (!file) throw new HTTPError("File not found");
 		const type = await FileType.fromBuffer(file);
@@ -79,7 +79,7 @@ router.get(
 		res.set("Cache-Control", "public, max-age=31536000");
 
 		return res.send(file);
-	}
+	},
 );
 
 router.delete(
@@ -94,7 +94,7 @@ router.delete(
 		await storage.delete(path);
 
 		return res.send({ success: true });
-	}
+	},
 );
 
 export default router;
diff --git a/src/cdn/routes/avatars.ts b/src/cdn/routes/avatars.ts
index e5e25a4c..50a76d4b 100644
--- a/src/cdn/routes/avatars.ts
+++ b/src/cdn/routes/avatars.ts
@@ -55,7 +55,7 @@ router.post(
 			size,
 			url: `${endpoint}${req.baseUrl}/${user_id}/${hash}`,
 		});
-	}
+	},
 );
 
 router.get("/:user_id", async (req: Request, res: Response) => {
@@ -86,7 +86,7 @@ export const getAvatar = async (req: Request, res: Response) => {
 	res.set("Cache-Control", "public, max-age=31536000");
 
 	return res.send(file);
-}
+};
 
 router.get("/:user_id/:hash", getAvatar);
 
diff --git a/src/cdn/routes/external.ts b/src/cdn/routes/external.ts
index cb17ff9b..405e665e 100644
--- a/src/cdn/routes/external.ts
+++ b/src/cdn/routes/external.ts
@@ -66,14 +66,14 @@ router.get("/resize/:url", async (req: Request, res: Response) => {
 	const { resizeHeightMax, resizeWidthMax } = Config.get().cdn;
 	const w = Math.min(parseInt(width as string), resizeWidthMax ?? 100);
 	const h = Math.min(parseInt(height as string), resizeHeightMax ?? 100);
-	if (w < 1 || h < 1) throw new HTTPError("Width and height must be greater than 0");
+	if (w < 1 || h < 1)
+		throw new HTTPError("Width and height must be greater than 0");
 
 	let buffer, response;
 	try {
 		response = await fetch(url, DEFAULT_FETCH_OPTIONS);
 		buffer = await response.buffer();
-	}
-	catch (e) {
+	} catch (e) {
 		throw new HTTPError("Couldn't fetch website");
 	}
 
@@ -84,7 +84,10 @@ router.get("/resize/:url", async (req: Request, res: Response) => {
 		.toBuffer();
 
 	res.setHeader("Content-Disposition", "attachment");
-	res.setHeader("Content-Type", response.headers.get("content-type") ?? "image/png");
+	res.setHeader(
+		"Content-Type",
+		response.headers.get("content-type") ?? "image/png",
+	);
 	return res.end(resizedBuffer);
 });
 
diff --git a/src/cdn/routes/guilds.ts b/src/cdn/routes/guilds.ts
index 3c4b646c..6f0719b6 100644
--- a/src/cdn/routes/guilds.ts
+++ b/src/cdn/routes/guilds.ts
@@ -7,4 +7,4 @@ const router = Router();
 router.get("/:guild_id/users/:user_id/avatars/:hash", getAvatar);
 router.get("/:guild_id/users/:user_id/banners/:hash", getAvatar);
 
-export default router;
\ No newline at end of file
+export default router;
diff --git a/src/cdn/routes/role-icons.ts b/src/cdn/routes/role-icons.ts
index 12aae8a4..bdfa0355 100644
--- a/src/cdn/routes/role-icons.ts
+++ b/src/cdn/routes/role-icons.ts
@@ -54,7 +54,7 @@ router.post(
 			size,
 			url: `${endpoint}${req.baseUrl}/${role_id}/${hash}`,
 		});
-	}
+	},
 );
 
 router.get("/:role_id", async (req: Request, res: Response) => {
diff --git a/src/cdn/start.ts b/src/cdn/start.ts
index 1fdea22e..c22984fa 100644
--- a/src/cdn/start.ts
+++ b/src/cdn/start.ts
@@ -1,4 +1,4 @@
-require('module-alias/register')
+require("module-alias/register");
 import dotenv from "dotenv";
 dotenv.config();
 
diff --git a/src/cdn/util/S3Storage.ts b/src/cdn/util/S3Storage.ts
index c4066817..33c11265 100644
--- a/src/cdn/util/S3Storage.ts
+++ b/src/cdn/util/S3Storage.ts
@@ -14,7 +14,7 @@ export class S3Storage implements Storage {
 	public constructor(
 		private client: S3,
 		private bucket: string,
-		private basePath?: string
+		private basePath?: string,
 	) {}
 
 	/**
diff --git a/src/cdn/util/Storage.ts b/src/cdn/util/Storage.ts
index d040f50b..d66cb2dc 100644
--- a/src/cdn/util/Storage.ts
+++ b/src/cdn/util/Storage.ts
@@ -33,14 +33,14 @@ if (process.env.STORAGE_PROVIDER === "file" || !process.env.STORAGE_PROVIDER) {
 
 	if (!region) {
 		console.error(
-			`[CDN] You must provide a region when using the S3 storage provider.`
+			`[CDN] You must provide a region when using the S3 storage provider.`,
 		);
 		process.exit(1);
 	}
 
 	if (!bucket) {
 		console.error(
-			`[CDN] You must provide a bucket when using the S3 storage provider.`
+			`[CDN] You must provide a bucket when using the S3 storage provider.`,
 		);
 		process.exit(1);
 	}
@@ -50,7 +50,7 @@ if (process.env.STORAGE_PROVIDER === "file" || !process.env.STORAGE_PROVIDER) {
 
 	if (!location) {
 		console.warn(
-			`[CDN] STORAGE_LOCATION unconfigured for S3 provider, defaulting to the bucket root...`
+			`[CDN] STORAGE_LOCATION unconfigured for S3 provider, defaulting to the bucket root...`,
 		);
 		location = undefined;
 	}