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
+4 -4
View File
@@ -56,7 +56,7 @@ router.post(
};
return res.json(file);
}
},
);
router.get(
@@ -65,7 +65,7 @@ router.get(
const { channel_id, id, filename } = req.params;
const file = await storage.get(
`attachments/${channel_id}/${id}/${filename}`
`attachments/${channel_id}/${id}/${filename}`,
);
if (!file) throw new HTTPError("File not found");
const type = await FileType.fromBuffer(file);
@@ -79,7 +79,7 @@ router.get(
res.set("Cache-Control", "public, max-age=31536000");
return res.send(file);
}
},
);
router.delete(
@@ -94,7 +94,7 @@ router.delete(
await storage.delete(path);
return res.send({ success: true });
}
},
);
export default router;
+2 -2
View File
@@ -55,7 +55,7 @@ router.post(
size,
url: `${endpoint}${req.baseUrl}/${user_id}/${hash}`,
});
}
},
);
router.get("/:user_id", async (req: Request, res: Response) => {
@@ -86,7 +86,7 @@ export const getAvatar = async (req: Request, res: Response) => {
res.set("Cache-Control", "public, max-age=31536000");
return res.send(file);
}
};
router.get("/:user_id/:hash", getAvatar);
+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);
});
+1 -1
View File
@@ -7,4 +7,4 @@ const router = Router();
router.get("/:guild_id/users/:user_id/avatars/:hash", getAvatar);
router.get("/:guild_id/users/:user_id/banners/:hash", getAvatar);
export default router;
export default router;
+1 -1
View File
@@ -54,7 +54,7 @@ router.post(
size,
url: `${endpoint}${req.baseUrl}/${role_id}/${hash}`,
});
}
},
);
router.get("/:role_id", async (req: Request, res: Response) => {