parent
eee0e22bf6
commit
ed734bfdf3
1 changed files with 42 additions and 32 deletions
|
@ -493,30 +493,42 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
if(attachment.snapshot === false || !this._saveFiles) {
|
if(attachment.snapshot === false || !this._saveFiles) {
|
||||||
// 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;
|
||||||
if(attachment.document) {
|
if(attachment.document) {
|
||||||
yield Zotero.Attachments.linkFromURL({
|
url = attachment.document.location.href;
|
||||||
url: attachment.document.location.href,
|
mimeType = attachment.mimeType ? attachment.mimeType : attachment.document.contentType;
|
||||||
parentItemID: parentID,
|
|
||||||
contentType: attachment.mimeType ? attachment.mimeType : attachment.document.contentType,
|
|
||||||
title: title
|
|
||||||
})
|
|
||||||
.catch(function (e) {
|
|
||||||
Zotero.debug("Translate: Error adding attachment "+attachment.url, 2);
|
|
||||||
attachmentCallback(attachment, false, e);
|
|
||||||
});
|
|
||||||
|
|
||||||
attachmentCallback(attachment, 100);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
if(!attachment.mimeType || !title) {
|
url = attachment.url
|
||||||
Zotero.debug("Translate: Either mimeType or title is missing; attaching file will be slower", 3);
|
mimeType = attachment.mimeType ? attachment.mimeType : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!mimeType || !title) {
|
||||||
|
Zotero.debug("Translate: Either mimeType or title is missing; attaching link to URL will be slower", 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
let cleanURI = Zotero.Attachments.cleanAttachmentURI(url);
|
||||||
|
if (!cleanURI) {
|
||||||
|
let e = "Translate: Invalid attachment URL specified <" + url + ">";
|
||||||
|
Zotero.debug(e, 2);
|
||||||
|
attachmentCallback(attachment, false, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
url = Components.classes["@mozilla.org/network/io-service;1"]
|
||||||
|
.getService(Components.interfaces.nsIIOService)
|
||||||
|
.newURI(cleanURI, null, null); // This cannot fail, since we check above
|
||||||
|
|
||||||
|
// Only HTTP/HTTPS links are allowed
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield Zotero.Attachments.linkFromURL({
|
yield Zotero.Attachments.linkFromURL({
|
||||||
url: attachment.url,
|
url: cleanURI,
|
||||||
parentItemID: parentID,
|
parentItemID: parentID,
|
||||||
contentType: attachment.mimeType ? attachment.mimeType : undefined,
|
contentType: mimeType,
|
||||||
title: title
|
title: title
|
||||||
})
|
})
|
||||||
.catch(function (e) {
|
.catch(function (e) {
|
||||||
|
@ -526,8 +538,6 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
|
|
||||||
attachmentCallback(attachment, 100);
|
attachmentCallback(attachment, 100);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// if snapshot is not explicitly set to false, retrieve snapshot
|
// if snapshot is not explicitly set to false, retrieve snapshot
|
||||||
|
|
Loading…
Add table
Reference in a new issue