From 6eba5f88230bc4c5a7071c48da58e38731a3b61c Mon Sep 17 00:00:00 2001 From: Baltazar Gomez Date: Wed, 4 Jul 2018 17:06:13 -0600 Subject: [PATCH 1/2] update lbry.getMediaType function logic --- src/lbry.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lbry.js b/src/lbry.js index b4982cb..c220c34 100644 --- a/src/lbry.js +++ b/src/lbry.js @@ -110,9 +110,7 @@ Lbry.connect = () => { }; Lbry.getMediaType = (contentType, fileName) => { - if (contentType) { - return /^[^/]+/.exec(contentType)[0]; - } else if (fileName) { + if (fileName) { const formats = [ [/^.+\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], [/^.+\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], @@ -128,7 +126,9 @@ Lbry.getMediaType = (contentType, fileName) => { } }, fileName); return res === fileName ? 'unknown' : res; - } + } else if (contentType) { + return /^[^/]+/.exec(contentType)[0]; + } return 'unknown'; }; From 6a21ea7d72eca245c6b275d827b8cbeed6d5956c Mon Sep 17 00:00:00 2001 From: Baltazar Gomez Date: Thu, 5 Jul 2018 12:20:41 -0600 Subject: [PATCH 2/2] use file extension for media detection --- src/lbry.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lbry.js b/src/lbry.js index c220c34..c40b22e 100644 --- a/src/lbry.js +++ b/src/lbry.js @@ -109,13 +109,13 @@ Lbry.connect = () => { return Lbry.connectPromise; }; -Lbry.getMediaType = (contentType, fileName) => { - 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)) { @@ -124,8 +124,8 @@ 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]; }