Files: ca718f616a051e93adeb22faa3fc06646f667973 / assets / api.js
957 bytesRaw
1 | const { join } = require('path') |
2 | const sendJson = require('send-data/json') |
3 | const sendError = require('send-data/error') |
4 | const pull = require('pull-stream') |
5 | const toPull = require('stream-to-pull-stream') |
6 | const Assets = require('bankai') |
7 | |
8 | module.exports = AssetsApi |
9 | |
10 | function AssetsApi (ssb, config) { |
11 | const clientPath = join(__dirname, '../browser.js') |
12 | const assets = Assets(clientPath) |
13 | |
14 | return (req, res, next) => { |
15 | if (req.url === '/') { |
16 | assets.html(req, res).pipe(res) |
17 | } else if (req.url.substring(0, 7) === '/blobs/') { |
18 | const id = req.url.substring(7) |
19 | sendBlob(id, req, res) |
20 | } else if (req.url === '/bundle.js') { |
21 | assets.js(req, res).pipe(res) |
22 | } else if (req.url === '/bundle.css') { |
23 | assets.css(req, res).pipe(res) |
24 | } else next() |
25 | } |
26 | |
27 | function sendBlob (id, req, res) { |
28 | pull( |
29 | ssb.blobs.get(id), |
30 | toPull(res) |
31 | ) |
32 | } |
33 | |
34 | function getBlob (id) { |
35 | return ssb.blobs.get(id) |
36 | } |
37 | } |
38 |
Built with git-ssb-web