diff --git a/lib/boards-api.js b/lib/boards-api.js index e019871..c5f1e8f 100644 --- a/lib/boards-api.js +++ b/lib/boards-api.js @@ -116,9 +116,9 @@ BoardsAPI.prototype.createProfile = function (profile, done) { (e, cb) => { // Remove old profile files if present var path = '/ipfs-boards-profile/ipfs-boards-version.txt' - this.ipfs.files.rm(path, { r: true }, res => { + this.ipfs.files.rm(path, { recursive: true }, res => { var path = '/ipfs-boards-profile/profile.json' - this.ipfs.files.rm(path, { r: true }, res => cb()) + this.ipfs.files.rm(path, { recursive: true }, res => cb()) }) }, cb => { @@ -129,16 +129,22 @@ BoardsAPI.prototype.createProfile = function (profile, done) { }, (e, cb) => { // Serialize profile and add to IPFS - this.ipfs.add(new Buffer(profileStr), cb) + var file = { + path: 'profile.json', + content: profileStr + } + this.ipfs.add(file, cb) }, (res, cb) => { // Move profile into mfs - console.log('added profile to IPFS:', res.Hash) - var profilepath = '/ipfs/' + res.Hash + var hash = res[0].Hash + console.log('added profile to IPFS:', hash) + var profilepath = '/ipfs/' + hash this.ipfs.files.cp([profilepath, '/ipfs-boards-profile/profile.json'], cb) }, (e, cb) => this.ipfs.files.stat('/', cb), (res, cb) => { + console.log('Result:', res) var profileHash = res.Hash console.log('Publishing profile...') this.ipfs.name.publish(profileHash, cb) @@ -345,7 +351,19 @@ BoardsAPI.prototype.cat = function (path, done) { } else { // Download via http api try { - this.ipfs.cat(path, done) + this.ipfs.cat(path, (err, res) => { + if (err) return done(err) + var ret = '' + res.on('error', e => { + done(e) + }) + res.on('data', (data) => { + ret += data + }) + res.on('end', () => { + done(null, ret) + }) + }) } catch (e) { done(e) } @@ -485,6 +503,7 @@ BoardsAPI.prototype.getProfile = function (userID, done) { this.ee.emit('error', err2) done(err2, null) } else { + console.log('Got Profile: ', res) var p try { p = JSON.parse(res.toString())