From 4e506dcf768bc9bf2c1cee1dcd84c31bef0f54c0 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 5 Feb 2024 09:47:58 -0800 Subject: [PATCH] feat: also check content-type with @sgtpooki/file-type --- packages/verified-fetch/package.json | 1 + packages/verified-fetch/src/utils/get-content-type.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/packages/verified-fetch/package.json b/packages/verified-fetch/package.json index 007cb8d94..b98d1510d 100644 --- a/packages/verified-fetch/package.json +++ b/packages/verified-fetch/package.json @@ -155,6 +155,7 @@ "@ipld/dag-pb": "^4.0.8", "@libp2p/interface": "^1.1.2", "@libp2p/peer-id": "^4.0.5", + "@sgtpooki/file-type": "^1.0.0-1e871f8", "hashlru": "^2.3.0", "ipfs-unixfs-exporter": "^13.4.0", "mime-types": "^2.1.35", diff --git a/packages/verified-fetch/src/utils/get-content-type.ts b/packages/verified-fetch/src/utils/get-content-type.ts index 9552f9ed7..8850fcf3f 100644 --- a/packages/verified-fetch/src/utils/get-content-type.ts +++ b/packages/verified-fetch/src/utils/get-content-type.ts @@ -1,3 +1,4 @@ +import { fileTypeFromBuffer } from '@sgtpooki/file-type' import mime from 'mime-types' interface TestInput { @@ -20,6 +21,8 @@ const tests: Array<(input: TestInput) => TestOutput> = [ async ({ bytes }): TestOutput => xmlRegex.test(new TextDecoder().decode(bytes.slice(0, 64))) ? 'image/svg+xml' : undefined, + // testing file-type from buffer + async ({ bytes }): TestOutput => (await fileTypeFromBuffer(bytes))?.mime, // testing file-type from path async ({ path }): TestOutput => { const mimeType = mime.lookup(path)