Skip to content

Commit

Permalink
fix(mimetype): getMimetype response fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sethk4783 committed Jan 20, 2025
1 parent 3cf7ebc commit 6c0615f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.10.0
v18.20.5
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,17 @@ export const getMimetype = async(file: Uint8Array | Buffer, name?: string): Prom
let type;

try {
type = await fromBuffer(file);
type = await fromBuffer(file);
} catch(e) {
console.warn("An exception occurred while processing the buffer:", e.message);
}

const excludedMimetypes = ['text/plain', 'application/octet-stream', 'application/x-ms', 'application/x-msi', 'application/zip'];

if (type && excludedMimetypes.indexOf(type.mime) === -1) {
return type.mime;
}

if (name && name.indexOf('.') > -1) {
const mime = extensionToMime(name);

Expand All @@ -118,12 +124,6 @@ export const getMimetype = async(file: Uint8Array | Buffer, name?: string): Prom
}
}

const excludedMimetypes = ['text/plain', 'application/octet-stream', 'application/x-ms', 'application/x-msi', 'application/zip'];

if (type && excludedMimetypes.indexOf(type.mime) === -1) {
return type.mime;
}

try {
if (isutf8(file)) {
return 'text/plain';
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const banner = fs.readFileSync('./LICENSE', 'utf8').replace('{year}', new Date()
const config = {
mode: 'production',
node: {
Buffer: false,
Buffer: true,
buffer: true,
fs: 'empty',
},
watchOptions: {
Expand Down

0 comments on commit 6c0615f

Please sign in to comment.