git ssb

3+

dust / capsule



Commit a7de32004c62ccfee0c58ceabf82fa58c35d2158

added parser file

dust committed on 4/4/2016, 5:06:00 AM
Parent: bd3e4314469072052f476a8acb6945b96e85b121

Files changed

package.jsonchanged
os/parseradded
package.jsonView
@@ -14,6 +14,13 @@
1414 "scuttlebot",
1515 "swarmbot"
1616 ],
1717 "author": "du5t",
18- "license": "AGPL-3.0"
18+ "license": "AGPL-3.0",
19+ "devDependencies": {
20+ "browserify": "^13.0.0",
21+ "ssb-client": "^3.0.1"
22+ },
23+ "dependencies": {
24+ "ssbify-string": "git://github.com/du5t/ssbify-string.git"
25+ }
1926 }
os/parserView
@@ -1,0 +1,43 @@
1+#!/usr/bin/env node
2+
3+var fs = require('fs')
4+fs.writeFileSync('capsule.log', 'node parser was called but did not catch', 'utf8')
5+
6+var url = require('url')
7+
8+// parse URL, split up query params
9+var uri = process.argv[2]
10+var parsedURI = url.parse(uri)
11+payloadArray = parsedURI.query.split(/[\=\&]/)
12+
13+// convert to key-val dict
14+var payload = {}
15+for (var i = 0, len = payloadArray.length ; i<len ; i+=2) {
16+ payload[payloadArray[i]] = (payloadArray[i+1])
17+}
18+
19+// decode body from base64
20+payload.body = unescape(new Buffer(payload.body, 'base64').toString())
21+payload.title = unescape(payload.title)
22+
23+// ssbify the dang thing, finally
24+var ssbifyString = require('ssbify-string')
25+var ssbClient = require('ssb-client')
26+
27+ssbClient(function (err, sbot) {
28+ if (err) fs.writeFileSync('capsule.log', err, 'utf8')
29+
30+ ssbifyString(
31+ sbot, payload.body,
32+ { ignoreBrokenLinks: true, url: payload.src, title: payload.title },
33+ function(err, res) {
34+ if (err) fs.writeFileSync('capsule.log', err, 'utf8')
35+
36+ // publish a message
37+ sbot.publish({ type: 'post', text: res, channel: 'test' },
38+ function (err, msg) {
39+ if (err) fs.writeFileSync('capsule.log', err, 'utf8')
40+ })
41+
42+ })
43+})

Built with git-ssb-web