Handle missing 'attachments' array in /connector/saveItems
This commit is contained in:
parent
6cb4057fee
commit
862ac5ab40
2 changed files with 8 additions and 4 deletions
|
@ -667,21 +667,24 @@ Zotero.Server.Connector.SaveItems.prototype = {
|
||||||
function (topLevelItems) {
|
function (topLevelItems) {
|
||||||
// Only return the properties the connector needs
|
// Only return the properties the connector needs
|
||||||
topLevelItems = topLevelItems.map((item) => {
|
topLevelItems = topLevelItems.map((item) => {
|
||||||
return {
|
let o = {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
title: item.title,
|
title: item.title,
|
||||||
itemType: item.itemType,
|
itemType: item.itemType,
|
||||||
contentType: item.mimeType,
|
contentType: item.mimeType,
|
||||||
mimeType: item.mimeType, // TODO: Remove
|
mimeType: item.mimeType, // TODO: Remove
|
||||||
attachments: item.attachments.map((attachment) => {
|
};
|
||||||
|
if (item.attachments) {
|
||||||
|
o.attachments = item.attachments.map((attachment) => {
|
||||||
return {
|
return {
|
||||||
id: session.id + '_' + attachment.id, // TODO: Remove prefix
|
id: session.id + '_' + attachment.id, // TODO: Remove prefix
|
||||||
title: attachment.title,
|
title: attachment.title,
|
||||||
contentType: attachment.contentType,
|
contentType: attachment.contentType,
|
||||||
mimeType: attachment.mimeType, // TODO: Remove
|
mimeType: attachment.mimeType, // TODO: Remove
|
||||||
};
|
};
|
||||||
})
|
});
|
||||||
};
|
};
|
||||||
|
return o;
|
||||||
});
|
});
|
||||||
resolve([201, "application/json", JSON.stringify({items: topLevelItems})]);
|
resolve([201, "application/json", JSON.stringify({items: topLevelItems})]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,6 +222,7 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
if (urlObjects.length) {
|
if (urlObjects.length) {
|
||||||
let title = Zotero.getString('findPDF.openAccessPDF');
|
let title = Zotero.getString('findPDF.openAccessPDF');
|
||||||
let jsonAttachment = this._makeJSONAttachment(jsonItem.id, title);
|
let jsonAttachment = this._makeJSONAttachment(jsonItem.id, title);
|
||||||
|
if (!jsonItem.attachments) jsonItem.attachments = [];
|
||||||
jsonItem.attachments.push(jsonAttachment);
|
jsonItem.attachments.push(jsonAttachment);
|
||||||
attachmentCallback(jsonAttachment, 0);
|
attachmentCallback(jsonAttachment, 0);
|
||||||
}
|
}
|
||||||
|
@ -266,7 +267,7 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
let jsonItem = jsonByItem.get(item);
|
let jsonItem = jsonByItem.get(item);
|
||||||
// Reuse the existing status line if there is one. This could be a failed
|
// Reuse the existing status line if there is one. This could be a failed
|
||||||
// translator attachment or a possible OA PDF found above.
|
// translator attachment or a possible OA PDF found above.
|
||||||
let jsonAttachment = jsonItem.attachments.find(
|
let jsonAttachment = jsonItem.attachments && jsonItem.attachments.find(
|
||||||
x => x.mimeType == 'application/pdf' && x.isPrimaryPDF
|
x => x.mimeType == 'application/pdf' && x.isPrimaryPDF
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue