Skip to content

Commit e0299f3

Browse files
committed
Remove mime-types/mime-db dependency
1 parent 9928152 commit e0299f3

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": false,
33
"name": "html5-file-selector",
4-
"version": "1.0.2",
4+
"version": "2.0.0",
55
"description": "A wrapper library for more easily handling html5 drag/drop and file input file and folder selections",
66
"homepage": "https://www.github.com/quarklemotion/html5-file-selector",
77
"repository": "quarklemotion/html5-file-selector",
@@ -27,8 +27,7 @@
2727
"extends": "airbnb-base"
2828
},
2929
"dependencies": {
30-
"babel-runtime": "6.11.x",
31-
"mime-types": "2.1.x"
30+
"babel-runtime": "6.11.x"
3231
},
3332
"devDependencies": {
3433
"babel-cli": "6.16.x",

src/Html5FileSelector.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1-
import mimeTypes from 'mime-types';
2-
31
const DEFAULT_FILES_TO_IGNORE = [
42
'.DS_Store', // OSX indexing file
53
'Thumbs.db' // Windows indexing file
64
];
75

6+
// map of common (mostly media types) mime types to use when the browser does not supply the mime type
7+
const EXTENSION_TO_MIME_TYPE_MAP = {
8+
avi: 'video/avi',
9+
gif: 'image/gif',
10+
ico: 'image/x-icon',
11+
jpeg: 'image/jpeg',
12+
jpg: 'image/jpeg',
13+
mkv: 'video/x-matroska',
14+
mov: 'video/quicktime',
15+
mp4: 'video/mp4',
16+
pdf: 'application/pdf',
17+
png: 'image/png',
18+
zip: 'application/zip'
19+
};
20+
821
function shouldIgnoreFile(file) {
922
return DEFAULT_FILES_TO_IGNORE.indexOf(file.name) >= 0;
1023
}
1124

25+
function copyString(aString) {
26+
return ` ${aString}`.slice(1);
27+
}
28+
1229
function traverseDirectory(entry) {
1330
const reader = entry.createReader();
1431
// Resolved when the entire directory is traversed
@@ -48,14 +65,18 @@ function packageFile(file, entry) {
4865
// handle some browsers sometimes missing mime types for dropped files
4966
const hasExtension = file.name && file.name.lastIndexOf('.') !== -1;
5067
if (hasExtension && !file.type) {
51-
fileTypeOverride = mimeTypes.lookup(file.name);
68+
const fileExtension = (file.name || '').split('.').pop();
69+
fileTypeOverride = EXTENSION_TO_MIME_TYPE_MAP[fileExtension];
5270
}
5371
return {
54-
fileObject: file,
55-
type: file.type ? file.type : fileTypeOverride,
72+
fileObject: file, // provide access to the raw File object (required for uploading)
73+
fullPath: entry ? copyString(entry.fullPath) : file.name,
74+
lastModified: file.lastModified,
75+
lastModifiedDate: file.lastModifiedDate,
5676
name: file.name,
5777
size: file.size,
58-
fullPath: entry ? entry.fullPath : file.name
78+
type: file.type ? file.type : fileTypeOverride,
79+
webkitRelativePath: file.webkitRelativePath
5980
};
6081
}
6182

0 commit comments

Comments
 (0)