From 3a1ce5893cdb0930683d14dd948867a3f14b2fed Mon Sep 17 00:00:00 2001 From: jbenet Date: Mon, 25 Jun 2018 21:36:37 -0700 Subject: [PATCH] added resolve command --- package.json | 2 +- scripts/ipfs.coffee | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 52a549c..c343640 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "hubot-scripts": "^2.17.2", "hubot-shipit": "^0.2.1", "hubot-slack": "^4.5.1", - "ipfs-api": "^22.1.0", + "ipfs-api": "github:ipfs/js-ipfs-api#f77bbf59392bd4ea5ed04db46882ed265fcdd231", "underscore": "^1.9.1" }, "engines": { diff --git a/scripts/ipfs.coffee b/scripts/ipfs.coffee index 3aebcdc..21854e4 100644 --- a/scripts/ipfs.coffee +++ b/scripts/ipfs.coffee @@ -281,6 +281,14 @@ runCmdContent = (cmdfn) -> (res) -> # pinbot implementation module.exports = (robot) -> + resolveToCid = (res, path, cb) -> + ipfs.resolve path, {r: true}, mustSucceed res, (path2) -> + if path2.substr(0, 6) != '/ipfs/' + return reportFail res, 'failed to resolve path. got: ' + path2 + cid = path2.substr(6) + console.log('resolve', path, path2, cid) + cb(cid) + # NODE INFO robot.respond /ipfs api-info/i, (res) -> res.send """ @@ -317,12 +325,13 @@ module.exports = (robot) -> # FILE COMMANDS robot.respond /ipfs files read (\S+)/i, runCmdContent ipfs.files.read robot.respond /ipfs files stat (\S+)/i, runCmd ipfs.files.stat - robot.respond /ipfs files ls (\S)?/i, runCmd ipfs.files.ls, + robot.respond /ipfs files ls (\S+)?/i, runCmd ipfs.files.ls, output: (o) -> _.pluck(o, 'name').join('\n') # NAME COMMANDS + robot.respond /ipfs resolve (\S+)/i, runCmdPath ipfs.resolve robot.respond /ipfs name resolve (\S+)/i, runCmd ipfs.name.resolve - robot.respond /ipfs dns (\S+)/i, runCmd ipfs.dns.resolve + robot.respond /ipfs dns (\S+)/i, runCmd ipfs.dns # REPO AND PINNING COMMANDS robot.respond /ipfs repo version/i, runCmd ipfs.repo.version @@ -334,12 +343,13 @@ module.exports = (robot) -> testApi res, -> res.send "pinning #{prettyPath path} (warning: experimental)" # todo: implement -r=false support (right now it assumes -r=true) - ipfs.refs path, {r: true}, mustSucceed res, (r) -> - ipfs.pin.add path, {r: true}, mustSucceed res, (r) -> - res.send """ - success: pinned recursively: #{prettyPath path} - (warning: this pinbot is experimental. do not rely on me yet.) - """ + resolveToCid res, path, (cid) -> + ipfs.refs cid, {r: true}, mustSucceed res, (r) -> + ipfs.pin.add cid, {r: true}, mustSucceed res, (r) -> + res.send """ + success: pinned recursively: #{prettyPath path} + (warning: this pinbot is experimental. do not rely on me yet.) + """ robot.respond /ipfs pin ls (\S+)/i, runCmdPath ipfs.pin.ls, output: (o) -> o.map((e) -> "#{e.hash} #{e.type}").join('\n')