git ssb

0+

mixmix / scuttle-blog



Tree: ab2a7ca4c54c5bcaaffdd55eaad2490350509757

Files: ab2a7ca4c54c5bcaaffdd55eaad2490350509757 / async / fetch.js

643 bytesRaw
1const isBlog = require('../isBlog')
2
3// TODO take blog or blogKey?
4
5module.exports = function (server) {
6 return function fetch (blog, cb) {
7 if (!isBlog(blog)) return cb(new Error(`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
20function 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

Built with git-ssb-web