mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-10 12:24:20 +01:00
fixed some usage of ipfs-api to work with version 3
This commit is contained in:
parent
49bd61bd2e
commit
890f3d4b37
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user