From 6ea0ac234588bdbbeb7680f6b6bbd2a53cc3261d Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 3 Nov 2013 14:04:01 -0500 Subject: [PATCH] Don't try to index non-text files when importing from document Also call the callback when importing PDFs from the document. I'm not sure why this wasn't called before, but it seems like it should be. --- chrome/content/zotero/xpcom/attachments.js | 26 ++++++++++------------ chrome/content/zotero/xpcom/fulltext.js | 12 +++++++--- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 8e74bb8195..d62a7579be 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -486,7 +486,7 @@ Zotero.Attachments = new function(){ // No file, so no point running the PDF indexer //Zotero.Fulltext.indexItems([itemID]); } - else { + else if (Zotero.MIME.isTextType(document.contentType)) { Zotero.Fulltext.indexDocument(document, itemID); } }, 50); @@ -563,22 +563,20 @@ Zotero.Attachments = new function(){ 100 //make sure this matches WPD settings in webpagedump/common.js ); file.append(fileName) - - if (mimeType == 'application/pdf') { - var f = function() { + + var f = function() { + if (mimeType == 'application/pdf') { Zotero.Fulltext.indexPDF(file, itemID); Zotero.Notifier.trigger('refresh', 'item', itemID); - }; - } - else { - var f = function() { + } + if (Zotero.MIME.isTextType(mimeType)) { Zotero.Fulltext.indexDocument(document, itemID); Zotero.Notifier.trigger('refresh', 'item', itemID); - if (callback) { - callback(attachmentItem); - } - }; - } + } + if (callback) { + callback(attachmentItem); + } + }; if (mimeType === 'text/html' || mimeType === 'application/xhtml+xml') { var sync = true; @@ -1445,7 +1443,7 @@ Zotero.Attachments = new function(){ } var ext = Zotero.File.getExtension(file); - if (!Zotero.MIME.hasInternalHandler(mimeType, ext)) { + if (!Zotero.MIME.hasInternalHandler(mimeType, ext) || !Zotero.MIME.isTextType(mimeType)) { return; } diff --git a/chrome/content/zotero/xpcom/fulltext.js b/chrome/content/zotero/xpcom/fulltext.js index 559397d2c1..9a21aeb111 100644 --- a/chrome/content/zotero/xpcom/fulltext.js +++ b/chrome/content/zotero/xpcom/fulltext.js @@ -297,13 +297,18 @@ Zotero.Fulltext = new function(){ Zotero.debug("Indexing document '" + document.title + "'"); + if (!Zotero.MIME.isTextType(document.contentType)) { + Zotero.debug(document.contentType + " document is not text", 2); + return false; + } + if (!document.body) { - Zotero.debug("Cannot index " + document.contentType + " file in indexDocument()", 2); + Zotero.debug("Cannot index " + document.contentType + " file", 2); return false; } if (!document.characterSet){ - Zotero.debug("Text file didn't have charset in indexFile()", 1); + Zotero.debug("Text file didn't have charset", 2); return false; } @@ -356,7 +361,7 @@ Zotero.Fulltext = new function(){ } } - if (mimeType.substr(0, 5)!='text/'){ + if (!Zotero.MIME.isTextType(mimeType)) { Zotero.debug('File is not text in indexFile()', 2); return false; } @@ -405,6 +410,7 @@ Zotero.Fulltext = new function(){ */ function indexPDF(file, itemID, allPages) { if (!_pdfConverter) { + Zotero.debug("PDF tools are not installed -- skipping indexing"); return false; }