Files: cd8ac2d0fc9c1f5e2e287e2a0f67c68c8b2e417d / async / get.js
821 bytesRaw
1 | const { resolve } = 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 asyncGet (blogMsg, cb) { |
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 cb(err) |
16 | if (!success) return cb(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 cb(err) |
22 | |
23 | obs.body.set(Buffer.concat(ary).toString()) |
24 | cb(null, resolve(obs)) |
25 | }) |
26 | ) |
27 | }) |
28 | } |
29 | } |
30 | |
31 |
Built with git-ssb-web