git ssb

39+

cel / git-ssb



Commit 95a861ed6112ce439db8392d05ff9a592fb59a06

Factor out ssb client connection

Charles Lehner committed on 2/17/2016, 2:38:12 AM
Parent: c5a9bbb454761554e1299b537e5b13193072a06e

Files changed

bin.jschanged
client.jsadded
bin.jsView
@@ -1,8 +1,7 @@
11 #!/usr/bin/env node
22
33 var ref = require('ssb-ref')
4-var ssbKeys = require('ssb-keys')
54 var path = require('path')
65 var toPull = require('stream-to-pull-stream')
76 var pull = require('pull-stream')
87 var ssbGit = require('ssb-git')
@@ -18,17 +17,9 @@
1817 var root = m && m[1]
1918 if (!ref.isMsgId(root))
2019 throw new Error(root || 'URL', 'is not a valid SSB message ID')
2120
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) {
3122 if (err) throw err
3223 ssbGit.getRepo(sbot, root, function (err, repo) {
3324 if (err) {
3425 if (err.name == 'NotFoundError')
client.jsView
@@ -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