git ssb

2+

dinoworm ๐Ÿ› / ssb-graphviz



Tree: e8b919558c93da12334cc6e605de9d1828ddb297

Files: e8b919558c93da12334cc6e605de9d1828ddb297 / assets / api.js

845 bytesRaw
1const { join } = require('path')
2const pull = require('pull-stream')
3const toPull = require('stream-to-pull-stream')
4const Assets = require('bankai')
5
6module.exports = AssetsApi
7
8function AssetsApi (ssb, config) {
9 const clientPath = join(__dirname, '../browser.js')
10 const assets = Assets(clientPath)
11
12 return (req, res, next) => {
13 if (req.url === '/') {
14 assets.html(req, res).pipe(res)
15 } else if (req.url.substring(0, 7) === '/blobs/') {
16 const id = req.url.substring(7)
17 sendBlob(id, req, res)
18 } else if (req.url === '/bundle.js') {
19 assets.js(req, res).pipe(res)
20 } else if (req.url === '/bundle.css') {
21 assets.css(req, res).pipe(res)
22 } else next()
23 }
24
25 function sendBlob (id, req, res) {
26 pull(getBlob(id), toPull(res))
27 }
28
29 function getBlob (id) {
30 return ssb.blobs.get(id)
31 }
32}
33

Built with git-ssb-web