git ssb

9+

cel / ssb-viewer



Commit 01ecbe27dbc13188bc4d92afa7856145282ecc96

Merge web branch

Anders Rune Jensen committed on 4/20/2018, 7:04:00 PM
Parent: ab4973d90c791719438173dbbb74eaecc9f467a3
Parent: c71fb2a0899fe94c63306d8822b797c6dd42ef68

Files changed

index.jschanged
package.jsonchanged
index.jsView
@@ -8,8 +8,9 @@
88 var sort = require('ssb-sort')
99 var toPull = require('stream-to-pull-stream')
1010 var memo = require('asyncmemo')
1111 var lru = require('lrucache')
12 +var webresolve = require('ssb-web-resolver')
1213 var serveEmoji = require('emoji-server')()
1314 var {
1415 MdRenderer,
1516 renderEmoji,
@@ -176,8 +177,30 @@
176177 })
177178 })
178179 }
179180
181 + exports.serveWeb = function(req, res, url) {
182 + var self = this
183 + var id = decodeURIComponent(url.substr(1))
184 +
185 + var components = url.split('/')
186 + if (components[0] === '') components.shift()
187 + if (components[0] === 'web') components.shift()
188 + components[0] = decodeURIComponent(components[0])
189 +
190 + webresolve(sbot, components, function (err, data) {
191 + if (err) {
192 + return respond(res, 404, 'ERROR: ' + err)
193 + }
194 + return pull(
195 + pull.once(data),
196 + toPull(res, function (err) {
197 + if (err) console.error('[viewer]', err)
198 + })
199 + )
200 + })
201 + }
202 +
180203 function serveFeeds(req, res, following, channelSubscriptions, feedId, name) {
181204 var feedOpts = Object.assign({}, defaultOpts, {
182205 renderPrivate: false,
183206 renderSubscribe: false,
@@ -394,8 +417,9 @@
394417 return exports.serveUserFeed(req, res, m[4].substring(m[4].lastIndexOf('user-feed/')+10, 100))
395418 else if (req.url.startsWith('/channel/'))
396419 return exports.serveChannel(req, res, m[4].substring(m[4].lastIndexOf('channel/')+8, 100))
397420 else if (req.url.startsWith('/.well-known/acme-challenge')) return serveAcmeChallenge(req, res)
421 + else if (req.url.startsWith('/web/')) return exports.serveWeb(req, res, m[4])
398422
399423 if (m[2] && m[2].length === 3) {
400424 m[1] = decodeURIComponent(m[1])
401425 m[2] = m[1][0]
package.jsonView
@@ -18,8 +18,9 @@
1818 "ssb-client": "^4.5.2",
1919 "ssb-marked": "^0.7.3",
2020 "ssb-ref": "^2.9.0",
2121 "ssb-sort": "^1.0.0",
22 + "ssb-web-resolver": "^1.0.4",
2223 "stream-to-pull-stream": "^1.7.2"
2324 },
2425 "devDependencies": {
2526 "tape": "^4.6.2"

Built with git-ssb-web