Skip to content

Commit

Permalink
fix:Added fallback type as application/octet-stream (#555)
Browse files Browse the repository at this point in the history
Co-authored-by: SethK <[email protected]>
  • Loading branch information
sethk4783 and SethK committed Mar 13, 2024
1 parent 518cdaf commit f5d5cdb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,21 @@ export const uniqueId = (len: number = 10): string => {
*/
export const getMimetype = async(file: Uint8Array | Buffer, name?: string): Promise<string> => {
let type;

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

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

if (mime) {
return mime;
}
}

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

if (type && excludedMimetypes.indexOf(type.mime) === -1) {
Expand All @@ -137,6 +140,7 @@ export const getMimetype = async(file: Uint8Array | Buffer, name?: string): Prom
return type.mime;
}

return 'application/octet-stream';
};

/**
Expand Down

0 comments on commit f5d5cdb

Please sign in to comment.