Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
start fixing small issues with the new object api
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 14, 2016
1 parent 0a33a61 commit a73902b
Showing 1 changed file with 56 additions and 9 deletions.
65 changes: 56 additions & 9 deletions src/api/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/get', multihash, null, null, (err, result) => {
if (err) {
Expand Down Expand Up @@ -105,14 +110,23 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/data', multihash, null, null, (err, result) => {
if (err) {
return callback(err)
}

result.pipe(bl(callback))
if (typeof result.pipe === 'function') {
result.pipe(bl(callback))
} else {
callback(null, result)
}
})
}),
links: promisify((multihash, options, callback) => {
Expand All @@ -123,7 +137,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/links', multihash, null, null, (err, result) => {
if (err) {
Expand All @@ -148,7 +167,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/stat', multihash, null, null, callback)
}),
Expand All @@ -175,7 +199,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/patch/add-link', [multihash, dLink.name, bs58.encode(dLink.hash).toString()], null, null, (err, result) => {
if (err) {
Expand All @@ -192,7 +221,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/patch/rm-link', [multihash, dLink.name], null, null, (err, result) => {
if (err) {
Expand All @@ -209,7 +243,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/patch/set-data', [multihash], null, data, (err, result) => {
if (err) {
Expand All @@ -226,7 +265,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/patch/append-data', [multihash], null, data, (err, result) => {
if (err) {
Expand Down Expand Up @@ -262,6 +306,9 @@ function cleanMultihash (multihash, options) {
} else {
throw new Error('not valid multihash')
}
} else if (!multihash) {
throw new Error('missing valid multihash')
}

return multihash
}

0 comments on commit a73902b

Please sign in to comment.