git ssb

0+

Matt McKegg / ssb-about



Commit 25a70276fabd9332f9e03d154fd2fc70b553cc2d

initial commit

Matt McKegg committed on 6/12/2017, 11:56:18 AM

Files changed

.gitignoreadded
README.mdadded
index.jsadded
package.jsonadded
.gitignoreView
@@ -1,0 +1,1 @@
1 +node_modules
README.mdView
@@ -1,0 +1,7 @@
1 +# ssb-about
2 +
3 +[scuttlebot](http://scuttlebutt.nz/) plugin for indexing reduced "about" state.
4 +
5 +## License
6 +
7 +MIT
index.jsView
@@ -1,0 +1,55 @@
1 +var FlumeReduce = require('flumeview-reduce')
2 +var ref = require('ssb-ref')
3 +
4 +exports.name = 'about'
5 +exports.version = require('./package.json').version
6 +exports.manifest = {
7 + stream: 'source',
8 + get: 'async'
9 +}
10 +
11 +exports.init = function (ssb, config) {
12 + return ssb._flumeUse('about', FlumeReduce(0, reduce, map))
13 +}
14 +
15 +function reduce (result, item) {
16 + if (!result) result = {}
17 + if (item) {
18 + for (var target in item) {
19 + var valuesForId = result[target] = result[target] || {}
20 + for (var key in item[target]) {
21 + var valuesForKey = valuesForId[key] = valuesForId[key] || {}
22 + for (var author in item[target][key]) {
23 + var value = item[target][key][author]
24 + if (!valuesForKey[author] || value.lastSeq > valuesForKey[author].lastSeq) {
25 + valuesForKey[author] = value
26 + }
27 + }
28 + }
29 + }
30 + }
31 + return result
32 +}
33 +
34 +function map (msg) {
35 + if (msg.value.content && msg.value.content.type === 'about' && ref.isLink(msg.value.content.about)) {
36 + var author = msg.value.author
37 + var target = msg.value.content.about
38 + var values = {}
39 +
40 + for (var key in msg.value.content) {
41 + if (key !== 'about' && key !== 'type') {
42 + values[key] = {
43 + [author]: {
44 + value: msg.value.content[key],
45 + lastSeq: msg.value.sequence
46 + }
47 + }
48 + }
49 + }
50 +
51 + return {
52 + [target]: values
53 + }
54 + }
55 +}
package.jsonView
@@ -1,0 +1,18 @@
1 +{
2 + "name": "ssb-about",
3 + "description": "scuttlebot plugin for getting reduced 'about' state",
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 + "flumeview-reduce": "^1.1.0",
12 + "ssb-ref": "^2.7.1"
13 + },
14 + "devDependencies": {},
15 + "scripts": {},
16 + "author": "Secure Scuttlebutt Consortium",
17 + "license": "MIT"
18 +}

Built with git-ssb-web