aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Whitmore <sww@eight45.net>2018-04-16 12:05:59 -0700
committerStephen Whitmore <sww@eight45.net>2018-04-16 13:27:38 -0700
commitb037d20c242f538c48bf87cd060435b1e7cc2dc7 (patch)
tree5360ed29750ac4c5e31559f547ffce312b496081
parent4267334f1d3b50038c43b2f41e1fb5da2e9dbd6c (diff)
downloadpatchfoo-b037d20c242f538c48bf87cd060435b1e7cc2dc7.tar.gz
patchfoo-b037d20c242f538c48bf87cd060435b1e7cc2dc7.zip
feat: handle /web blob websites
-rw-r--r--lib/serve.js25
-rw-r--r--package.json1
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/serve.js b/lib/serve.js
index 004079b..4c60cce 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -25,6 +25,7 @@ var Catch = require('pull-catch')
var Diff = require('diff')
var split = require('pull-split')
var utf8 = require('pull-utf8-decoder')
+var webresolve = require('ssb-web-resolver')
module.exports = Serve
@@ -352,6 +353,7 @@ Serve.prototype.path = function (url) {
case '/npm-readme': return this.npmReadme(m[2])
case '/markdown': return this.markdown(m[2])
case '/zip': return this.zip(m[2])
+ case '/web': return this.web(m[2])
}
return this.respond(404, 'Not found')
}
@@ -2652,6 +2654,29 @@ Serve.prototype.zip = function (url) {
})
}
+Serve.prototype.web = function (url) {
+ var self = this
+ var id = decodeURIComponent(url.substr(1))
+
+ var components = url.split('/')
+ if (components[0] === '') components.shift()
+ components[0] = decodeURIComponent(components[0])
+
+ webresolve(this.app.sbot, components, function (err, res) {
+ if (err) {
+ return pull(
+ pull.once('ERROR:', err),
+ self.respondSink(404)
+ )
+ }
+
+ return pull(
+ pull.once(res),
+ self.respondSink(200)
+ )
+ })
+}
+
// wrap a binary source and render it or turn into an embed
Serve.prototype.wrapBinary = function (opts) {
var self = this
diff --git a/package.json b/package.json
index 26dcfa2..20055ed 100644
--- a/package.json
+++ b/package.json
@@ -33,6 +33,7 @@
"ssb-marked": "^0.7.1",
"ssb-mentions": "http://localhost:8989/blobs/get/&GjuxknqKwJqHznKueFNCyIh52v1woz5PB41vqmoHfyM=.sha256",
"ssb-sort": "^1.0.0",
+ "ssb-web-resolver": "^1.0.2",
"stream-to-pull-stream": "^1.7.2",
"unzip": "^0.1.11"
},