Merge pull request #51 from btzr-io/patch-1

Fix getMediaType logic
This commit is contained in:
Sean Yesmunt 2018-07-09 00:55:48 -04:00 committed by GitHub
commit 189b11ac50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -109,15 +109,13 @@ Lbry.connect = () => {
return Lbry.connectPromise; return Lbry.connectPromise;
}; };
Lbry.getMediaType = (contentType, fileName) => { Lbry.getMediaType = (contentType, extname) => {
if (contentType) { if (extname) {
return /^[^/]+/.exec(contentType)[0];
} else if (fileName) {
const formats = [ const formats = [
[/^.+\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], [/^(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'],
[/^.+\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], [/^(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'],
[/^.+\.(html|htm|xml|pdf|odf|doc|docx|md|markdown|txt|epub|org)$/i, 'document'], [/^(html|htm|xml|pdf|odf|doc|docx|md|markdown|txt|epub|org)$/i, 'document'],
[/^.+\.(stl|obj|fbx|gcode)$/i, '3D-file'], [/^(stl|obj|fbx|gcode)$/i, '3D-file'],
]; ];
const res = formats.reduce((ret, testpair) => { const res = formats.reduce((ret, testpair) => {
switch (testpair[0].test(ret)) { switch (testpair[0].test(ret)) {
@ -126,9 +124,11 @@ Lbry.getMediaType = (contentType, fileName) => {
default: default:
return ret; return ret;
} }
}, fileName); }, extname);
return res === fileName ? 'unknown' : res; return res === extname ? 'unknown' : res;
} } else if (contentType) {
return /^[^/]+/.exec(contentType)[0];
}
return 'unknown'; return 'unknown';
}; };