summary refs log tree commit diff
path: root/cdn/src
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-07-24 21:24:44 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-07-24 21:25:31 +1000
commit9a3286b6059fa06636ada20c0a0140e16625df67 (patch)
treef3581a5474570f8fd00eaaa5821c9176142575f0 /cdn/src
parentTurns out I reverted the code I needed rather than the one that will delete a... (diff)
downloadserver-9a3286b6059fa06636ada20c0a0140e16625df67.tar.xz
Silently resize images back to max height/width
Diffstat (limited to 'cdn/src')
-rw-r--r--cdn/src/routes/external.ts9
1 files changed, 3 insertions, 6 deletions
diff --git a/cdn/src/routes/external.ts b/cdn/src/routes/external.ts
index 65b8bcb1..577c38ec 100644
--- a/cdn/src/routes/external.ts
+++ b/cdn/src/routes/external.ts
@@ -62,14 +62,11 @@ router.get("/resize/:url", async (req: Request, res: Response) => {
 	const url = decodeURIComponent(req.params.url);
 	const { width, height } = req.query;
 	if (!width || !height) throw new HTTPError("Must provide width and height");
-	const w = parseInt(width as string);
-	const h = parseInt(height as string);
-	if (w < 1 || h < 1) throw new HTTPError("Width and height must be greater than 0");
 
 	const { resizeHeightMax, resizeWidthMax } = Config.get().cdn;
-	if (resizeHeightMax && resizeWidthMax &&
-		(w > resizeWidthMax || h > resizeHeightMax))
-		throw new HTTPError(`Width and height must not exceed ${resizeWidthMax}, ${resizeHeightMax}`);
+	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");
 
 	let buffer;
 	try {