Don't load linked URLs during import
Regression from 5a6a772ca2
, I think
This commit is contained in:
parent
ff579d411a
commit
8b4bb62efc
3 changed files with 66 additions and 3 deletions
|
@ -8,6 +8,7 @@
|
||||||
"Zotero": false,
|
"Zotero": false,
|
||||||
"ZOTERO_CONFIG": false,
|
"ZOTERO_CONFIG": false,
|
||||||
"AddonManager": false,
|
"AddonManager": false,
|
||||||
|
"assert": false,
|
||||||
"Cc": false,
|
"Cc": false,
|
||||||
"Ci": false,
|
"Ci": false,
|
||||||
"Components": false,
|
"Components": false,
|
||||||
|
|
|
@ -495,7 +495,7 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
let newAttachment;
|
let newAttachment;
|
||||||
|
|
||||||
// determine whether to save files and attachments
|
// determine whether to save files and attachments
|
||||||
let isLink = Zotero.MIME.isWebPageType(attachment.mimeType)
|
var isLink = Zotero.MIME.isWebPageType(attachment.mimeType)
|
||||||
// .snapshot coming from most translators, .linkMode coming from RDF
|
// .snapshot coming from most translators, .linkMode coming from RDF
|
||||||
&& (attachment.snapshot === false || attachment.linkMode == Zotero.Attachments.LINK_MODE_LINKED_URL);
|
&& (attachment.snapshot === false || attachment.linkMode == Zotero.Attachments.LINK_MODE_LINKED_URL);
|
||||||
if (isLink || this.attachmentMode == Zotero.Translate.ItemSaver.ATTACHMENT_MODE_DOWNLOAD) {
|
if (isLink || this.attachmentMode == Zotero.Translate.ItemSaver.ATTACHMENT_MODE_DOWNLOAD) {
|
||||||
|
@ -597,7 +597,7 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point, must be a valid HTTP/HTTPS url
|
// At this point, must be a valid HTTP/HTTPS url
|
||||||
attachment.linkMode = "linked_file";
|
attachment.linkMode = "linked_url";
|
||||||
newItem = yield Zotero.Attachments.linkFromURL({
|
newItem = yield Zotero.Attachments.linkFromURL({
|
||||||
url: attachment.url,
|
url: attachment.url,
|
||||||
parentItemID,
|
parentItemID,
|
||||||
|
@ -775,7 +775,9 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
// Commit to saving
|
// Commit to saving
|
||||||
attachmentCallback(attachment, 0);
|
attachmentCallback(attachment, 0);
|
||||||
|
|
||||||
if(attachment.snapshot === false || this.attachmentMode === Zotero.Translate.ItemSaver.ATTACHMENT_MODE_IGNORE) {
|
var isLink = attachment.snapshot === false
|
||||||
|
|| attachment.linkMode == Zotero.Attachments.LINK_MODE_LINKED_URL;
|
||||||
|
if (isLink || this.attachmentMode === Zotero.Translate.ItemSaver.ATTACHMENT_MODE_IGNORE) {
|
||||||
// if snapshot is explicitly set to false, attach as link
|
// if snapshot is explicitly set to false, attach as link
|
||||||
attachment.linkMode = "linked_url";
|
attachment.linkMode = "linked_url";
|
||||||
let url, mimeType;
|
let url, mimeType;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
new function() {
|
new function() {
|
||||||
Components.utils.import("resource://gre/modules/osfile.jsm");
|
Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||||
|
Components.utils.import("resource://zotero-unit/httpd.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new translator that saves the specified items
|
* Create a new translator that saves the specified items
|
||||||
|
@ -405,6 +406,65 @@ describe("Zotero.Translate", function() {
|
||||||
assert.equal(newItems[0].getAttachments().length, 0);
|
assert.equal(newItems[0].getAttachments().length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('import translators should save link attachments', async function () {
|
||||||
|
// Start a local server so we can make sure a web request isn't made for the URL
|
||||||
|
var port = 16213;
|
||||||
|
var baseURL = `http://127.0.0.1:${port}/`;
|
||||||
|
var httpd = new HttpServer();
|
||||||
|
httpd.start(port);
|
||||||
|
var callCount = 0;
|
||||||
|
var handler = function (_request, response) {
|
||||||
|
callCount++;
|
||||||
|
response.setStatusLine(null, 200, "OK");
|
||||||
|
response.write("<html><head><title>Title</title><body>Body</body></html>");
|
||||||
|
};
|
||||||
|
httpd.registerPathHandler("/1", { handle: handler });
|
||||||
|
httpd.registerPathHandler("/2", { handle: handler });
|
||||||
|
|
||||||
|
var items = [{
|
||||||
|
itemType: "book",
|
||||||
|
title: "Item",
|
||||||
|
attachments: [
|
||||||
|
// With mimeType
|
||||||
|
{
|
||||||
|
itemType: "attachment",
|
||||||
|
linkMode: Zotero.Attachments.LINK_MODE_LINKED_URL,
|
||||||
|
title: "Link 1",
|
||||||
|
url: baseURL + "1",
|
||||||
|
mimeType: 'text/html'
|
||||||
|
},
|
||||||
|
// Without mimeType
|
||||||
|
{
|
||||||
|
itemType: "attachment",
|
||||||
|
linkMode: Zotero.Attachments.LINK_MODE_LINKED_URL,
|
||||||
|
title: "Link 2",
|
||||||
|
url: baseURL + "2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}];
|
||||||
|
|
||||||
|
var newItems = itemsArrayToObject(await saveItemsThroughTranslator("import", items));
|
||||||
|
|
||||||
|
assert.equal(callCount, 0);
|
||||||
|
|
||||||
|
var attachments = await Zotero.Items.getAsync(newItems.Item.getAttachments());
|
||||||
|
assert.equal(attachments.length, 2);
|
||||||
|
|
||||||
|
assert.equal(attachments[0].getField("title"), "Link 1");
|
||||||
|
assert.equal(attachments[0].getField("url"), baseURL + "1");
|
||||||
|
assert.equal(attachments[0].attachmentContentType, "text/html");
|
||||||
|
assert.equal(attachments[0].attachmentLinkMode, Zotero.Attachments.LINK_MODE_LINKED_URL);
|
||||||
|
|
||||||
|
assert.equal(attachments[1].getField("title"), "Link 2");
|
||||||
|
assert.equal(attachments[1].getField("url"), baseURL + "2");
|
||||||
|
assert.equal(attachments[1].attachmentLinkMode, Zotero.Attachments.LINK_MODE_LINKED_URL);
|
||||||
|
assert.equal(attachments[1].attachmentContentType, '');
|
||||||
|
|
||||||
|
await new Promise(function (resolve) {
|
||||||
|
httpd.stop(resolve);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("import translators should save linked-URL attachments with savingAttachments: false", async function () {
|
it("import translators should save linked-URL attachments with savingAttachments: false", async function () {
|
||||||
var json = [
|
var json = [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue