Skip to content

Commit

Permalink
Expose attachments, as suggested by noctux
Browse files Browse the repository at this point in the history
  • Loading branch information
wetneb committed Dec 5, 2019
1 parent 1927486 commit a056f76
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ Zotero.Utilities.itemToAPIJSON = function(item) {

var fieldID, itemFieldID;
for(var field in item) {
if(field === "complete" || field === "itemID" || field === "attachments"
|| field === "seeAlso") continue;
if(field === "complete" || field === "itemID" || field === "seeAlso")
continue;

var val = item[field];

Expand Down Expand Up @@ -149,6 +149,22 @@ Zotero.Utilities.itemToAPIJSON = function(item) {
note: note.toString()
});
}
} else if(field === "attachments") {
var n = val.length;
for(var j=0; j<n; j++) {
var attachment = val[j];
if(typeof attachment !== "object" || !attachment.url) {
Zotero.debug("itemToAPIJSON: Discarded attachment: not an URL");
continue;
}
newItems.push({
itemType: "attachment",
parentItem: newItem.key,
title: attachment.title.toString(),
mimeType: attachment.mimeType.toString(),
url: attachment.url.toString(),
});
}
} else if((fieldID = Zotero.ItemFields.getID(field))) {
// if content is not a string, either stringify it or delete it
if(typeof val !== "string") {
Expand Down

0 comments on commit a056f76

Please sign in to comment.