Update file-type
This commit is contained in:
parent
46ce140033
commit
3a0bded7f2
BIN
package-lock.json
generated
BIN
package-lock.json
generated
Binary file not shown.
@ -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",
|
||||
|
||||
@ -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";
|
||||
}
|
||||
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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");
|
||||
|
||||
Reference in New Issue
Block a user