This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: fix current tests, add more cli tests
- Loading branch information
1 parent
7015586
commit 5fe4674
Showing
24 changed files
with
484 additions
and
995 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,64 @@ | ||
'use strict' | ||
|
||
const boom = require('boom') | ||
const multiaddr = require('multiaddr') | ||
|
||
exports = module.exports | ||
|
||
// common pre request handler that parses the args and returns `key` which is assigned to `request.pre.args` | ||
exports.parseKey = (request, reply) => { | ||
if (!request.query.arg) { | ||
return reply("Argument 'multiaddr' is required").code(400).takeover() | ||
} | ||
|
||
try { | ||
return reply({ | ||
addr: multiaddr(request.query.arg) | ||
}) | ||
} catch (err) { | ||
return reply({ | ||
Message: 'Not a valid multiaddr', | ||
Code: 0 | ||
}).code(500).takeover() | ||
} | ||
} | ||
|
||
exports.list = (request, reply) => { | ||
request.server.app.ipfs.bootstrap.list((err, list) => { | ||
const ipfs = request.server.app.ipfs | ||
ipfs.bootstrap.list((err, list) => { | ||
if (err) { | ||
return reply(boom.badRequest(err)) | ||
} | ||
return reply(list) | ||
}) | ||
} | ||
|
||
exports.add = (request, reply) => { | ||
// request.server.app.ipfs.id((err, id) => { | ||
// if (err) { return reply(boom.badRequest(err)) } | ||
// return reply(id) | ||
// }) | ||
exports.add = { | ||
parseArgs: exports.parseKey, | ||
handler (request, reply) { | ||
const ipfs = request.server.app.ipfs | ||
const addr = request.pre.args.addr | ||
|
||
ipfs.bootstrap.add(addr.toString(), (err, list) => { | ||
if (err) { | ||
return reply(boom.badRequest(err)) | ||
} | ||
return reply() | ||
}) | ||
} | ||
} | ||
|
||
exports.rm = (request, reply) => { | ||
// request.server.app.ipfs.id((err, id) => { | ||
// if (err) { return reply(boom.badRequest(err)) } | ||
// return reply(id) | ||
// }) | ||
exports.rm = { | ||
parseArgs: exports.parseKey, | ||
handler (request, reply) { | ||
const ipfs = request.server.app.ipfs | ||
const addr = request.pre.args.addr | ||
|
||
ipfs.bootstrap.rm(addr.toString(), (err, list) => { | ||
if (err) { | ||
return reply(boom.badRequest(err)) | ||
} | ||
return reply() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.