Commit 6787cc5778ab73694fedeb3f50bcce2da71f782f
improved URI parsing
dust committed on 4/9/2016, 6:58:17 PMParent: 578ffa8b1012f2827ca12664c52bd3cca2dd9757
Files changed
os/parser | changed |
os/parser | ||
---|---|---|
@@ -11,11 +11,15 @@ | ||
11 | 11 | payloadArray = parsedURI.query.split(/[\=\&]/) |
12 | 12 | |
13 | 13 | // convert to key-val dict |
14 | 14 | var payload = {} |
15 | -for (var i = 0, len = payloadArray.length ; i<len ; i+=2) { | |
16 | - payload[payloadArray[i]] = (payloadArray[i+1]) | |
17 | -} | |
15 | +var keysToParse = ['body', 'title', 'src', 'comment', 'channel', 'mentions'] | |
16 | +keysToParse.forEach(function(key) { | |
17 | + const keyPos = payloadArray.indexOf(key) | |
18 | + if (keyPos !== -1) { | |
19 | + payload[key] = payloadArray[keyPos + 1] | |
20 | + } | |
21 | +}) | |
18 | 22 | |
19 | 23 | // decode payload from base64 |
20 | 24 | payload.body = unescape(new Buffer(payload.body, 'base64').toString()) |
21 | 25 | if (typeof payload.comment === 'string') { |
@@ -23,9 +27,9 @@ | ||
23 | 27 | } |
24 | 28 | payload.title = unescape(payload.title) |
25 | 29 | payload.channel = unescape(payload.channel) |
26 | 30 | |
27 | -// ssbify the dang thing, finally | |
31 | +// ssbify the thing, finally | |
28 | 32 | var ssbifyString = require('ssbify-string') |
29 | 33 | var ssbClient = require('ssb-client') |
30 | 34 | |
31 | 35 | ssbClient(function (err, sbot) { |
Built with git-ssb-web