Add preference to connector to control saving attachments and PDFs via server, part 1
This commit is contained in:
parent
9817b02181
commit
c0c5695bf2
1 changed files with 36 additions and 27 deletions
|
@ -197,6 +197,8 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
} else {
|
} else {
|
||||||
Zotero.debug("Translate: Save to server complete");
|
Zotero.debug("Translate: Save to server complete");
|
||||||
|
|
||||||
|
Zotero.Prefs.getCallback(["downloadAssociatedFiles", "automaticSnapshots"],
|
||||||
|
function(prefs) {
|
||||||
if(typedArraysSupported) {
|
if(typedArraysSupported) {
|
||||||
try {
|
try {
|
||||||
var newKeys = me._getItemKeysFromServerResponse(response);
|
var newKeys = me._getItemKeysFromServerResponse(response);
|
||||||
|
@ -209,12 +211,13 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
var item = items[i], key = newKeys[i];
|
var item = items[i], key = newKeys[i];
|
||||||
if(item.attachments && item.attachments.length) {
|
if(item.attachments && item.attachments.length) {
|
||||||
me._saveAttachmentsToServer(key, me._getFileBaseNameFromItem(item),
|
me._saveAttachmentsToServer(key, me._getFileBaseNameFromItem(item),
|
||||||
item.attachments, attachmentCallback);
|
item.attachments, prefs, attachmentCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(true, items);
|
callback(true, items);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -224,11 +227,12 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
* @param {String} itemKey The key of the parent item
|
* @param {String} itemKey The key of the parent item
|
||||||
* @param {String} baseName A string to use as the base name for attachments
|
* @param {String} baseName A string to use as the base name for attachments
|
||||||
* @param {Object[]} attachments An array of attachment objects
|
* @param {Object[]} attachments An array of attachment objects
|
||||||
|
* @param {Object} prefs An object with the values of the downloadAssociatedFiles and automaticSnapshots preferences
|
||||||
* @param {Function} attachmentCallback A callback that receives information about attachment
|
* @param {Function} attachmentCallback A callback that receives information about attachment
|
||||||
* save progress. The callback will be called as attachmentCallback(attachment, false, error)
|
* save progress. The callback will be called as attachmentCallback(attachment, false, error)
|
||||||
* on failure or attachmentCallback(attachment, progressPercent) periodically during saving.
|
* on failure or attachmentCallback(attachment, progressPercent) periodically during saving.
|
||||||
*/
|
*/
|
||||||
"_saveAttachmentsToServer":function(itemKey, baseName, attachments, attachmentCallback) {
|
"_saveAttachmentsToServer":function(itemKey, baseName, attachments, prefs, attachmentCallback) {
|
||||||
var me = this,
|
var me = this,
|
||||||
uploadAttachments = [],
|
uploadAttachments = [],
|
||||||
retrieveHeadersForAttachments = attachments.length;
|
retrieveHeadersForAttachments = attachments.length;
|
||||||
|
@ -240,6 +244,7 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
* @inner
|
* @inner
|
||||||
*/
|
*/
|
||||||
var createAttachments = function() {
|
var createAttachments = function() {
|
||||||
|
if(uploadAttachments.length === 0) return;
|
||||||
var attachmentPayload = [];
|
var attachmentPayload = [];
|
||||||
for(var i=0; i<uploadAttachments.length; i++) {
|
for(var i=0; i<uploadAttachments.length; i++) {
|
||||||
var attachment = uploadAttachments[i];
|
var attachment = uploadAttachments[i];
|
||||||
|
@ -297,16 +302,6 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
delete attachment.key;
|
delete attachment.key;
|
||||||
delete attachment.data;
|
delete attachment.data;
|
||||||
|
|
||||||
if(attachment.snapshot === false && attachment.mimeType) {
|
|
||||||
// If we aren't taking a snapshot and we have the MIME type, we don't need
|
|
||||||
// to retrieve anything
|
|
||||||
attachment.linkMode = "linked_url";
|
|
||||||
uploadAttachments.push(attachment);
|
|
||||||
if(attachmentCallback) attachmentCallback(attachment, 0);
|
|
||||||
if(--retrieveHeadersForAttachments === 0) createAttachments();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var isSnapshot = false;
|
var isSnapshot = false;
|
||||||
if(attachment.mimeType) {
|
if(attachment.mimeType) {
|
||||||
switch(attachment.mimeType.toLowerCase()) {
|
switch(attachment.mimeType.toLowerCase()) {
|
||||||
|
@ -316,6 +311,20 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if((isSnapshot && !prefs.automaticSnapshots) || (!isSnapshot && !prefs.downloadAssociatedFiles)) {
|
||||||
|
// Check preferences to see if we should download this file
|
||||||
|
if(--retrieveHeadersForAttachments === 0) createAttachments();
|
||||||
|
return;
|
||||||
|
} else if(attachment.snapshot === false && attachment.mimeType) {
|
||||||
|
// If we aren't taking a snapshot and we have the MIME type, we don't need
|
||||||
|
// to retrieve anything
|
||||||
|
attachment.linkMode = "linked_url";
|
||||||
|
uploadAttachments.push(attachment);
|
||||||
|
if(attachmentCallback) attachmentCallback(attachment, 0);
|
||||||
|
if(--retrieveHeadersForAttachments === 0) createAttachments();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks headers to ensure that they reflect our expectations. When headers have
|
* Checks headers to ensure that they reflect our expectations. When headers have
|
||||||
* been checked for all attachments, creates new items on the z.org server and
|
* been checked for all attachments, creates new items on the z.org server and
|
||||||
|
|
Loading…
Reference in a new issue