commit
4f812db1c7
5 changed files with 35 additions and 62 deletions
36
dist/bundle.es.js
vendored
36
dist/bundle.es.js
vendored
|
@ -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';
|
||||
|
|
4
flow-typed/mime.js
vendored
4
flow-typed/mime.js
vendored
|
@ -1,4 +0,0 @@
|
|||
// @flow
|
||||
declare module 'mime' {
|
||||
declare module.exports: any;
|
||||
}
|
|
@ -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"
|
||||
|
|
51
src/lbry.js
51
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';
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue