git ssb

0+

Matt McKegg / ssb-backlinks



Commit 389fe124a06bd5e7915acd466ce8aaa047d4eaca

initial commit (extracted from patchcore fork)

Matt McKegg committed on 6/12/2017, 1:29:16 AM

Files changed

.gitignoreadded
README.mdadded
index.jsadded
lib/flumeview-links-raw.jsadded
package.jsonadded
.gitignoreView
@@ -1,0 +1,1 @@
1 +node_modules
README.mdView
@@ -1,0 +1,9 @@
1 +# ssb-backlinks
2 +
3 +[scuttlebot](http://scuttlebutt.nz/) plugin for indexing all link mentions of messages.
4 +
5 +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.
6 +
7 +## License
8 +
9 +MIT
index.jsView
@@ -1,0 +1,59 @@
1 +var FlumeQueryLinks = require('./lib/flumeview-links-raw')
2 +var ref = require('ssb-ref')
3 +var deepEqual = require('deep-equal')
4 +var extend = require('xtend')
5 +var matchChannel = /^#[^\s#]+$/
6 +
7 +var indexes = [
8 + { key: 'DTS', value: [['dest'], ['timestamp']] },
9 + { key: 'DTY', value: [['dest'], ['value', 'content', 'type'], ['timestamp']] }
10 +]
11 +
12 +var indexVersion = 0
13 +
14 +exports.name = 'backlinks'
15 +exports.version = require('./package.json').version
16 +exports.manifest = {
17 + read: 'source'
18 +}
19 +
20 +exports.init = function (ssb, config) {
21 + return ssb._flumeUse(
22 + 'backlinks',
23 + FlumeQueryLinks(indexes, extractLinks, indexVersion)
24 + )
25 +}
26 +
27 +function extractLinks (msg, emit) {
28 + var links = new Set()
29 + walk(msg.value.content, function (path, value) {
30 + // HACK: handle legacy channel mentions
31 + if (deepEqual(path, ['channel']) && typeof value === 'string' && value.length < 30) {
32 + value = `#${value.replace(/\s/g, '')}`
33 + }
34 +
35 + // TODO: should add channel matching to ref.type
36 + if (ref.type(value) || isChannel(value)) {
37 + links.add(value)
38 + }
39 + })
40 + links.forEach(link => {
41 + emit(extend(msg, {
42 + dest: link
43 + }))
44 + })
45 +}
46 +
47 +function isChannel (value) {
48 + return typeof value === 'string' && value.length < 30 && matchChannel.test(value)
49 +}
50 +
51 +function walk (obj, fn, prefix) {
52 + if (obj && typeof obj === 'object') {
53 + for (var k in obj) {
54 + walk(obj[k], fn, (prefix || []).concat(k))
55 + }
56 + } else {
57 + fn(prefix, obj)
58 + }
59 +}
lib/flumeview-links-raw.jsView
@@ -1,0 +1,105 @@
package.jsonView
@@ -1,0 +1,24 @@
1 +{
2 + "name": "ssb-backlinks",
3 + "description": "scuttlebot plugin for indexing all link mentions of messages",
4 + "version": "0.0.0",
5 + "homepage": "https://github.com/ssbc/ssb-backlinks",
6 + "repository": {
7 + "type": "git",
8 + "url": "git://github.com/ssbc/ssb-backlinks.git"
9 + },
10 + "dependencies": {
11 + "deep-equal": "^1.0.1",
12 + "flumeview-level": "^2.0.2",
13 + "flumeview-query": "^3.0.3",
14 + "map-filter-reduce": "^3.0.3",
15 + "pull-flatmap": "0.0.1",
16 + "pull-stream": "^3.6.0",
17 + "ssb-ref": "^2.7.1",
18 + "xtend": "^4.0.1"
19 + },
20 + "devDependencies": {},
21 + "scripts": {},
22 + "author": "Secure Scuttlebutt Consortium",
23 + "license": "MIT"
24 +}

Built with git-ssb-web