From e2f9403f63f6ac25d6fd90f08ae3b8dcb3fb878c Mon Sep 17 00:00:00 2001 From: mpl Date: Thu, 27 Jun 2013 16:30:09 +0200 Subject: [PATCH] ui/blobinfo.js: check mimeType presence to avoid exception http://camlistore.org/issue/165 Change-Id: Ie1ee86b5cc7807786d428efb92f2f571dd0450f2 --- server/camlistored/ui/blobinfo.js | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/server/camlistored/ui/blobinfo.js b/server/camlistored/ui/blobinfo.js index aa0b09924..ee8f80a2f 100644 --- a/server/camlistored/ui/blobinfo.js +++ b/server/camlistored/ui/blobinfo.js @@ -127,25 +127,25 @@ function(bmap) { if (binfo.camliType == "file") { // TODO(mpl): we can't get the thumnails url in a describe // response because the server only gives it for a permanode. - // That's why we do this messy business here. Fix it server side. - try { - finfo = JSON.parse(data); - bd.innerHTML = ""; - var fileName = finfo.fileName || blobref; - bd.firstChild.href = "./download/" + blobref + "/" + fileName; - if (binfo.file.mimeType.indexOf("image/") == 0) { - var thumbURL = ""; - goog.dom.getElement("thumbnail").innerHTML = thumbURL; - } else { - goog.dom.getElement("thumbnail").innerHTML = ""; - } - goog.dom.setTextContent(bd.firstChild, fileName); - bd.innerHTML = "download: " + bd.innerHTML; - } catch (x) { - // TOD(mpl): why? + // That's why we do this messy business here. Fix it server side. + finfo = JSON.parse(data); + bd.innerHTML = ""; + var fileName = finfo.fileName || blobref; + bd.firstChild.href = "./download/" + blobref + "/" + fileName; + // If the mime type was not detected by magic pkg, we end up + // with an empty mimetype value in the indexer's fileinfo, + // hence no mimeType in the returned JSON. + if (!!binfo.file.mimeType && + binfo.file.mimeType.indexOf("image/") == 0) { + var thumbURL = ""; + goog.dom.getElement("thumbnail").innerHTML = thumbURL; + } else { + goog.dom.getElement("thumbnail").innerHTML = ""; } + goog.dom.setTextContent(bd.firstChild, fileName); + bd.innerHTML = "download: " + bd.innerHTML; } }, this), alert