git ssb

0+

Matt McKegg / ssb-backlinks



Commit ef2c601a248ad8bb704a322364e0c04aaac98dd6

also index private messages

Matt McKegg committed on 6/17/2017, 12:43:52 AM
Parent: 06963db96c5b71a42282a6f2adfe0baf0bd088e8

Files changed

README.mdchanged
index.jschanged
lib/flumeview-links-raw.jschanged
package.jsonchanged
README.mdView
@@ -1,7 +1,7 @@
11 # ssb-backlinks
22
3-[scuttlebot](http://scuttlebutt.nz/) plugin for indexing all link mentions of messages.
3 +[scuttlebot](http://scuttlebutt.nz/) plugin for indexing all link mentions of messages (including private for the current identity).
44
55 Walks all values of a message searching for [ssb-ref](https://github.com/ssbc/ssb-ref) recognized keys. Provides an [ssb-query](https://github.com/dominictarr/ssb-query) style interface.
66
77 ## License
index.jsView
@@ -2,16 +2,18 @@
22 var ref = require('ssb-ref')
33 var deepEqual = require('deep-equal')
44 var extend = require('xtend')
55 var matchChannel = /^#[^\s#]+$/
6 +var ssbKeys = require('ssb-keys')
7 +var toUrlFriendly = require('base64-url').escape
68
79 var indexes = [
810 { key: 'DTS', value: [['dest'], ['timestamp']] },
911 { key: 'DTA', value: [['dest'], ['value', 'timestamp']] }, // asserted timestamp
1012 { key: 'TDT', value: [['value', 'content', 'type'], ['dest'], ['value', 'timestamp']] }
1113 ]
1214
13-var indexVersion = 2
15 +var indexVersion = 3
1416
1517 exports.name = 'backlinks'
1618 exports.version = require('./package.json').version
1719 exports.manifest = {
@@ -19,11 +21,40 @@
1921 }
2022
2123 exports.init = function (ssb, config) {
2224 return ssb._flumeUse(
23- 'backlinks',
24- FlumeQueryLinks(indexes, extractLinks, indexVersion)
25 + `backlinks-${toUrlFriendly(ssb.id.slice(1, 10))}`,
26 + FlumeQueryLinks(indexes, extractLinks, indexVersion, unbox)
2527 )
28 +
29 + function unbox (msg) {
30 + if (typeof msg.value.content === 'string') {
31 + var value = unboxValue(msg.value)
32 + if (value) {
33 + return {
34 + key: msg.key, value: value, timestamp: msg.timestamp
35 + }
36 + }
37 + }
38 + return msg
39 + }
40 +
41 + function unboxValue (value) {
42 + var plaintext = null
43 + try {
44 + plaintext = ssbKeys.unbox(value.content, ssb.keys.private)
45 + } catch (ex) {}
46 + if (!plaintext) return null
47 + return {
48 + previous: value.previous,
49 + author: value.author,
50 + sequence: value.sequence,
51 + timestamp: value.timestamp,
52 + hash: value.hash,
53 + content: plaintext,
54 + private: true
55 + }
56 + }
2657 }
2758
2859 function extractLinks (msg, emit) {
2960 var links = new Set()
lib/flumeview-links-raw.jsView
@@ -1,5 +1,6 @@
@@ -10,13 +11,9 @@
@@ -33,18 +30,20 @@
@@ -83,9 +82,8 @@
@@ -96,13 +94,17 @@
package.jsonView
@@ -7,14 +7,16 @@
77 "type": "git",
88 "url": "git://github.com/ssbc/ssb-backlinks.git"
99 },
1010 "dependencies": {
11 + "base64-url": "^1.3.3",
1112 "deep-equal": "^1.0.1",
1213 "flumeview-level": "^2.0.3",
1314 "flumeview-query": "^3.0.3",
1415 "map-filter-reduce": "^3.0.3",
1516 "pull-flatmap": "0.0.1",
1617 "pull-stream": "^3.6.0",
18 + "ssb-keys": "^7.0.9",
1719 "ssb-ref": "^2.7.1",
1820 "xtend": "^4.0.1"
1921 },
2022 "devDependencies": {},

Built with git-ssb-web