commit
189b11ac50
1 changed files with 11 additions and 11 deletions
20
src/lbry.js
20
src/lbry.js
|
@ -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)) {
|
||||
|
@ -126,8 +124,10 @@ 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';
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue