From 862ac5ab40efe28ca0c39b442ef70f8a0633689b Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 25 Aug 2018 16:47:45 -0400 Subject: [PATCH] Handle missing 'attachments' array in /connector/saveItems --- .../content/zotero/xpcom/connector/server_connector.js | 9 ++++++--- .../content/zotero/xpcom/translation/translate_item.js | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/connector/server_connector.js b/chrome/content/zotero/xpcom/connector/server_connector.js index 455ffacaa3..1f1eae2a96 100644 --- a/chrome/content/zotero/xpcom/connector/server_connector.js +++ b/chrome/content/zotero/xpcom/connector/server_connector.js @@ -667,21 +667,24 @@ Zotero.Server.Connector.SaveItems.prototype = { function (topLevelItems) { // Only return the properties the connector needs topLevelItems = topLevelItems.map((item) => { - return { + let o = { id: item.id, title: item.title, itemType: item.itemType, contentType: item.mimeType, mimeType: item.mimeType, // TODO: Remove - attachments: item.attachments.map((attachment) => { + }; + if (item.attachments) { + o.attachments = item.attachments.map((attachment) => { return { id: session.id + '_' + attachment.id, // TODO: Remove prefix title: attachment.title, contentType: attachment.contentType, mimeType: attachment.mimeType, // TODO: Remove }; - }) + }); }; + return o; }); resolve([201, "application/json", JSON.stringify({items: topLevelItems})]); } diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index 21831df6a8..6113e9924d 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -222,6 +222,7 @@ Zotero.Translate.ItemSaver.prototype = { if (urlObjects.length) { let title = Zotero.getString('findPDF.openAccessPDF'); let jsonAttachment = this._makeJSONAttachment(jsonItem.id, title); + if (!jsonItem.attachments) jsonItem.attachments = []; jsonItem.attachments.push(jsonAttachment); attachmentCallback(jsonAttachment, 0); } @@ -266,7 +267,7 @@ Zotero.Translate.ItemSaver.prototype = { let jsonItem = jsonByItem.get(item); // Reuse the existing status line if there is one. This could be a failed // 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 );