From 3a0bded7f2c704c6587d06e7de7ce0578b50ae02 Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 29 Sep 2025 21:22:46 +0200 Subject: [PATCH] Update file-type --- package-lock.json | Bin 426543 -> 429971 bytes package.json | 2 +- src/cdn/routes/attachments.ts | 6 +++--- src/cdn/routes/avatars.ts | 8 ++++---- src/cdn/routes/badge-icons.ts | 4 ++-- src/cdn/routes/embed.ts | 6 +++--- src/cdn/routes/guild-profiles.ts | 8 ++++---- src/cdn/routes/role-icons.ts | 8 ++++---- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index f8aed44db217552bbc4a1576cb81effdc88d379d..301b0ff7789898efce9e6f9ec949f83bb6204938 100644 GIT binary patch delta 1553 zcmZuxS!~;M7?-cK>xS0upk>`?n~iCZCbn}rlg5aXG;!`UaW0{)PU0NSWjjZcJn_I7 zFHDST{H49nJxoZ@iA|F*(lh}A2?>y32NUW8^a1e(8lb@gNZ_<#MH_zl?B6GS{(i^z z-pdD8-a2sgB0O@+NE!$Oas3i}=gWy~L*|#uExg5dTl!oh&jYA}?FXxSP!ynEh?sk< zA&2X?yK{O1NIyY`SxW$K)7_fDIhmBDL}hgCwyxr^)6qaBhbOCqmGvxII3cvyZR_xq z(5TavGUXGC3qd&|m;$M|GvXk`4%O?joh)0{MO!702V6p+8F1MNsc41wgrq82XvP?#80?XqQYRD-Wm!q?>cmXJm#BejpTicgaTS>yFKkZM z9-q~oA`Fx|_2e2d1%8;oCcx?$^dQ)ngGRvfA3z!qK8I{GsEi+l|Kz~O&%7IQ2_c_w6RCC+>VcNV%W_s>Y zpXQjT7!^4=PcK;d6!_%|iYw2)jeL(lMgU#LOdxy(!S=Lz;(+l&xytJYwO(a>A994{ zE0%63WlYoQYN}LbQ|+?Jh0`g{6v#`FS|i}I$&$Nk%=&#cw}W*TYN=w9aB)qWD`ySK z_FzZi!gWR}M-oIWQ^94N6+@0K#&_PscIt)_4=FbqY})y;9qOZPwq(^3rcHoU4KNhr zh;neX)7z8+EUm&L zVCD`s36{A}1>;lD z=>IqpZ2XRmDfjPT;t9wKAg@Zs%0A5jwcb1}m6AP>V3J;ovmUUT7_mSIr7F$z2(~E) z1w7<)6~tzbj7i~CHQ;wAdZ|=et}k>K;$$xzPA5Ec%pvlLx)52$n{?ko7u#j=d*!UYgru<54 HPMrJ)n}P+I delta 275 zcmbO{Uuu1e)P`A1>~)4_dZv0Nn-?-&J~Mg#CB@0}FS2fyx~OQ`zFdHD`*H!M1lj32 zifkO)B@LKfBu-bzWES79JBjJmpXmm(m}RE-3$e*e59w$AI(>pVtL*mb3CvFvwx?`j zzQ;U0i;MB`bO%;Ov1!+tIj8TcWfht}nVa#>^!_c(tnEQNn70S*V7Xs0Jzy1+()9dx z7V+)%hOG8l(*puo<+gu}X1%Qd(=5E5tCsZ=6PPQ)& 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");