git ssb

0+

mixmix / scuttle-blog



Tree: cd8ac2d0fc9c1f5e2e287e2a0f67c68c8b2e417d

Files: cd8ac2d0fc9c1f5e2e287e2a0f67c68c8b2e417d / obs / get.js

864 bytesRaw
1const { Struct, Value, Array: MutantArray } = require('mutant')
2const pull = require('pull-stream')
3const fetch = require('../async/fetch')
4const isBlog = require('../isBlog')
5const Blog = require('../struct')
6const getMsgContent = require('../lib/getMsgContent')
7
8module.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