Files: 7c528349577470dee18f77f63097c8b28f7825fa / gathering / async / get.js
997 bytesRaw
1 | const { isUpdate, isAttendee } = require('ssb-gathering-schema') |
2 | const merge = require('lodash.merge') |
3 | const getBacklinks = require('../../lib/get-backlinks') |
4 | const permittedOpts = require('../../lib/permitted-opts') |
5 | |
6 | module.exports = function (server) { |
7 | return function getGathering (key, cb) { |
8 | server.get(key, (err, value) => { |
9 | if (err) return cb(err) |
10 | |
11 | const doc = { key, value } |
12 | |
13 | getBacklinks(server)(doc, (err, backlinks) => { |
14 | if (err) return cb(err) |
15 | |
16 | const updates = backlinks |
17 | .filter(isUpdate) |
18 | .map(m => permittedOpts(m.value.content)) |
19 | .reduce((acc, update) => { |
20 | const { image } = update |
21 | if (image) { |
22 | acc.image = image |
23 | if (!acc.images.find(i => i.link === image.link)) acc.images.push(image) |
24 | delete update.image |
25 | } |
26 | |
27 | return merge(acc, update) |
28 | }, { images: [] }) |
29 | |
30 | cb(null, merge(doc, updates)) |
31 | }) |
32 | }) |
33 | } |
34 | } |
35 |
Built with git-ssb-web