Fix linked-URL attachments not being saved to groups without files
It looks like this may have been broken for years.
This commit is contained in:
parent
506ed313da
commit
5a6a772ca2
2 changed files with 53 additions and 6 deletions
|
@ -445,7 +445,11 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
|
|
||||||
|
|
||||||
_canSaveAttachment: function (attachment) {
|
_canSaveAttachment: function (attachment) {
|
||||||
if (this.attachmentMode == Zotero.Translate.ItemSaver.ATTACHMENT_MODE_DOWNLOAD) {
|
// Always save link attachments
|
||||||
|
var isLink = Zotero.MIME.isWebPageType(attachment.mimeType)
|
||||||
|
// .snapshot coming from most translators, .linkMode coming from RDF
|
||||||
|
&& (attachment.snapshot === false || attachment.linkMode == Zotero.Attachments.LINK_MODE_LINKED_URL);
|
||||||
|
if (isLink || this.attachmentMode == Zotero.Translate.ItemSaver.ATTACHMENT_MODE_DOWNLOAD) {
|
||||||
if (!attachment.url && !attachment.document) {
|
if (!attachment.url && !attachment.document) {
|
||||||
Zotero.debug("Translate: Not adding attachment: no URL specified");
|
Zotero.debug("Translate: Not adding attachment: no URL specified");
|
||||||
return false;
|
return false;
|
||||||
|
@ -489,9 +493,12 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
_saveAttachment: Zotero.Promise.coroutine(function* (attachment, parentItemID, attachmentCallback) {
|
_saveAttachment: Zotero.Promise.coroutine(function* (attachment, parentItemID, attachmentCallback) {
|
||||||
try {
|
try {
|
||||||
let newAttachment;
|
let newAttachment;
|
||||||
|
|
||||||
// determine whether to save files and attachments
|
// determine whether to save files and attachments
|
||||||
if (this.attachmentMode == Zotero.Translate.ItemSaver.ATTACHMENT_MODE_DOWNLOAD) {
|
let isLink = Zotero.MIME.isWebPageType(attachment.mimeType)
|
||||||
|
// .snapshot coming from most translators, .linkMode coming from RDF
|
||||||
|
&& (attachment.snapshot === false || attachment.linkMode == Zotero.Attachments.LINK_MODE_LINKED_URL);
|
||||||
|
if (isLink || this.attachmentMode == Zotero.Translate.ItemSaver.ATTACHMENT_MODE_DOWNLOAD) {
|
||||||
newAttachment = yield this._saveAttachmentDownload.apply(this, arguments);
|
newAttachment = yield this._saveAttachmentDownload.apply(this, arguments);
|
||||||
} else if (this.attachmentMode == Zotero.Translate.ItemSaver.ATTACHMENT_MODE_FILE) {
|
} else if (this.attachmentMode == Zotero.Translate.ItemSaver.ATTACHMENT_MODE_FILE) {
|
||||||
newAttachment = yield this._saveAttachmentFile.apply(this, arguments);
|
newAttachment = yield this._saveAttachmentFile.apply(this, arguments);
|
||||||
|
|
|
@ -6,7 +6,7 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||||
* @param {String} translatorType - "import" or "web"
|
* @param {String} translatorType - "import" or "web"
|
||||||
* @param {Object} items - items as translator JSON
|
* @param {Object} items - items as translator JSON
|
||||||
*/
|
*/
|
||||||
function saveItemsThroughTranslator(translatorType, items) {
|
function saveItemsThroughTranslator(translatorType, items, translateOptions = {}) {
|
||||||
let tyname;
|
let tyname;
|
||||||
if (translatorType == "web") {
|
if (translatorType == "web") {
|
||||||
tyname = "Web";
|
tyname = "Web";
|
||||||
|
@ -35,7 +35,7 @@ function saveItemsThroughTranslator(translatorType, items) {
|
||||||
" item.complete();\n"+
|
" item.complete();\n"+
|
||||||
" }\n"+
|
" }\n"+
|
||||||
"}"));
|
"}"));
|
||||||
return translate.translate().then(function(items) {
|
return translate.translate(translateOptions).then(function(items) {
|
||||||
if (browser) Zotero.Browser.deleteHiddenBrowser(browser);
|
if (browser) Zotero.Browser.deleteHiddenBrowser(browser);
|
||||||
return items;
|
return items;
|
||||||
});
|
});
|
||||||
|
@ -404,7 +404,47 @@ describe("Zotero.Translate", function() {
|
||||||
assert.equal(newItems[0].getField("title"), "Container Item");
|
assert.equal(newItems[0].getField("title"), "Container Item");
|
||||||
assert.equal(newItems[0].getAttachments().length, 0);
|
assert.equal(newItems[0].getAttachments().length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("import translators should save linked-URL attachments with savingAttachments: false", async function () {
|
||||||
|
var json = [
|
||||||
|
{
|
||||||
|
itemType: "journalArticle",
|
||||||
|
title: "Parent Item",
|
||||||
|
attachments: [
|
||||||
|
// snapshot: false
|
||||||
|
{
|
||||||
|
title: "Link",
|
||||||
|
mimeType: "text/html",
|
||||||
|
url: "http://example.com",
|
||||||
|
snapshot: false
|
||||||
|
},
|
||||||
|
// linkMode (used by RDF import)
|
||||||
|
{
|
||||||
|
title: "Link",
|
||||||
|
mimeType: "text/html",
|
||||||
|
url: "http://example.com",
|
||||||
|
linkMode: Zotero.Attachments.LINK_MODE_LINKED_URL
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
var newItems = itemsArrayToObject(
|
||||||
|
await saveItemsThroughTranslator(
|
||||||
|
"import",
|
||||||
|
json,
|
||||||
|
{
|
||||||
|
saveAttachments: false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
var attachmentIDs = newItems["Parent Item"].getAttachments();
|
||||||
|
assert.lengthOf(attachmentIDs, 2);
|
||||||
|
var attachments = await Zotero.Items.getAsync(attachmentIDs);
|
||||||
|
assert.equal(attachments[0].attachmentLinkMode, Zotero.Attachments.LINK_MODE_LINKED_URL);
|
||||||
|
assert.equal(attachments[1].attachmentLinkMode, Zotero.Attachments.LINK_MODE_LINKED_URL);
|
||||||
|
});
|
||||||
|
|
||||||
it('web translators should set accessDate to current date', function* () {
|
it('web translators should set accessDate to current date', function* () {
|
||||||
let myItem = {
|
let myItem = {
|
||||||
"itemType":"webpage",
|
"itemType":"webpage",
|
||||||
|
|
Loading…
Add table
Reference in a new issue