Fixes #901, downloadAssociatedFiles pref has no effect if automaticSnapshots is false
Cleaner version of zeppomedio's patch, with an additional check to not save links when automaticSnapshots is off (since that code would now be executed even if only downloadAssociatedFiles was checked) I haven't tested this extensively, but the settings seem to now work as expected. Thanks to zeppomedio for the patch.
This commit is contained in:
parent
ab958ae726
commit
b0d576b089
|
@ -1285,14 +1285,21 @@ Zotero.Translate.prototype._itemDone = function(item, attachedTo) {
|
|||
}
|
||||
}
|
||||
|
||||
var automaticSnapshots = Zotero.Prefs.get("automaticSnapshots");
|
||||
var downloadAssociatedFiles = Zotero.Prefs.get("downloadAssociatedFiles");
|
||||
|
||||
// handle attachments
|
||||
if(item.attachments && Zotero.Prefs.get("automaticSnapshots")) {
|
||||
if(item.attachments && (automaticSnapshots || downloadAssociatedFiles)) {
|
||||
for each(var attachment in item.attachments) {
|
||||
if(this.type == "web") {
|
||||
if(!attachment.url && !attachment.document) {
|
||||
Zotero.debug("Translate: not adding attachment: no URL specified");
|
||||
} else {
|
||||
if(attachment.snapshot === false) {
|
||||
if(!automaticSnapshots) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// if snapshot is explicitly set to false, attach as link
|
||||
if(attachment.document) {
|
||||
Zotero.Attachments.linkFromURL(attachment.document.location.href, myID,
|
||||
|
@ -1313,7 +1320,7 @@ Zotero.Translate.prototype._itemDone = function(item, attachedTo) {
|
|||
}
|
||||
} else if(attachment.document
|
||||
|| (attachment.mimeType && attachment.mimeType == "text/html")
|
||||
|| Zotero.Prefs.get("downloadAssociatedFiles")) {
|
||||
|| downloadAssociatedFiles) {
|
||||
// if snapshot is not explicitly set to false, retrieve snapshot
|
||||
if(attachment.document) {
|
||||
try {
|
||||
|
@ -1321,10 +1328,10 @@ Zotero.Translate.prototype._itemDone = function(item, attachedTo) {
|
|||
} catch(e) {
|
||||
Zotero.debug("Translate: error attaching document");
|
||||
}
|
||||
} else {
|
||||
} else if(attachment.url != item.url || automaticSnapshots) {
|
||||
var mimeType = null;
|
||||
var title = null;
|
||||
|
||||
|
||||
if(attachment.mimeType) {
|
||||
// first, try to extract mime type from mimeType attribute
|
||||
mimeType = attachment.mimeType;
|
||||
|
@ -1332,24 +1339,24 @@ Zotero.Translate.prototype._itemDone = function(item, attachedTo) {
|
|||
// if that fails, use document if possible
|
||||
mimeType = attachment.document.contentType
|
||||
}
|
||||
|
||||
|
||||
// same procedure for title as mime type
|
||||
if(attachment.title) {
|
||||
title = attachment.title;
|
||||
} else if(attachment.document && attachment.document.title) {
|
||||
title = attachment.document.title;
|
||||
}
|
||||
|
||||
|
||||
if(this.locationIsProxied) {
|
||||
attachment.url = Zotero.Ingester.ProxyMonitor.properToProxy(attachment.url);
|
||||
}
|
||||
|
||||
|
||||
var fileBaseName = Zotero.Attachments.getFileBaseNameFromItem(myID);
|
||||
try {
|
||||
Zotero.Attachments.importFromURL(attachment.url, myID, title, fileBaseName);
|
||||
} catch(e) {
|
||||
Zotero.debug("Zotero.Translate: error adding attachment "+attachment.url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user