Untested gif resize support in cdn
This commit is contained in:
parent
de7e6f476f
commit
c2d388e16d
@ -68,9 +68,9 @@ router.get("/resize/:url", async (req: Request, res: Response) => {
|
|||||||
const h = Math.min(parseInt(height as string), resizeHeightMax ?? 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;
|
let buffer, response;
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url, DEFAULT_FETCH_OPTIONS);
|
response = await fetch(url, DEFAULT_FETCH_OPTIONS);
|
||||||
buffer = await response.buffer();
|
buffer = await response.buffer();
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
@ -81,11 +81,10 @@ router.get("/resize/:url", async (req: Request, res: Response) => {
|
|||||||
.resize(parseInt(width as string), parseInt(height as string), {
|
.resize(parseInt(width as string), parseInt(height as string), {
|
||||||
fit: "inside",
|
fit: "inside",
|
||||||
})
|
})
|
||||||
.png()
|
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
|
|
||||||
res.setHeader("Content-Disposition", "attachment");
|
res.setHeader("Content-Disposition", "attachment");
|
||||||
res.setHeader("Content-Type", "image/png");
|
res.setHeader("Content-Type", response.headers.get("content-type") ?? "image/png");
|
||||||
return res.end(resizedBuffer);
|
return res.end(resizedBuffer);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user