Some snapshot-related fixes

This commit is contained in:
Simon Kornblith 2015-06-07 14:02:10 -04:00
parent aa2e0a8582
commit 38eeab06a3

View file

@ -234,7 +234,7 @@ Zotero.Attachments = new function(){
var parentItemID = options.parentItemID; var parentItemID = options.parentItemID;
var collections = options.collections; var collections = options.collections;
var title = options.title; var title = options.title;
var fileBaseName = options.forceFileBaseName; var fileBaseName = options.fileBaseName;
var contentType = options.contentType; var contentType = options.contentType;
var cookieSandbox = options.cookieSandbox; var cookieSandbox = options.cookieSandbox;
@ -280,9 +280,9 @@ Zotero.Attachments = new function(){
// Save using remote web browser persist // Save using remote web browser persist
var externalHandlerImport = Zotero.Promise.coroutine(function* (contentType) { var externalHandlerImport = Zotero.Promise.coroutine(function* (contentType) {
if (forceFileBaseName) { if (fileBaseName) {
let ext = _getExtensionFromURL(url, contentType); let ext = _getExtensionFromURL(url, contentType);
var fileName = forceFileBaseName + (ext != '' ? '.' + ext : ''); var fileName = fileBaseName + (ext != '' ? '.' + ext : '');
} }
else { else {
var fileName = _getFileNameFromURL(url, contentType); var fileName = _getFileNameFromURL(url, contentType);
@ -305,19 +305,19 @@ Zotero.Attachments = new function(){
// Save to temp dir // Save to temp dir
var deferred = Zotero.Promise.defer(); var deferred = Zotero.Promise.defer();
wbp.progressListener = new Zotero.WebProgressFinishListener(function() { wbp.progressListener = new Zotero.WebProgressFinishListener(function() {
if (contentType == 'application/pdf' && Zotero.File.getSample(tmpFile)
Zotero.MIME.sniffForMIMEType(str) != 'application/pdf') { .then(function (sample) {
let errString = "Downloaded PDF did not have MIME type " if (contentType == 'application/pdf' &&
+ "'application/pdf' in Attachments.importFromURL()"; Zotero.MIME.sniffForMIMEType(sample) != 'application/pdf') {
Zotero.debug(errString, 2); let errString = "Downloaded PDF did not have MIME type "
Zotero.File.getSample(tmpFile) + "'application/pdf' in Attachments.importFromURL()";
.then(function (sample) { Zotero.debug(errString, 2);
Zotero.debug(sample, 3); Zotero.debug(sample, 3);
deferred.reject(new Error(errString)); deferred.reject(new Error(errString));
}); } else {
return; deferred.resolve();
} }
deferred.resolve(); });
}); });
var nsIURL = Components.classes["@mozilla.org/network/standard-url;1"] var nsIURL = Components.classes["@mozilla.org/network/standard-url;1"]
@ -390,7 +390,7 @@ Zotero.Attachments = new function(){
}, 1000); }, 1000);
return attachmentItem; return attachmentItem;
}); }.bind(this));
var process = function (contentType, hasNativeHandler) { var process = function (contentType, hasNativeHandler) {
// If we can load this natively, use a hidden browser // If we can load this natively, use a hidden browser
@ -676,14 +676,16 @@ Zotero.Attachments = new function(){
// We don't have any way of knowing that the file is flushed to disk, // We don't have any way of knowing that the file is flushed to disk,
// so we just wait a second before indexing and hope for the best. // so we just wait a second before indexing and hope for the best.
// We'll index it later if it fails. (This may not be necessary.) // We'll index it later if it fails. (This may not be necessary.)
setTimeout(function () { if (contentType == 'application/pdf') {
if (contentType == 'application/pdf') { setTimeout(function () {
Zotero.Fulltext.indexPDF(file.path, attachmentItem.id); Zotero.Fulltext.indexPDF(file.path, attachmentItem.id);
} }, 1000);
else if (Zotero.MIME.isTextType(contentType)) { }
Zotero.Fulltext.indexDocument(document, attachmentItem.id); else if (Zotero.MIME.isTextType(contentType)) {
} // Index document immediately, so that browser object can't
}, 1000); // be removed before indexing completes
yield Zotero.Fulltext.indexDocument(document, attachmentItem.id);
}
return attachmentItem; return attachmentItem;
}); });