diff --git a/src/cdn/Server.ts b/src/cdn/Server.ts
index bb7c9edf..37317bff 100644
--- a/src/cdn/Server.ts
+++ b/src/cdn/Server.ts
@@ -24,7 +24,7 @@ import guildProfilesRoute from "./routes/guild-profiles";
import iconsRoute from "./routes/role-icons";
import bodyParser from "body-parser";
-export interface CDNServerOptions extends ServerOptions {}
+export type CDNServerOptions = ServerOptions;
export class CDNServer extends Server {
public declare options: CDNServerOptions;
diff --git a/src/cdn/routes/attachments.ts b/src/cdn/routes/attachments.ts
index 76824925..d7764bd7 100644
--- a/src/cdn/routes/attachments.ts
+++ b/src/cdn/routes/attachments.ts
@@ -41,7 +41,7 @@ router.post(
throw new HTTPError("Invalid request signature");
if (!req.file) throw new HTTPError("file missing");
- const { buffer, mimetype, size, originalname, fieldname } = req.file;
+ const { buffer, mimetype, size, originalname } = req.file;
const { channel_id } = req.params;
const filename = originalname
.replaceAll(" ", "_")
@@ -53,8 +53,8 @@ router.post(
Config.get()?.cdn.endpointPublic || "http://localhost:3003";
await storage.set(path, buffer);
- var width;
- var height;
+ let width;
+ let height;
if (mimetype.includes("image")) {
const dimensions = imageSize(buffer);
if (dimensions) {
@@ -81,10 +81,10 @@ router.get(
"/:channel_id/:id/:filename",
async (req: Request, res: Response) => {
const { channel_id, id, filename } = req.params;
- const { format } = req.query;
+ // const { format } = req.query;
const path = `attachments/${channel_id}/${id}/${filename}`;
- let file = await storage.get(path);
+ const file = await storage.get(path);
if (!file) throw new HTTPError("File not found");
const type = await FileType.fromBuffer(file);
let content_type = type?.mime || "application/octet-stream";
diff --git a/src/cdn/routes/avatars.ts b/src/cdn/routes/avatars.ts
index e2d80d11..2c078c29 100644
--- a/src/cdn/routes/avatars.ts
+++ b/src/cdn/routes/avatars.ts
@@ -48,10 +48,10 @@ router.post(
if (req.headers.signature !== Config.get().security.requestSignature)
throw new HTTPError("Invalid request signature");
if (!req.file) throw new HTTPError("Missing file");
- const { buffer, mimetype, size, originalname, fieldname } = req.file;
+ const { buffer, size } = req.file;
const { user_id } = req.params;
- var hash = crypto
+ let hash = crypto
.createHash("md5")
.update(Snowflake.generate())
.digest("hex");
@@ -77,7 +77,7 @@ router.post(
);
router.get("/:user_id", async (req: Request, res: Response) => {
- var { user_id } = req.params;
+ let { user_id } = req.params;
user_id = user_id.split(".")[0]; // remove .file extension
const path = `avatars/${user_id}`;
@@ -92,7 +92,8 @@ router.get("/:user_id", async (req: Request, res: Response) => {
});
export const getAvatar = async (req: Request, res: Response) => {
- var { user_id, hash } = req.params;
+ const { user_id } = req.params;
+ let { hash } = req.params;
hash = hash.split(".")[0]; // remove .file extension
const path = `avatars/${user_id}/${hash}`;
diff --git a/src/cdn/routes/guild-profiles.ts b/src/cdn/routes/guild-profiles.ts
index 517550b7..a02d152c 100644
--- a/src/cdn/routes/guild-profiles.ts
+++ b/src/cdn/routes/guild-profiles.ts
@@ -45,7 +45,7 @@ router.post("/", multer.single("file"), async (req: Request, res: Response) => {
if (req.headers.signature !== Config.get().security.requestSignature)
throw new HTTPError("Invalid request signature");
if (!req.file) throw new HTTPError("Missing file");
- const { buffer, mimetype, size, originalname, fieldname } = req.file;
+ const { buffer, size } = req.file;
const { guild_id, user_id } = req.params;
let hash = crypto
@@ -72,7 +72,8 @@ router.post("/", multer.single("file"), async (req: Request, res: Response) => {
});
router.get("/", async (req: Request, res: Response) => {
- let { guild_id, user_id } = req.params;
+ const { guild_id } = req.params;
+ let { user_id } = req.params;
user_id = user_id.split(".")[0]; // remove .file extension
const path = `guilds/${guild_id}/users/${user_id}/avatars`;
@@ -87,7 +88,8 @@ router.get("/", async (req: Request, res: Response) => {
});
router.get("/:hash", async (req: Request, res: Response) => {
- let { guild_id, user_id, hash } = req.params;
+ const { guild_id, user_id } = req.params;
+ let { hash } = req.params;
hash = hash.split(".")[0]; // remove .file extension
const path = `guilds/${guild_id}/users/${user_id}/avatars/${hash}`;
diff --git a/src/cdn/routes/role-icons.ts b/src/cdn/routes/role-icons.ts
index b6e6812e..c3ad51c1 100644
--- a/src/cdn/routes/role-icons.ts
+++ b/src/cdn/routes/role-icons.ts
@@ -48,10 +48,10 @@ router.post(
if (req.headers.signature !== Config.get().security.requestSignature)
throw new HTTPError("Invalid request signature");
if (!req.file) throw new HTTPError("Missing file");
- const { buffer, mimetype, size, originalname, fieldname } = req.file;
+ const { buffer, size } = req.file;
const { role_id } = req.params;
- var hash = crypto
+ const hash = crypto
.createHash("md5")
.update(Snowflake.generate())
.digest("hex");
@@ -76,7 +76,7 @@ router.post(
);
router.get("/:role_id", async (req: Request, res: Response) => {
- var { role_id } = req.params;
+ const { role_id } = req.params;
//role_id = role_id.split(".")[0]; // remove .file extension
const path = `role-icons/${role_id}`;
@@ -91,7 +91,7 @@ router.get("/:role_id", async (req: Request, res: Response) => {
});
router.get("/:role_id/:hash", async (req: Request, res: Response) => {
- var { role_id, hash } = req.params;
+ const { role_id, hash } = req.params;
//hash = hash.split(".")[0]; // remove .file extension
const path = `role-icons/${role_id}/${hash}`;
diff --git a/src/cdn/util/FileStorage.ts b/src/cdn/util/FileStorage.ts
index c8473e30..ee087c85 100644
--- a/src/cdn/util/FileStorage.ts
+++ b/src/cdn/util/FileStorage.ts
@@ -28,7 +28,7 @@ import ExifTransformer from "exif-be-gone";
function getPath(path: string) {
// STORAGE_LOCATION has a default value in start.ts
const root = process.env.STORAGE_LOCATION || "../";
- var filename = join(root, path);
+ const filename = join(root, path);
if (path.indexOf("\0") !== -1 || !filename.startsWith(root))
throw new Error("invalid path");
@@ -51,15 +51,15 @@ export class FileStorage implements Storage {
}
}
- async set(path: string, value: any) {
+ async set(path: string, value: Buffer) {
path = getPath(path);
if (!fs.existsSync(dirname(path)))
fs.mkdirSync(dirname(path), { recursive: true });
- value = Readable.from(value);
+ const ret = Readable.from(value);
const cleaned_file = fs.createWriteStream(path);
- return value.pipe(new ExifTransformer()).pipe(cleaned_file);
+ ret.pipe(new ExifTransformer()).pipe(cleaned_file);
}
async delete(path: string) {
diff --git a/src/cdn/util/Storage.ts b/src/cdn/util/Storage.ts
index ee4ae889..0d55bbd0 100644
--- a/src/cdn/util/Storage.ts
+++ b/src/cdn/util/Storage.ts
@@ -19,7 +19,6 @@
import { FileStorage } from "./FileStorage";
import path from "path";
import fs from "fs";
-import { bgCyan, black } from "picocolors";
import { S3 } from "@aws-sdk/client-s3";
import { S3Storage } from "./S3Storage";
process.cwd();
|