summary refs log tree commit diff
path: root/src/cdn
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-01-05 17:12:21 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-01-05 17:16:55 +1100
commitdf449169bde6c0576757700f68f2d406139cc846 (patch)
treef8bcbaf30ed3ed007d392a51614a134e543e3c17 /src/cdn
parentchannel flags whoops (diff)
downloadserver-df449169bde6c0576757700f68f2d406139cc846.tar.xz
Prettier
Diffstat (limited to 'src/cdn')
-rw-r--r--src/cdn/Server.ts12
-rw-r--r--src/cdn/routes/guild-profiles.ts24
-rw-r--r--src/cdn/util/FileStorage.ts3
3 files changed, 29 insertions, 10 deletions
diff --git a/src/cdn/Server.ts b/src/cdn/Server.ts

index 1fd9ca38..7340a735 100644 --- a/src/cdn/Server.ts +++ b/src/cdn/Server.ts
@@ -56,7 +56,7 @@ export class CDNServer extends Server { this.app.use("/splashes/", avatarsRoute); this.log("verbose", "[Server] Route /splashes registered"); - + this.app.use("/discovery-splashes/", avatarsRoute); this.log("verbose", "[Server] Route /discovery-splashes registered"); @@ -75,10 +75,16 @@ export class CDNServer extends Server { this.app.use("/channel-icons/", avatarsRoute); this.log("verbose", "[Server] Route /channel-icons registered"); - this.app.use("/guilds/:guild_id/users/:user_id/avatars", guildProfilesRoute); + this.app.use( + "/guilds/:guild_id/users/:user_id/avatars", + guildProfilesRoute, + ); this.log("verbose", "[Server] Route /guilds/avatars registered"); - this.app.use("/guilds/:guild_id/users/:user_id/banners", guildProfilesRoute); + this.app.use( + "/guilds/:guild_id/users/:user_id/banners", + guildProfilesRoute, + ); this.log("verbose", "[Server] Route /guilds/banners registered"); return super.start(); diff --git a/src/cdn/routes/guild-profiles.ts b/src/cdn/routes/guild-profiles.ts
index 98af7f69..2acc4ab7 100644 --- a/src/cdn/routes/guild-profiles.ts +++ b/src/cdn/routes/guild-profiles.ts
@@ -12,21 +12,32 @@ import { storage } from "../util/Storage"; // TODO: delete old icons const ANIMATED_MIME_TYPES = ["image/apng", "image/gif", "image/gifv"]; -const STATIC_MIME_TYPES = ["image/png", "image/jpeg", "image/webp", "image/svg+xml", "image/svg"]; +const STATIC_MIME_TYPES = [ + "image/png", + "image/jpeg", + "image/webp", + "image/svg+xml", + "image/svg", +]; const ALLOWED_MIME_TYPES = [...ANIMATED_MIME_TYPES, ...STATIC_MIME_TYPES]; const router = Router(); 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.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 { guild_id, user_id } = req.params; - let hash = crypto.createHash("md5").update(Snowflake.generate()).digest("hex"); + let hash = crypto + .createHash("md5") + .update(Snowflake.generate()) + .digest("hex"); const type = await FileType.fromBuffer(buffer); - if (!type || !ALLOWED_MIME_TYPES.includes(type.mime)) throw new HTTPError("Invalid file type"); + if (!type || !ALLOWED_MIME_TYPES.includes(type.mime)) + throw new HTTPError("Invalid file type"); if (ANIMATED_MIME_TYPES.includes(type.mime)) hash = `a_${hash}`; // animated icons have a_ infront of the hash const path = `guilds/${guild_id}/users/${user_id}/avatars/${hash}`; @@ -38,7 +49,7 @@ router.post("/", multer.single("file"), async (req: Request, res: Response) => { id: hash, content_type: type.mime, size, - url: `${endpoint}${req.baseUrl}/${user_id}/${hash}` + url: `${endpoint}${req.baseUrl}/${user_id}/${hash}`, }); }); @@ -73,7 +84,8 @@ router.get("/:hash", async (req: Request, res: Response) => { }); router.delete("/:id", async (req: Request, res: Response) => { - if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature"); + if (req.headers.signature !== Config.get().security.requestSignature) + throw new HTTPError("Invalid request signature"); const { guild_id, user_id, id } = req.params; const path = `guilds/${guild_id}/users/${user_id}/avatars/${id}`; diff --git a/src/cdn/util/FileStorage.ts b/src/cdn/util/FileStorage.ts
index 9386663f..e8d499e2 100644 --- a/src/cdn/util/FileStorage.ts +++ b/src/cdn/util/FileStorage.ts
@@ -35,7 +35,8 @@ export class FileStorage implements Storage { async set(path: string, value: any) { path = getPath(path); - if (!fs.existsSync(dirname(path))) fs.mkdirSync(dirname(path), { recursive: true }); + if (!fs.existsSync(dirname(path))) + fs.mkdirSync(dirname(path), { recursive: true }); value = Readable.from(value); const cleaned_file = fs.createWriteStream(path);