From 46989800631bd5bc3af1a26626dcd0cafb7da2c2 Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Mon, 16 Nov 2015 13:20:15 +0100 Subject: [PATCH] bug fixing and ipfs version checking --- lib/boards-api.js | 18 ++++++++++++++---- webapp/app.jsx | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/boards-api.js b/lib/boards-api.js index d977a36..7b6b537 100644 --- a/lib/boards-api.js +++ b/lib/boards-api.js @@ -77,7 +77,7 @@ BoardsAPI.prototype.backupCache = function(){ // Rewrote this to use event emitters. Should also add periodic rechecking BoardsAPI.prototype.resolveIPNS = function(n,handler){ - if(handler) this.ee.on(n,handler) + if(handler && handler.apply) this.ee.on(n,handler) var cached = this.users[n] //console.log('Cached is',cached) if(cached){ @@ -86,10 +86,11 @@ BoardsAPI.prototype.resolveIPNS = function(n,handler){ if(this.resolving_ipns[n] != true){ this.resolving_ipns[n] = true this.ipfs.name.resolve(n,(err,r) => { + this.resolving_ipns[n] = false setTimeout(_ => { - console.log('Launching automatic check for IPNS address',n) + console.log('Launched automatic check for IPNS address',n) this.resolveIPNS(n) - },20*1000) + },10*1000) if(!err) console.log('Resolved',n,'to',r.Path) if(err){ // Communicate error @@ -99,6 +100,7 @@ BoardsAPI.prototype.resolveIPNS = function(n,handler){ //console.log('Setting cache for',n,'to',r.Path) this.users[n] = r.Path this.backupCache() + console.log('Address for',n,'was updated to',r.Path) this.ee.emit(n,r.Path) } }) @@ -179,7 +181,7 @@ BoardsAPI.prototype.getProfile = function(userID,done){ var l = res.Objects[0].Links.map(i => { return { name: i.Name, hash: i.Hash } }) - this.ee.emit('boards',l) + this.ee.emit('boards for '+userID,l) } else { this.ee.emit('error',err2) } @@ -291,6 +293,14 @@ BoardsAPI.prototype.init = function(done){ }) } }) + this.ipfs.version((err,res) => { + if(err){ + this.ee.emit('error',err) + } else { + this.ipfs_version = res.Version + console.log('IPFS Version is',res.Version) + } + }) } module.exports = BoardsAPI diff --git a/webapp/app.jsx b/webapp/app.jsx index f0c6a61..6e8c1fb 100644 --- a/webapp/app.jsx +++ b/webapp/app.jsx @@ -64,7 +64,7 @@ var Profile = React.createClass({ this.setState({ name: res.name }) } }) - ee.on('boards',l => { + ee.on('boards for '+this.props.params.userid,l => { if(!this.isMounted()) return true this.setState({ boards: l }) })