Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (path, opts) => {
opts = opts || {}
const p = deferred.source()
try {
path = cleanCID(path)
} catch (err) {
if (!v.ipfsPath(path)) {
return p.end(err)
}
}
const request = { path: 'get', args: path, qs: opts }
// Convert the response stream to TarStream objects
send.andTransform(request, TarStreamToObjects, (err, stream) => {
if (err) { return p.end(err) }
p.resolve(
pull(
toPull.source(stream),
map(file => {
const { path, content } = file
return content ? { path, content: toPull.source(content) } : file
callback = opts
opts = {}
}
// opts is the real callback --
// 'callback' is being injected by promisify
if (typeof opts === 'function' &&
typeof callback === 'function') {
callback = opts
opts = {}
}
try {
path = cleanCID(path)
} catch (err) {
if (!v.ipfsPath(path)) {
return callback(err)
}
}
const request = {
path: 'get',
args: path,
qs: opts
}
// Convert the response stream to TarStream objects
send.andTransform(request, TarStreamToObjects, callback)
})
}
function safePathPrefix (prefix, path, isDestination) {
const realPath = safePath(path)
if (!isDestination && IsIpfs.ipfsPath(realPath)) {
// we don't prefix valid /ipfs/ paths in source paths
// (those are public and immutable, so safe as-is)
return realPath
}
return Path.join(prefix, realPath)
}
exports.parseKey = (request, h) => {
const { arg } = request.query
if (!arg) {
throw Boom.badRequest("Argument 'key' is required")
}
const isArray = Array.isArray(arg)
const args = isArray ? arg : [arg]
for (const arg of args) {
if (!isIpfs.ipfsPath(arg) && !isIpfs.cid(arg) && !isIpfs.ipfsPath('/ipfs/' + arg)) {
throw Boom.badRequest(`invalid ipfs ref path '${arg}'`)
}
}
return {
key: isArray ? args : arg,
options: {
offset: numberFromQuery(request.query, 'offset'),
length: numberFromQuery(request.query, 'length')
}
}
}
const paths = args.filter(arg => isIpfs.ipfsPath(arg) || isIpfs.cid(arg))
return (hash, opts) => {
opts = opts || {}
const p = deferred.source()
try {
hash = cleanCID(hash)
} catch (err) {
if (!v.ipfsPath(hash)) {
return p.end(err)
}
}
const query = {
offset: opts.offset,
length: opts.length
}
send({ path: 'cat', args: hash, buffer: opts.buffer, qs: query }, (err, stream) => {
if (err) { return p.end(err) }
p.resolve(toPull(stream))
})
return p
export function validateIPFS (text) {
return isIPFS.multihash(text) ||
isIPFS.cid(text) ||
isIPFS.ipfsPath(text) ||
isIPFS.ipfsPath(`/ipfs/${text}`)
}
export function validateIPFS (text) {
return isIPFS.multihash(text) ||
isIPFS.cid(text) ||
isIPFS.ipfsPath(text) ||
isIPFS.ipfsPath(`/ipfs/${text}`)
}
return (hash, opts) => {
opts = opts || {}
const pt = new Stream.PassThrough()
try {
hash = cleanCID(hash)
} catch (err) {
if (!v.ipfsPath(hash)) {
return pt.destroy(err)
}
}
const query = {
offset: opts.offset,
length: opts.length
}
send({ path: 'cat', args: hash, buffer: opts.buffer, qs: query }, (err, stream) => {
if (err) { return pt.destroy(err) }
pump(stream, pt)
})
return pt