git ssb

2+

dinoworm ๐Ÿ› / ssb-graphviz



Tree: 4ada924920b23d49a8e65386cd7a30e2ccfe3c59

Files: 4ada924920b23d49a8e65386cd7a30e2ccfe3c59 / assets / api.js

878 bytesRaw
1const { join } = require('path')
2const pull = require('pull-stream')
3const toPull = require('stream-to-pull-stream')
4const Assets = require('bankai')
5const Routes = require('http-routes')
6
7module.exports = AssetsApi
8
9function AssetsApi (ssb, config) {
10 const clientPath = join(__dirname, '../browser.js')
11 const assets = Assets(clientPath)
12
13 return Routes([
14 ['/', (req, res, next) => {
15 assets.html(req, res).pipe(res)
16 }],
17 ['/bundle.js', (req, res, next) => {
18 assets.js(req, res).pipe(res)
19 }],
20 ['/bundle.css', (req, res, next) => {
21 assets.css(req, res).pipe(res)
22 }],
23 ['/blobs/:blobId(.*)', {
24 get: (req, res, next) => {
25 sendBlob(req.params.blobId, req, res)
26 }
27 }]
28 ])
29
30 function sendBlob (id, req, res) {
31 pull(getBlob(id), toPull(res))
32 }
33
34 function getBlob (id) {
35 return ssb.blobs.get(id)
36 }
37}
38

Built with git-ssb-web