Merge pull request #756 from aurimasv/attachment-proxy
Attachment proxy fixes
This commit is contained in:
commit
46ff2f464d
|
@ -201,7 +201,7 @@ Zotero.Attachments = new function(){
|
||||||
|
|
||||||
function importFromURL(url, sourceItemID, forceTitle, forceFileBaseName, parentCollectionIDs,
|
function importFromURL(url, sourceItemID, forceTitle, forceFileBaseName, parentCollectionIDs,
|
||||||
mimeType, libraryID, callback, cookieSandbox) {
|
mimeType, libraryID, callback, cookieSandbox) {
|
||||||
Zotero.debug('Importing attachment from URL');
|
Zotero.debug('Importing attachment from URL ' + url);
|
||||||
|
|
||||||
if (sourceItemID && parentCollectionIDs) {
|
if (sourceItemID && parentCollectionIDs) {
|
||||||
var msg = "parentCollectionIDs is ignored when sourceItemID is set in Zotero.Attachments.importFromURL()";
|
var msg = "parentCollectionIDs is ignored when sourceItemID is set in Zotero.Attachments.importFromURL()";
|
||||||
|
|
|
@ -666,6 +666,9 @@ Zotero.Translate.Sandbox = {
|
||||||
|
|
||||||
if(attachment.url) {
|
if(attachment.url) {
|
||||||
// Remap attachment (but not link) URLs
|
// Remap attachment (but not link) URLs
|
||||||
|
// TODO: provide both proxied and un-proxied URLs (also for documents)
|
||||||
|
// because whether the attachment is attached as link or file
|
||||||
|
// depends on Zotero preferences as well.
|
||||||
attachment.url = translate.resolveURL(attachment.url, attachment.snapshot === false);
|
attachment.url = translate.resolveURL(attachment.url, attachment.snapshot === false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1237,19 +1240,16 @@ Zotero.Translate.Base.prototype = {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
"resolveURL":function(url, dontUseProxy) {
|
"resolveURL":function(url, dontUseProxy) {
|
||||||
const hostPortRe = /^((?:http|https|ftp):)\/\/([^\/]+)/i;
|
Zotero.debug("Translate: resolving URL " + url);
|
||||||
// resolve local URL
|
|
||||||
var resolved = "";
|
|
||||||
|
|
||||||
// convert proxy to proper if applicable
|
const hostPortRe = /^([A-Z][-A-Z0-9+.]*):\/\/[^\/]+/i;
|
||||||
if(hostPortRe.test(url)) {
|
const allowedSchemes = ['http', 'https', 'ftp'];
|
||||||
if(this.translator && this.translator[0]
|
|
||||||
&& this.translator[0].properToProxy && !dontUseProxy) {
|
var m = url.match(hostPortRe),
|
||||||
resolved = this.translator[0].properToProxy(url);
|
resolved;
|
||||||
} else {
|
if (!m) {
|
||||||
resolved = url;
|
// Convert relative URLs to absolute
|
||||||
}
|
if(Zotero.isFx && this.location) {
|
||||||
} else if(Zotero.isFx && this.location) {
|
|
||||||
resolved = Components.classes["@mozilla.org/network/io-service;1"].
|
resolved = Components.classes["@mozilla.org/network/io-service;1"].
|
||||||
getService(Components.interfaces.nsIIOService).
|
getService(Components.interfaces.nsIIOService).
|
||||||
newURI(this.location, "", null).resolve(url);
|
newURI(this.location, "", null).resolve(url);
|
||||||
|
@ -1266,6 +1266,24 @@ Zotero.Translate.Base.prototype = {
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Cannot resolve relative URL without an associated web page: ' + url);
|
throw new Error('Cannot resolve relative URL without an associated web page: ' + url);
|
||||||
}
|
}
|
||||||
|
} else if (allowedSchemes.indexOf(m[1].toLowerCase()) == -1) {
|
||||||
|
Zotero.debug("Translate: unsupported scheme " + m[1]);
|
||||||
|
return url;
|
||||||
|
} else {
|
||||||
|
resolved = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.debug("Translate: resolved to " + resolved);
|
||||||
|
|
||||||
|
// convert proxy to proper if applicable
|
||||||
|
if(!dontUseProxy && this.translator && this.translator[0]
|
||||||
|
&& this.translator[0].properToProxy) {
|
||||||
|
var proxiedURL = this.translator[0].properToProxy(resolved);
|
||||||
|
if (proxiedURL != resolved) {
|
||||||
|
Zotero.debug("Translate: proxified to " + proxiedURL);
|
||||||
|
}
|
||||||
|
resolved = proxiedURL;
|
||||||
|
}
|
||||||
|
|
||||||
/*var m = hostPortRe.exec(resolved);
|
/*var m = hostPortRe.exec(resolved);
|
||||||
if(!m) {
|
if(!m) {
|
||||||
|
|
|
@ -254,7 +254,7 @@ Zotero.Translators = new function() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
converterFunctions.push(new function() {
|
converterFunctions.push(new function() {
|
||||||
var re = new RegExp('^https?://(?:[^/]\\.)?'+Zotero.Utilities.quotemeta(properHosts[j-1]), "gi");
|
var re = new RegExp('^https?://(?:[^/]+\\.)?'+Zotero.Utilities.quotemeta(properHosts[j-1]+'/'), "gi");
|
||||||
var proxyHost = proxyHosts[j-1].replace(/\$/g, "$$$$");
|
var proxyHost = proxyHosts[j-1].replace(/\$/g, "$$$$");
|
||||||
return function(uri) { return uri.replace(re, "$&."+proxyHost) };
|
return function(uri) { return uri.replace(re, "$&."+proxyHost) };
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user