From 22dc431ee0230e9b7455f6f7a1eaebdf93dab439 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Fri, 16 Aug 2019 01:16:04 -0400 Subject: [PATCH] remove mime --- dist/bundle.es.js | 36 +++++++++++++------------------- flow-typed/mime.js | 4 ---- package.json | 1 - src/lbry.js | 51 +++++++++++++++++++--------------------------- yarn.lock | 5 ----- 5 files changed, 35 insertions(+), 62 deletions(-) delete mode 100644 flow-typed/mime.js diff --git a/dist/bundle.es.js b/dist/bundle.es.js index baa40ce..fbd32c8 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } require('proxy-polyfill'); -var mime = _interopDefault(require('mime')); var reselect = require('reselect'); var uuid = _interopDefault(require('uuid/v4')); @@ -692,29 +691,22 @@ const Lbry = { // Returns a human readable media type based on the content type or extension of a file that is returned by the sdk getMediaType: (contentType, fileName) => { - const formats = [[/\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], [/\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], [/\.(h|go|ja|java|js|jsx|c|cpp|cs|css|rb|scss|sh|php|py)$/i, 'script'], [/\.(json|csv|txt|log|md|markdown|docx|pdf|xml|yml|yaml)$/i, 'document'], [/\.(pdf|odf|doc|docx|epub|org|rtf)$/i, 'e-book'], [/\.(stl|obj|fbx|gcode)$/i, '3D-file'], [/\.(cbr|cbt|cbz)$/i, 'comic-book']]; + if (fileName) { + const formats = [[/\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], [/\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], [/\.(h|go|ja|java|js|jsx|c|cpp|cs|css|rb|scss|sh|php|py)$/i, 'script'], [/\.(json|csv|txt|log|md|markdown|docx|pdf|xml|yml|yaml)$/i, 'document'], [/\.(pdf|odf|doc|docx|epub|org|rtf)$/i, 'e-book'], [/\.(stl|obj|fbx|gcode)$/i, '3D-file'], [/\.(cbr|cbt|cbz)$/i, 'comic-book']]; - const extName = mime.getExtension(contentType); - const fileExt = extName ? `.${extName}` : null; - const testString = fileName || fileExt; - - // Get mediaType from file extension - if (testString) { const res = formats.reduce((ret, testpair) => { - const [regex, mediaType] = testpair; - - return regex.test(ret) ? mediaType : ret; - }, testString); - - if (res !== testString) return res; - } - - // Get mediaType from contentType - if (contentType) { - const matches = /^[^/]+/.exec(contentType); - if (matches) { - return matches[0]; - } + switch (testpair[0].test(ret)) { + case true: + return testpair[1]; + default: + return ret; + } + }, fileName); + return res === fileName ? 'unknown' : res; + } else if (contentType) { + // $FlowFixMe + return (/^[^/]+/.exec(contentType)[0] + ); } return 'unknown'; diff --git a/flow-typed/mime.js b/flow-typed/mime.js deleted file mode 100644 index 476b179..0000000 --- a/flow-typed/mime.js +++ /dev/null @@ -1,4 +0,0 @@ -// @flow -declare module 'mime' { - declare module.exports: any; -} diff --git a/package.json b/package.json index 8cba56d..21b595f 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "format": "prettier 'src/**/*.{js,json}' --write" }, "dependencies": { - "mime": "^2.4.4", "proxy-polyfill": "0.1.6", "reselect": "^3.0.0", "uuid": "^3.3.2" diff --git a/src/lbry.js b/src/lbry.js index b87a8a2..6313063 100644 --- a/src/lbry.js +++ b/src/lbry.js @@ -1,6 +1,5 @@ // @flow import 'proxy-polyfill'; -import mime from 'mime'; const CHECK_DAEMON_STARTED_TRY_NUMBER = 200; // @@ -34,37 +33,29 @@ const Lbry: LbryTypes = { // Returns a human readable media type based on the content type or extension of a file that is returned by the sdk getMediaType: (contentType?: string, fileName: ?string) => { - const formats = [ - [/\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], - [/\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], - [/\.(h|go|ja|java|js|jsx|c|cpp|cs|css|rb|scss|sh|php|py)$/i, 'script'], - [/\.(json|csv|txt|log|md|markdown|docx|pdf|xml|yml|yaml)$/i, 'document'], - [/\.(pdf|odf|doc|docx|epub|org|rtf)$/i, 'e-book'], - [/\.(stl|obj|fbx|gcode)$/i, '3D-file'], - [/\.(cbr|cbt|cbz)$/i, 'comic-book'], - ]; + if (fileName) { + const formats = [ + [/\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], + [/\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], + [/\.(h|go|ja|java|js|jsx|c|cpp|cs|css|rb|scss|sh|php|py)$/i, 'script'], + [/\.(json|csv|txt|log|md|markdown|docx|pdf|xml|yml|yaml)$/i, 'document'], + [/\.(pdf|odf|doc|docx|epub|org|rtf)$/i, 'e-book'], + [/\.(stl|obj|fbx|gcode)$/i, '3D-file'], + [/\.(cbr|cbt|cbz)$/i, 'comic-book'], + ]; - const extName = mime.getExtension(contentType); - const fileExt = extName ? `.${extName}` : null; - const testString = fileName || fileExt; - - // Get mediaType from file extension - if (testString) { const res = formats.reduce((ret, testpair) => { - const [regex, mediaType] = testpair; - - return regex.test(ret) ? mediaType : ret; - }, testString); - - if (res !== testString) return res; - } - - // Get mediaType from contentType - if (contentType) { - const matches = /^[^/]+/.exec(contentType); - if (matches) { - return matches[0]; - } + switch (testpair[0].test(ret)) { + case true: + return testpair[1]; + default: + return ret; + } + }, fileName); + return res === fileName ? 'unknown' : res; + } else if (contentType) { + // $FlowFixMe + return /^[^/]+/.exec(contentType)[0]; } return 'unknown'; diff --git a/yarn.lock b/yarn.lock index 182afdc..49dc513 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3523,11 +3523,6 @@ mime-types@^2.1.12, mime-types@~2.1.17: dependencies: mime-db "~1.33.0" -mime@^2.4.4: - version "2.4.4" - resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.4.tgz#bd7b91135fc6b01cde3e9bae33d659b63d8857e5" - integrity sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA== - mimic-fn@^1.0.0: version "1.2.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"