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