Files: 85899d9c65af617c7746ff686142b1bf2e513f20 / obs / get.js
798 bytesRaw
1 | const pull = require('pull-stream') |
2 | const fetch = require('../async/fetch') |
3 | const isBlog = require('../isBlog') |
4 | const Blog = require('../struct') |
5 | const getMsgContent = require('../lib/getMsgContent') |
6 | |
7 | module.exports = function (server) { |
8 | return function obsGet (blogMsg) { |
9 | if (!isBlog(blogMsg)) return // TODO handle this more gracefully? |
10 | |
11 | var obs = Blog(blogMsg) |
12 | |
13 | fetch(server)(blogMsg, (err, success) => { |
14 | if (err) return obs.errors.push(err) |
15 | if (!success) return obs.errors.push(new Error('Unable to fetch blob')) |
16 | |
17 | pull( |
18 | server.blobs.get(getMsgContent(blogMsg).blog), |
19 | pull.collect((err, ary) => { |
20 | if (err) return obs.errors.push(err) |
21 | |
22 | obs.body.set(Buffer.concat(ary).toString()) |
23 | }) |
24 | ) |
25 | }) |
26 | |
27 | return obs |
28 | } |
29 | } |
30 |
Built with git-ssb-web