From bc129eb3479bd195e633be02aa9dfe4a6784a158 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 2 Sep 2016 04:48:01 -0400 Subject: [PATCH] Make lbry.getMediaType() able to use MIME type as well as file name --- js/lbry.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/js/lbry.js b/js/lbry.js index 381dde98f..c783748e6 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -283,21 +283,25 @@ lbry.imagePath = function(file) return lbry.rootPath + '/img/' + file; } -lbry.getMediaType = function(filename) { - var dotIndex = filename.lastIndexOf('.'); - if (dotIndex == -1) { - return 'unknown'; - } - - var ext = filename.substr(dotIndex + 1); - if (/^mp4|mov|m4v|flv|f4v$/i.test(ext)) { - return 'video'; - } else if (/^mp3|m4a|aac|wav|flac|ogg$/i.test(ext)) { - return 'audio'; - } else if (/^html|htm|pdf|odf|doc|docx|md|markdown|txt$/i.test(ext)) { - return 'document'; +lbry.getMediaType = function(contentType, fileName) { + if (contentType) { + return /^[^/]+/.exec(contentType); } else { - return 'unknown'; + var dotIndex = filename.lastIndexOf('.'); + if (dotIndex == -1) { + return 'unknown'; + } + + var ext = filename.substr(dotIndex + 1); + if (/^mp4|mov|m4v|flv|f4v$/i.test(ext)) { + return 'video'; + } else if (/^mp3|m4a|aac|wav|flac|ogg$/i.test(ext)) { + return 'audio'; + } else if (/^html|htm|pdf|odf|doc|docx|md|markdown|txt$/i.test(ext)) { + return 'document'; + } else { + return 'unknown'; + } } }