git ssb

16+

Dominic / patchbay



Commit cb94bd0d83fae7b007a0e33061df18c620bd6cb1

make sbot apis into a plugin

Dominic Tarr committed on 5/29/2016, 11:13:41 AM
Parent: 682c62ee009cae46f4f5328ce86d4c2b938b2eb2

Files changed

index.jschanged
sbot-api.jsadded
index.jsView
@@ -3,24 +3,32 @@
33 var pull = require('pull-stream')
44 var combine = require('depject')
55 var fs = require('fs')
66 var path = require('path')
7+var SbotApi = require('./sbot-api')
78
89 document.head.appendChild(h('style', fs.readFileSync('./style.css', 'utf8')))
910
1011 var modules = fs.readdirSync(path.join(__dirname, 'modules'))
1112 .map(function (e) { return require('./modules/'+e) })
1213
1314 var renderers = []
1415 var app = []
15-modules.unshift({app: app})
1616
17-combine(modules)
1817
1918 var u = require('./util')
2019
2120 require('ssb-client')(function (err, sbot) {
2221 if(err) throw err
22+
23+ modules.unshift(SbotApi(sbot))
24+ modules.unshift({app: app})
25+ combine(modules)
26+
2327 document.body.appendChild(u.decorate(app, sbot))
2428 })
2529
2630
31+
32+
33+
34+
sbot-api.jsView
@@ -1,0 +1,39 @@
1+var pull = require('pull-stream')
2+var crypto = require('crypto')
3+
4+function Hash (onHash) {
5+ var hash = crypto.createHash('sha256')
6+ return pull.through(function (data) {
7+ hash.update(
8+ 'string' === typeof data
9+ ? new Buffer(data, 'utf8')
10+ : data
11+ )
12+ }, function (err) {
13+ if(err && !onHash) throw err
14+ onHash && onHash(err, '&'+hash.digest('base64')+'.sha256')
15+ })
16+}
17+
18+
19+module.exports = function (sbot) {
20+
21+ return {
22+ sbot_blobs_add: function (cb) {
23+ return pull(
24+ Hash(cb),
25+ sbot.blobs.add()
26+ )
27+ },
28+ sbot_links: function (query) {
29+ return sbot.links(query)
30+ },
31+ sbot_get: function (key, cb) {
32+ sbot.get(key, cb)
33+ },
34+ sbot_publish: function (msg, cb) {
35+ sbot.publish(msg, cb)
36+ }
37+ }
38+}
39+

Built with git-ssb-web