From 4ed4de2ea617eaf8d1f263acdc53acaeeaffb439 Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Mon, 23 Nov 2015 15:37:44 +0100 Subject: [PATCH] update API to work with js-ipfs-api 2.9.8 --- lib/boards-api.js | 22 +++++++++++++--------- package.json | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/boards-api.js b/lib/boards-api.js index 24cff0e..b1693a1 100644 --- a/lib/boards-api.js +++ b/lib/boards-api.js @@ -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) diff --git a/package.json b/package.json index e0657f1..b5feada 100644 --- a/package.json +++ b/package.json @@ -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",