Skip to content

Commit

Permalink
Merge pull request #30 from jedahan/pins
Browse files Browse the repository at this point in the history
Add pin function
  • Loading branch information
lidel committed Dec 18, 2015
2 parents 02836cf + 8679d87 commit c48470a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
18 changes: 18 additions & 0 deletions lib/gateways.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ function getPublicGatewayHostsRegex() {
return new RegExp('^https?:\/\/(' + hostsRegex + ')\/');
}

const notifications = require('sdk/notifications');
const Request = require('sdk/request').Request;
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({
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();
}
exports.pin = pin;

const callbacks = [];

Expand Down
16 changes: 13 additions & 3 deletions lib/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,17 @@ function toggle(val) { /*jshint ignore:line*/
gw.toggle(val);
}


const PIN_IPFS_ADDRESS = cm.Item({
label: 'Pin ipfs address',
contentScript: 'self.on("click", self.postMessage);',
onMessage: function() {
let ipfsURI = Cc['@mozilla.org/appshell/window-mediator;1']
.getService(Ci.nsIWindowMediator)
.getMostRecentWindow('navigator:browser')
.getBrowser().currentURI.spec;
gw.pin(ipfsURI.replace(gw.customUri().spec, '/'));
}
});

const COPY_IPFS_ADDRESS = cm.Item({
label: 'Copy canonical address',
Expand Down Expand Up @@ -96,12 +106,12 @@ const COPY_PUBLIC_HTTP_URL = cm.Item({

cm.Menu({
label: 'IPFS',
items: [COPY_IPFS_ADDRESS, COPY_PUBLIC_HTTP_URL]
items: [PIN_IPFS_ADDRESS, COPY_IPFS_ADDRESS, COPY_PUBLIC_HTTP_URL]
});


gw.onChange(() => {
for (let ctx of[COPY_PUBLIC_HTTP_URL.context, COPY_IPFS_ADDRESS.context]) {
for (let ctx of[PIN_IPFS_ADDRESS.context, COPY_PUBLIC_HTTP_URL.context, COPY_IPFS_ADDRESS.context]) {
let url = gw.customUri().spec + '*';
ctx.add(cm.URLContext(url));
}
Expand Down

0 comments on commit c48470a

Please sign in to comment.