File tree Expand file tree Collapse file tree 1 file changed +18
-9
lines changed
Expand file tree Collapse file tree 1 file changed +18
-9
lines changed Original file line number Diff line number Diff line change 1- import { fileTypeFromBuffer } from "file-type" ;
21import type {
32 AudioContent ,
43 BlobResourceContents ,
@@ -45,14 +44,14 @@ export function resourceLink(
4544
4645export type ContentOptions =
4746 | {
48- url : string ;
49- }
47+ url : string ;
48+ }
5049 | {
51- buffer : Buffer ;
52- }
50+ buffer : Buffer ;
51+ }
5352 | {
54- path : string ;
55- } ;
53+ path : string ;
54+ } ;
5655
5756export async function imageContent (
5857 content : ContentOptions ,
@@ -70,7 +69,7 @@ export async function imageContent(
7069 throw new Error ( "Invalid content options" ) ;
7170 }
7271
73- const mimeType = await fileTypeFromBuffer ( rawData ) ;
72+ const mimeType = await getMimeType ( rawData ) ;
7473
7574 const base64Data = rawData . toString ( "base64" ) ;
7675
@@ -98,7 +97,7 @@ export async function audioContent(
9897 throw new Error ( "Invalid content options" ) ;
9998 }
10099
101- const mimeType = await fileTypeFromBuffer ( rawData ) ;
100+ const mimeType = await getMimeType ( rawData ) ;
102101
103102 const base64Data = rawData . toString ( "base64" ) ;
104103
@@ -134,3 +133,13 @@ async function loadFromPath(path: string) {
134133 throw new Error ( "muppet: Unable to import 'fs' module." ) ;
135134 }
136135}
136+
137+ async function getMimeType ( buffer : Buffer ) {
138+ try {
139+ const { fileTypeFromBuffer } = await import ( "file-type" ) ;
140+
141+ return fileTypeFromBuffer ( buffer ) ;
142+ } catch ( error ) {
143+ throw new Error ( "muppet: Unable to import 'file-type' module." ) ;
144+ }
145+ }
You can’t perform that action at this time.
0 commit comments