Skip to content

Commit fe736c9

Browse files
committed
fix: bump file-type to avoid CVEs
Signed-off-by: Lídia Tarcza <100163235+diatrcz@users.noreply.github.com>
1 parent 8836081 commit fe736c9

4 files changed

Lines changed: 98 additions & 154 deletions

File tree

lib/helper.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import { isReadable } from 'isstream';
1818
import { lookup } from 'mime-types';
1919
import { basename } from 'path';
20+
import { loadEsm } from "load-esm";
2021
import logger from './logger';
2122

22-
const FileType = require('file-type');
2323

2424
export interface FileObject {
2525
value: NodeJS.ReadableStream | Buffer | string;
@@ -76,7 +76,17 @@ export async function getContentType(inputData: NodeJS.ReadableStream | Buffer):
7676
contentType = { mime: mimeType || null };
7777
} else if (Buffer.isBuffer(inputData)) {
7878
// if the inputData is a Buffer
79-
contentType = await FileType.fromBuffer(inputData);
79+
try {
80+
// Import a pure ESM package from a CommonJS TS project
81+
const { fileTypeFromBuffer } = await loadEsm<typeof import("file-type")>(
82+
"file-type"
83+
);
84+
85+
contentType = await fileTypeFromBuffer(inputData);
86+
logger.debug(contentType);
87+
} catch (error) {
88+
logger.debug("Error importing module:", error);
89+
}
8090
}
8191

8292
return contentType ? contentType.mime : null;

package-lock.json

Lines changed: 82 additions & 149 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)