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

Fixing small issues with the new object api #273

Merged
merged 1 commit into from
May 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}