diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-24 21:24:44 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-24 21:25:31 +1000 |
commit | 90f95b62468dfc2eb6fc0ef9f17f843b29c2f914 (patch) | |
tree | 253c8a2576f7e40e96168d7cd1a2c173b0366752 | |
parent | Turns out I reverted the code I needed rather than the one that will delete a... (diff) | |
download | server-90f95b62468dfc2eb6fc0ef9f17f843b29c2f914.tar.xz |
Silently resize images back to max height/width
-rw-r--r-- | cdn/src/routes/external.ts | 9 |
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 { |