Don't promote attachment.url to attachment.path
...but allow demoting from path to url if necessary.
This commit is contained in:
parent
cf9ec26eb4
commit
ed2b6ccec3
|
@ -226,32 +226,64 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!attachment.path) {
|
let done = false;
|
||||||
let url = Zotero.Attachments.cleanAttachmentURI(attachment.url);
|
if (attachment.path) {
|
||||||
if (!url) {
|
var file = this._parsePath(attachment.path);
|
||||||
Zotero.debug("Translate: Invalid attachment.url specified <" + attachment.url + "> Will attempt to treat it as path.");
|
if(!file) {
|
||||||
attachment.path = attachment.url;
|
let asUrl = Zotero.Attachments.cleanAttachmentURI(attachment.path);
|
||||||
attachment.url = false;
|
if (!attachment.url && !asUrl) {
|
||||||
} else {
|
let e = "Translate: Could not parse attachment path <" + attachment.path + ">";
|
||||||
attachment.url = url;
|
|
||||||
url = Components.classes["@mozilla.org/network/io-service;1"]
|
|
||||||
.getService(Components.interfaces.nsIIOService)
|
|
||||||
.newURI(url, null, null); // This cannot fail, since we check above
|
|
||||||
|
|
||||||
// see if this is actually a file URL
|
|
||||||
if(url.scheme == "file") {
|
|
||||||
attachment.path = attachment.url;
|
|
||||||
attachment.url = false;
|
|
||||||
} else if(url.scheme != "http" && url.scheme != "https") {
|
|
||||||
let e = "Translate: " + url.scheme + " protocol is not allowed for attachments from translators.";
|
|
||||||
Zotero.debug(e, 2);
|
Zotero.debug(e, 2);
|
||||||
attachmentCallback(attachment, false, e);
|
attachmentCallback(attachment, false, e);
|
||||||
return false;
|
return false;
|
||||||
|
} else if (!attachment.url && asUrl) {
|
||||||
|
Zotero.debug("Translate: attachment path looks like a URI: " + attachment.path);
|
||||||
|
attachment.url = asUrl;
|
||||||
|
delete attachment.path;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (attachment.url) {
|
||||||
|
attachment.linkMode = "imported_url";
|
||||||
|
var myID = Zotero.Attachments.importSnapshotFromFile(file,
|
||||||
|
attachment.url, attachment.title, attachment.mimeType, attachment.charset,
|
||||||
|
parentID);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
attachment.linkMode = "imported_file";
|
||||||
|
var myID = Zotero.Attachments.importFromFile(file, parentID);
|
||||||
|
}
|
||||||
|
attachmentCallback(attachment, 100);
|
||||||
|
done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!attachment.path) {
|
if(!done) {
|
||||||
|
let url = Zotero.Attachments.cleanAttachmentURI(attachment.url);
|
||||||
|
if (!url) {
|
||||||
|
let e = "Translate: Invalid attachment.url specified <" + attachment.url + ">";
|
||||||
|
Zotero.debug(e, 2);
|
||||||
|
attachmentCallback(attachment, false, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
attachment.url = url;
|
||||||
|
url = Components.classes["@mozilla.org/network/io-service;1"]
|
||||||
|
.getService(Components.interfaces.nsIIOService)
|
||||||
|
.newURI(url, null, null); // This cannot fail, since we check above
|
||||||
|
|
||||||
|
// see if this is actually a file URL
|
||||||
|
if(url.scheme == "file") {
|
||||||
|
let e = "Translate: Local file attachments cannot be specified in attachment.url";
|
||||||
|
Zotero.debug(e, 2);
|
||||||
|
attachmentCallback(attachment, false, e);
|
||||||
|
return false;
|
||||||
|
} else if(url.scheme != "http" && url.scheme != "https") {
|
||||||
|
let e = "Translate: " + url.scheme + " protocol is not allowed for attachments from translators.";
|
||||||
|
Zotero.debug(e, 2);
|
||||||
|
attachmentCallback(attachment, false, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// 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_file";
|
||||||
try {
|
try {
|
||||||
|
@ -265,27 +297,6 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
}
|
}
|
||||||
Zotero.debug("Translate: Created attachment; id is "+myID, 4);
|
Zotero.debug("Translate: Created attachment; id is "+myID, 4);
|
||||||
attachmentCallback(attachment, 100);
|
attachmentCallback(attachment, 100);
|
||||||
var newItem = Zotero.Items.get(myID);
|
|
||||||
} else {
|
|
||||||
var file = this._parsePath(attachment.path);
|
|
||||||
if(!file) {
|
|
||||||
let e = "Translate: Could not parse attachment path <" + attachment.path + ">";
|
|
||||||
Zotero.debug(e, 2);
|
|
||||||
attachmentCallback(attachment, false, e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (attachment.url) {
|
|
||||||
attachment.linkMode = "imported_url";
|
|
||||||
var myID = Zotero.Attachments.importSnapshotFromFile(file,
|
|
||||||
attachment.url, attachment.title, attachment.mimeType, attachment.charset,
|
|
||||||
parentID);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
attachment.linkMode = "imported_file";
|
|
||||||
var myID = Zotero.Attachments.importFromFile(file, parentID);
|
|
||||||
}
|
|
||||||
attachmentCallback(attachment, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var newItem = Zotero.Items.get(myID);
|
var newItem = Zotero.Items.get(myID);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user