Skip to content

Commit

Permalink
Merge pull request #51 from btzr-io/patch-1
Browse files Browse the repository at this point in the history
Fix getMediaType logic
  • Loading branch information
Sean Yesmunt authored Jul 9, 2018
2 parents 201d78b + 6a21ea7 commit 189b11a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/lbry.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,13 @@ Lbry.connect = () => {
return Lbry.connectPromise;
};

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

Expand Down

0 comments on commit 189b11a

Please sign in to comment.