1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-10 12:24:20 +01:00

bug fixing and ipfs version checking

This commit is contained in:
Enrico Fasoli 2015-11-16 13:20:15 +01:00
parent c264bc7fd6
commit 9344b360d7

View File

@ -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