diff --git a/package-lock.json b/package-lock.json index f8aed44d..301b0ff7 100644 Binary files a/package-lock.json and b/package-lock.json differ diff --git a/package.json b/package.json index c87c3dc8..4c400153 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "exif-be-gone": "^1.5.1", "fast-zlib": "^2.0.1", "fido2-lib": "^3.5.3", - "file-type": "~16.5.4", + "file-type": "^21.0.0", "form-data": "^4.0.4", "i18next": "^25.5.2", "i18next-fs-backend": "^2.6.0", diff --git a/src/cdn/routes/attachments.ts b/src/cdn/routes/attachments.ts index 4c65bbb2..1f3bc9f9 100644 --- a/src/cdn/routes/attachments.ts +++ b/src/cdn/routes/attachments.ts @@ -18,7 +18,7 @@ import { Config, hasValidSignature, NewUrlUserSignatureData, Snowflake, UrlSignResult } from "@spacebar/util"; import { Request, Response, Router } from "express"; -import FileType from "file-type"; +import { fileTypeFromBuffer } from "file-type"; import imageSize from "image-size"; import { HTTPError } from "lambert-server"; import { multer } from "../util/multer"; @@ -92,7 +92,7 @@ router.get("/:channel_id/:id/:filename", async (req: Request, res: Response) => const file = await storage.get(path); if (!file) throw new HTTPError("File not found"); - const type = await FileType.fromBuffer(file); + const type = await fileTypeFromBuffer(file); let content_type = type?.mime || "application/octet-stream"; if (SANITIZED_CONTENT_TYPE.includes(content_type)) { @@ -153,7 +153,7 @@ router.put("/:channel_id/:batch_id/:attachment_id/:filename", multer.single("fil let mimeType = att.userOriginalContentType; if (att.userOriginalContentType === null) { - const ft = await FileType.fromBuffer(buffer); + const ft = await fileTypeFromBuffer(buffer); mimeType = att.contentType = ft?.mime || "application/octet-stream"; } diff --git a/src/cdn/routes/avatars.ts b/src/cdn/routes/avatars.ts index 6af3243f..7e96dde3 100644 --- a/src/cdn/routes/avatars.ts +++ b/src/cdn/routes/avatars.ts @@ -19,7 +19,7 @@ import { Router, Response, Request } from "express"; import { Config, Snowflake } from "@spacebar/util"; import { storage } from "../util/Storage"; -import FileType from "file-type"; +import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server"; import crypto from "crypto"; import { multer } from "../util/multer"; @@ -56,7 +56,7 @@ router.post( .update(Snowflake.generate()) .digest("hex"); - const type = await FileType.fromBuffer(buffer); + const type = await fileTypeFromBuffer(buffer); 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 @@ -83,7 +83,7 @@ router.get("/:user_id", async (req: Request, res: Response) => { const file = await storage.get(path); if (!file) throw new HTTPError("not found", 404); - const type = await FileType.fromBuffer(file); + const type = await fileTypeFromBuffer(file); res.set("Content-Type", type?.mime); res.set("Cache-Control", "public, max-age=31536000"); @@ -99,7 +99,7 @@ export const getAvatar = async (req: Request, res: Response) => { const file = await storage.get(path); if (!file) throw new HTTPError("not found", 404); - const type = await FileType.fromBuffer(file); + const type = await fileTypeFromBuffer(file); res.set("Content-Type", type?.mime); res.set("Cache-Control", "public, max-age=31536000"); diff --git a/src/cdn/routes/badge-icons.ts b/src/cdn/routes/badge-icons.ts index 04e96f2f..44dd4c8f 100644 --- a/src/cdn/routes/badge-icons.ts +++ b/src/cdn/routes/badge-icons.ts @@ -18,7 +18,7 @@ import { Router, Response, Request } from "express"; import { storage } from "../util/Storage"; -import FileType from "file-type"; +import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server"; const router = Router(); @@ -29,7 +29,7 @@ router.get("/:badge_id", async (req: Request, res: Response) => { const file = await storage.get(path); if (!file) throw new HTTPError("not found", 404); - const type = await FileType.fromBuffer(file); + const type = await fileTypeFromBuffer(file); res.set("Content-Type", type?.mime); res.set("Cache-Control", "public, max-age=31536000, must-revalidate"); diff --git a/src/cdn/routes/embed.ts b/src/cdn/routes/embed.ts index 95ac720d..d0bb620f 100644 --- a/src/cdn/routes/embed.ts +++ b/src/cdn/routes/embed.ts @@ -17,7 +17,7 @@ */ import { Request, Response, Router } from "express"; -import FileType from "file-type"; +import { fileTypeFromBuffer } from "file-type"; import fs from "fs/promises"; import { HTTPError } from "lambert-server"; import { join } from "path"; @@ -75,7 +75,7 @@ router.get("/avatars/:id", async (req: Request, res: Response) => { const file = await getFile(path); if (!file) throw new HTTPError("not found", 404); - const type = await FileType.fromBuffer(file); + const type = await fileTypeFromBuffer(file); res.set("Content-Type", type?.mime); res.set("Cache-Control", "public, max-age=31536000"); @@ -100,7 +100,7 @@ router.get("/group-avatars/:id", async (req: Request, res: Response) => { const file = await getFile(path); if (!file) throw new HTTPError("not found", 404); - const type = await FileType.fromBuffer(file); + const type = await fileTypeFromBuffer(file); res.set("Content-Type", type?.mime); res.set("Cache-Control", "public, max-age=31536000"); diff --git a/src/cdn/routes/guild-profiles.ts b/src/cdn/routes/guild-profiles.ts index 1ee5eeca..4fcf1f39 100644 --- a/src/cdn/routes/guild-profiles.ts +++ b/src/cdn/routes/guild-profiles.ts @@ -19,7 +19,7 @@ import { Config, Snowflake } from "@spacebar/util"; import crypto from "crypto"; import { Request, Response, Router } from "express"; -import FileType from "file-type"; +import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server"; import { multer } from "../util/multer"; import { storage } from "../util/Storage"; @@ -53,7 +53,7 @@ router.post("/", multer.single("file"), async (req: Request, res: Response) => { .update(Snowflake.generate()) .digest("hex"); - const type = await FileType.fromBuffer(buffer); + const type = await fileTypeFromBuffer(buffer); 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 @@ -79,7 +79,7 @@ router.get("/", async (req: Request, res: Response) => { const file = await storage.get(path); if (!file) throw new HTTPError("not found", 404); - const type = await FileType.fromBuffer(file); + const type = await fileTypeFromBuffer(file); res.set("Content-Type", type?.mime); res.set("Cache-Control", "public, max-age=31536000"); @@ -95,7 +95,7 @@ router.get("/:hash", async (req: Request, res: Response) => { const file = await storage.get(path); if (!file) throw new HTTPError("not found", 404); - const type = await FileType.fromBuffer(file); + const type = await fileTypeFromBuffer(file); res.set("Content-Type", type?.mime); res.set("Cache-Control", "public, max-age=31536000"); diff --git a/src/cdn/routes/role-icons.ts b/src/cdn/routes/role-icons.ts index 8040405a..2d4f662c 100644 --- a/src/cdn/routes/role-icons.ts +++ b/src/cdn/routes/role-icons.ts @@ -19,7 +19,7 @@ import { Router, Response, Request } from "express"; import { Config, Snowflake } from "@spacebar/util"; import { storage } from "../util/Storage"; -import FileType from "file-type"; +import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server"; import crypto from "crypto"; import { multer } from "../util/multer"; @@ -56,7 +56,7 @@ router.post( .update(Snowflake.generate()) .digest("hex"); - const type = await FileType.fromBuffer(buffer); + const type = await fileTypeFromBuffer(buffer); if (!type || !ALLOWED_MIME_TYPES.includes(type.mime)) throw new HTTPError("Invalid file type"); @@ -82,7 +82,7 @@ router.get("/:role_id", async (req: Request, res: Response) => { const file = await storage.get(path); if (!file) throw new HTTPError("not found", 404); - const type = await FileType.fromBuffer(file); + const type = await fileTypeFromBuffer(file); res.set("Content-Type", type?.mime); res.set("Cache-Control", "public, max-age=31536000, must-revalidate"); @@ -114,7 +114,7 @@ router.get("/:role_id/:hash", async (req: Request, res: Response) => { } if (!file) throw new HTTPError("not found", 404); - const type = await FileType.fromBuffer(file); + const type = await fileTypeFromBuffer(file); res.set("Content-Type", type?.mime); res.set("Cache-Control", "public, max-age=31536000, must-revalidate");