From 9344b360d79777b9d8bab84f7650c48874edf80d 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 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 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