mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-23 10:52:30 +01:00
Silently resize images back to max height/width
This commit is contained in:
parent
b00e432c2d
commit
90f95b6246
@ -62,14 +62,11 @@ router.get("/resize/:url", async (req: Request, res: Response) => {
|
|||||||
const url = decodeURIComponent(req.params.url);
|
const url = decodeURIComponent(req.params.url);
|
||||||
const { width, height } = req.query;
|
const { width, height } = req.query;
|
||||||
if (!width || !height) throw new HTTPError("Must provide width and height");
|
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;
|
const { resizeHeightMax, resizeWidthMax } = Config.get().cdn;
|
||||||
if (resizeHeightMax && resizeWidthMax &&
|
const w = Math.min(parseInt(width as string), resizeWidthMax ?? 100);
|
||||||
(w > resizeWidthMax || h > resizeHeightMax))
|
const h = Math.min(parseInt(height as string), resizeHeightMax ?? 100);
|
||||||
throw new HTTPError(`Width and height must not exceed ${resizeWidthMax}, ${resizeHeightMax}`);
|
if (w < 1 || h < 1) throw new HTTPError("Width and height must be greater than 0");
|
||||||
|
|
||||||
let buffer;
|
let buffer;
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user