This commit is contained in:
Madeline
2022-09-26 22:41:21 +10:00
parent fcc0884e36
commit 99ee7e9400
280 changed files with 6800 additions and 3908 deletions
+7 -4
View File
@@ -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);
});