Commit 95a861ed6112ce439db8392d05ff9a592fb59a06
Factor out ssb client connection
Charles Lehner committed on 2/17/2016, 2:38:12 AMParent: c5a9bbb454761554e1299b537e5b13193072a06e
Files changed
bin.js | changed |
client.js | added |
bin.js | ||
---|---|---|
@@ -1,8 +1,7 @@ | ||
1 | 1 … | #!/usr/bin/env node |
2 | 2 … | |
3 | 3 … | var ref = require('ssb-ref') |
4 | -var ssbKeys = require('ssb-keys') | |
5 | 4 … | var path = require('path') |
6 | 5 … | var toPull = require('stream-to-pull-stream') |
7 | 6 … | var pull = require('pull-stream') |
8 | 7 … | var ssbGit = require('ssb-git') |
@@ -18,17 +17,9 @@ | ||
18 | 17 … | var root = m && m[1] |
19 | 18 … | if (!ref.isMsgId(root)) |
20 | 19 … | throw new Error(root || 'URL', 'is not a valid SSB message ID') |
21 | 20 … | |
22 | -var gitSsbConfig = require('parse-git-config').sync()['ssb'] | |
23 | -var appName = process.env.ssb_appname || gitSsbConfig.appname | |
24 | -var ssbConfig = require('ssb-config/inject')(appName, gitSsbConfig) | |
25 | - | |
26 | -var keys = ssbKeys.loadOrCreateSync(path.join(ssbConfig.path, 'secret')) | |
27 | -require('ssb-client')(keys, { | |
28 | - port: ssbConfig.port, | |
29 | - host: ssbConfig.host || 'localhost' | |
30 | -}, function (err, sbot) { | |
21 … | +require('./client')(function (err, sbot) { | |
31 | 22 … | if (err) throw err |
32 | 23 … | ssbGit.getRepo(sbot, root, function (err, repo) { |
33 | 24 … | if (err) { |
34 | 25 … | if (err.name == 'NotFoundError') |
client.js | |||
---|---|---|---|
@@ -1,0 +1,19 @@ | |||
1 … | +var path = require('path') | ||
2 … | +var ssbGit = require('ssb-git') | ||
3 … | +var ssbKeys = require('ssb-keys') | ||
4 … | + | ||
5 … | +module.exports = function createSSBClient(cb) { | ||
6 … | + require('parse-git-config')(function (err, gitConfig) { | ||
7 … | + if (err) return cb(err) | ||
8 … | + | ||
9 … | + var gitSsbConfig = gitConfig['ssb'] | ||
10 … | + var appName = process.env.ssb_appname || gitSsbConfig.appname | ||
11 … | + var ssbConfig = require('ssb-config/inject')(appName, gitSsbConfig) | ||
12 … | + | ||
13 … | + var keys = ssbKeys.loadOrCreateSync(path.join(ssbConfig.path, 'secret')) | ||
14 … | + require('ssb-client')(keys, { | ||
15 … | + port: ssbConfig.port, | ||
16 … | + host: ssbConfig.host || 'localhost' | ||
17 … | + }, cb) | ||
18 … | + }) | ||
19 … | +} |
Built with git-ssb-web