Skip to content

Commit

Permalink
Small cleanup after merge of #30
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Dec 18, 2015
1 parent c48470a commit 82c9228
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/gateways.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ function pin(address) {
let IPFS_API_URI = 'http://' + prefs.customGatewayHost + ':5001/api/v0';
let uri = ioservice.newURI(IPFS_API_URI + '/pin/add?arg=' + address, null, null);

Request({
new Request({
url: uri.spec,
onComplete: function (response) {
let pinned = address.indexOf(response.json.Pinned)==6;
notifications.notify({
title: pinned ? 'Pinned' : 'Failed to Pin',
text: address.slice(6)
})
});
}
}).get();
}
Expand Down Expand Up @@ -88,6 +88,8 @@ exports.onChange = (f) => {
callbacks.push(f);
};

exports.reload = reloadCachedProperties;

exports.customUri = function() {
return CUSTOM_GATEWAY_URI;
};
Expand All @@ -97,3 +99,4 @@ exports.publicUri = function() {
exports.publicHosts = function() {
return PUBLIC_GATEWAY_HOSTS;
};

4 changes: 2 additions & 2 deletions lib/redirects.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const gw = require('./gateways');
var prefs = require('sdk/simple-prefs').prefs;

var {
Cc, Ci
Expand All @@ -16,7 +15,7 @@ var ipfsRequestObserver = {
let httpUrl = channel.URI.spec;
if (httpUrl.match(gw.publicHosts()) && httpUrl.match(gw.IPFS_RESOURCE)) {
channel.setRequestHeader('x-ipfs-firefox-addon', 'true', false);
if (prefs.useCustomGateway) {
if (gw.isEnabled()) {
//console.info('Detected HTTP request to the public gateway: ' + channel.URI.spec);
let uri = ioservice.newURI(httpUrl.replace(gw.publicHosts(), gw.customUri().spec), null, null);
//console.info('Redirecting to custom gateway: ' + uri.spec);
Expand Down Expand Up @@ -50,6 +49,7 @@ gw.onChange(() => {
ipfsRequestObserver.unregister();
}
});
gw.reload(); // enable redirect


exports.on = ipfsRequestObserver.register;
Expand Down

0 comments on commit 82c9228

Please sign in to comment.