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.
This commit is contained in:
Dan Stillman 2013-11-03 14:04:01 -05:00
parent 05fef08a63
commit 6ea0ac2345
2 changed files with 21 additions and 17 deletions

View file

@ -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;
}

View file

@ -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;
}