Skip to content

Commit

Permalink
added resolve command
Browse files Browse the repository at this point in the history
  • Loading branch information
jbenet committed Jun 26, 2018
1 parent de9ca2f commit 3a1ce58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",

This comment has been minimized.

Copy link
@jbenet

jbenet Jun 26, 2018

Author Contributor

js-ipfs-api needs a new command -- i added it and PRed it here: ipfs-inactive/js-ipfs-http-client#794 -- but until that's merged have to install from this commit.

"underscore": "^1.9.1"
},
"engines": {
Expand Down
26 changes: 18 additions & 8 deletions scripts/ipfs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand Down

0 comments on commit 3a1ce58

Please sign in to comment.