Files: cd8ac2d0fc9c1f5e2e287e2a0f67c68c8b2e417d / async / fetch.js
639 bytesRaw
1 | const isBlog = require('../isBlog') |
2 | |
3 | // TODO take blog or blogKey? |
4 | |
5 | module.exports = function (server) { |
6 | return function fetch (blog, cb) { |
7 | if (!isBlog(blog)) return cb(`Not a valid blog ${JSON.stringify(blog, null, 2)}`) |
8 | |
9 | server.blobs.want(getBlob(blog), (err, success) => { |
10 | if (err) { |
11 | if (cb) return cb(err) |
12 | else throw err |
13 | } |
14 | |
15 | cb(null, success) |
16 | }) |
17 | } |
18 | } |
19 | |
20 | function getBlob (msg) { |
21 | // is msg of form { key, value } |
22 | if (msg.value.content && msg.value.content.blog) return msg.value.content.blog |
23 | // is just body of the message, 'msg content' |
24 | else if (msg.blog) return msg.blog |
25 | } |
26 | |
27 |
Built with git-ssb-web