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

update API to work with js-ipfs-api 2.9.8

This commit is contained in:
Enrico Fasoli 2015-11-23 15:37:44 +01:00
parent c7174a9dfd
commit 4ed4de2ea6
2 changed files with 14 additions and 10 deletions

View File

@ -17,11 +17,12 @@ function asObj(str,done){
obj = JSON.parse(str)
} catch (e) {
console.log('error parsing:',str,'Error:',e)
return done(e,null)
return done(e,undefined)
}
done(null,obj)
} else {
done(null,str)
console.log('not string:',str)
done('not string: '+str,undefined)
}
}
@ -43,7 +44,7 @@ function replyAsObj(res,isJson,done){
}
})
} else {
//console.log('got string:',res)
console.log('got string:',res)
// Is a string
if(isJson){
asObj(res,done)
@ -189,9 +190,10 @@ BoardsAPI.prototype.getProfile = function(userID,done){
this.ee.emit('error',err2)
done(err2,null)
} else {
// It already returns a JSON?
this.ee.emit('profile for '+userID,res)
done(null,res)
// TODO: JSON parse error handling
var p = JSON.parse(res.toString())
this.ee.emit('profile for '+userID,p)
done(null,p)
}
})
// Get other info
@ -217,7 +219,9 @@ BoardsAPI.prototype.getBoardSettings = function(userID,board){
this.ee.emit('error',e)
} else {
var url = r+this.baseurl+'boards/'+board+'/settings.json'
this.ipfs.cat(url,(err,settings) => {
this.ipfs.cat(url,(err,resp) => {
// TODO: error handling json conversion
var settings = JSON.parse(resp.toString())
if(err){
this.ee.emit('error',err)
} else {
@ -266,8 +270,8 @@ BoardsAPI.prototype.downloadPost = function(hash,adminID,board,op,done){
console.log('Could not download post',hash,'of',board+'@'+adminID)
if(done && done.apply) done(err2)
} else {
// It already returns a JSON?
var post = r
// TODO: add JSON parsing error handling
var post = JSON.parse(r.toString())
post.hash = hash
if(op) post.op = op // Inject op
if(board) this.ee.emit('post in '+board+'@'+adminID,post,hash)

View File

@ -37,7 +37,7 @@
"history": "~1.13.1",
"html-loader": "^0.3.0",
"html-webpack-plugin": "~1.6.2",
"ipfs-api": "2.9.1",
"ipfs-api": "2.9.8",
"json-loader": "~0.5.3",
"lodash.sortedindex": "~3.1.1",
"markdown-loader": "^0.1.7",