git ssb

0+

Matt McKegg / ssb-backlinks



Tree: 4a84a761c29ecd2e1b840ea5d875a5958fe47c24

Files: 4a84a761c29ecd2e1b840ea5d875a5958fe47c24 / index.js

1386 bytesRaw
1var FlumeQueryLinks = require('./lib/flumeview-links-raw')
2var ssbKeys = require('ssb-keys')
3var toUrlFriendly = require('base64-url').escape
4var emitLinks = require('./emit-links')
5
6var indexes = [
7 { key: 'DTS', value: [['dest'], ['timestamp']] },
8 { key: 'DTA', value: [['dest'], ['rts']] }, // asserted timestamp
9 { key: 'TDT', value: [['value', 'content', 'type'], ['dest'], ['rts']] }
10]
11
12var indexVersion = 7
13
14exports.name = 'backlinks'
15exports.version = require('./package.json').version
16exports.manifest = {
17 read: 'source'
18}
19
20exports.init = function (ssb, config) {
21 return ssb._flumeUse(
22 `backlinks-${toUrlFriendly(ssb.id.slice(1, 10))}`,
23 FlumeQueryLinks(indexes, emitLinks, indexVersion, unbox)
24 )
25
26 function unbox (msg) {
27 if (typeof msg.value.content === 'string') {
28 var value = unboxValue(msg.value)
29 if (value) {
30 return {
31 key: msg.key, value: value, timestamp: msg.timestamp
32 }
33 }
34 }
35 return msg
36 }
37
38 function unboxValue (value) {
39 var plaintext = null
40 try {
41 plaintext = ssbKeys.unbox(value.content, ssb.keys.private)
42 } catch (ex) {}
43 if (!plaintext) return null
44 return {
45 previous: value.previous,
46 author: value.author,
47 sequence: value.sequence,
48 timestamp: value.timestamp,
49 hash: value.hash,
50 content: plaintext,
51 private: true
52 }
53 }
54}
55

Built with git-ssb-web