1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-26 15:04:19 +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 // Rewrote this to use event emitters. Should also add periodic rechecking
BoardsAPI.prototype.resolveIPNS = function(n,handler){ 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] var cached = this.users[n]
//console.log('Cached is',cached) //console.log('Cached is',cached)
if(cached){ if(cached){
@ -86,10 +86,11 @@ BoardsAPI.prototype.resolveIPNS = function(n,handler){
if(this.resolving_ipns[n] != true){ if(this.resolving_ipns[n] != true){
this.resolving_ipns[n] = true this.resolving_ipns[n] = true
this.ipfs.name.resolve(n,(err,r) => { this.ipfs.name.resolve(n,(err,r) => {
this.resolving_ipns[n] = false
setTimeout(_ => { setTimeout(_ => {
console.log('Launching automatic check for IPNS address',n) console.log('Launched automatic check for IPNS address',n)
this.resolveIPNS(n) this.resolveIPNS(n)
},20*1000) },10*1000)
if(!err) console.log('Resolved',n,'to',r.Path) if(!err) console.log('Resolved',n,'to',r.Path)
if(err){ if(err){
// Communicate error // Communicate error
@ -99,6 +100,7 @@ BoardsAPI.prototype.resolveIPNS = function(n,handler){
//console.log('Setting cache for',n,'to',r.Path) //console.log('Setting cache for',n,'to',r.Path)
this.users[n] = r.Path this.users[n] = r.Path
this.backupCache() this.backupCache()
console.log('Address for',n,'was updated to',r.Path)
this.ee.emit(n,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 => { var l = res.Objects[0].Links.map(i => {
return { name: i.Name, hash: i.Hash } return { name: i.Name, hash: i.Hash }
}) })
this.ee.emit('boards',l) this.ee.emit('boards for '+userID,l)
} else { } else {
this.ee.emit('error',err2) 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 module.exports = BoardsAPI