git ssb

10+

Matt McKegg / patchwork



Commit 660713a09e56ca4799e4f891a0d70851cd142b51

use ssb-ws instead of serve-blobs.js, support secret blobs

Matt McKegg committed on 4/12/2018, 1:08:14 AM
Parent: 59a186b48e46c8378f67af13b60fcc8acc3607a9

Files changed

index.jschanged
lib/serve-blobs.jsdeleted
main-window.jschanged
package.jsonchanged
plugs/blob/sync/url.jschanged
server-process.jschanged
index.jsView
@@ -131,9 +131,9 @@
131131
132132 function setupContext (appName, opts, cb) {
133133 ssbConfig = require('ssb-config/inject')(appName, extend({
134134 port: 8008,
135- blobsPort: 7777,
135+ blobsPort: 8989, // matches ssb-ws
136136 friends: {
137137 dunbar: 150,
138138 hops: 2 // down from 3
139139 }
lib/serve-blobs.jsView
@@ -1,71 +1,0 @@
1-var pull = require('pull-stream')
2-var cat = require('pull-cat')
3-var toPull = require('stream-to-pull-stream')
4-var ident = require('pull-identify-filetype')
5-var mime = require('mime-types')
6-var URL = require('url')
7-var http = require('http')
8-
9-module.exports = function (context, cb) {
10- return http.createServer(ServeBlobs(context.sbot)).listen(context.config.blobsPort, cb)
11-}
12-
13-function ServeBlobs (sbot) {
14- return function (req, res, next) {
15- var parsed = URL.parse(req.url, true)
16- var hash = decodeURIComponent(parsed.pathname.slice(1))
17- waitFor(hash, function (_, has) {
18- if (!has) return respond(res, 404, 'File not found')
19- // optional name override
20- if (parsed.query.name) {
21- res.setHeader('Content-Disposition', 'inline; filename=' + encodeURIComponent(parsed.query.name))
22- }
23-
24- // serve
25- res.setHeader('Content-Security-Policy', BlobCSP())
26- respondSource(res, sbot.blobs.get(hash), false)
27- })
28- }
29-
30- function waitFor (hash, cb) {
31- sbot.blobs.has(hash, function (err, has) {
32- if (err) return cb(err)
33- if (has) {
34- cb(null, has)
35- } else {
36- sbot.blobs.want(hash, cb)
37- }
38- })
39- }
40-}
41-
42-function respondSource (res, source, wrap) {
43- if (wrap) {
44- res.writeHead(200, {'Content-Type': 'text/html'})
45- pull(
46- cat([
47- pull.once('<html><body><script>'),
48- source,
49- pull.once('</script></body></html>')
50- ]),
51- toPull.sink(res)
52- )
53- } else {
54- pull(
55- source,
56- ident(function (type) {
57- if (type) res.writeHead(200, {'Content-Type': mime.lookup(type)})
58- }),
59- toPull.sink(res)
60- )
61- }
62-}
63-
64-function respond (res, status, message) {
65- res.writeHead(status)
66- res.end(message)
67-}
68-
69-function BlobCSP () {
70- return 'default-src none; sandbox'
71-}
main-window.jsView
@@ -141,9 +141,9 @@
141141
142142 catchLinks(container, (href, external, anchor) => {
143143 if (external) {
144144 electron.shell.openExternal(href)
145- } else if (ref.isBlob(href)) {
145+ } else if (href && href.startsWith('&')) { // (ref.isBlob(href)) {
146146 electron.shell.openExternal(api.blob.sync.url(href))
147147 } else if (ref.isMsg(href)) {
148148 getExternalHandler(href, (err, handler) => {
149149 if (!err && handler) {
package.jsonView
@@ -36,20 +36,18 @@
3636 "i18n": "^0.8.3",
3737 "level": "~1.7.0",
3838 "lrucache": "^1.0.2",
3939 "micro-css": "^2.0.1",
40- "mime-types": "^2.1.15",
4140 "moment": "^2.18.1",
4241 "mutant": "^3.21.2",
4342 "mutant-pull-reduce": "^1.1.0",
4443 "obv": "0.0.1",
4544 "patch-settings": "~1.1.0",
46- "patchcore": "~1.24.0",
45+ "patchcore": "~1.24.1",
4746 "pull-abortable": "^4.1.0",
4847 "pull-cat": "^1.1.11",
4948 "pull-defer": "^0.2.2",
5049 "pull-file": "~1.0.0",
51- "pull-identify-filetype": "^1.1.0",
5250 "pull-next": "~1.0.0",
5351 "pull-notify": "^0.1.1",
5452 "pull-paramap": "^1.2.2",
5553 "pull-pause": "~0.0.1",
@@ -74,8 +72,9 @@
7472 "ssb-private": "0.1.4",
7573 "ssb-query": "^1.0.0",
7674 "ssb-ref": "^2.9.0",
7775 "ssb-sort": "^1.0.0",
76+ "ssb-ws": "~2.1.1",
7877 "standard": "^11.0.1",
7978 "statistics": "^3.3.0",
8079 "stream-to-pull-stream": "^1.7.2",
8180 "suggest-box": "^2.2.3",
plugs/blob/sync/url.jsView
@@ -8,11 +8,11 @@
88
99 exports.create = function (api) {
1010 return nest('blob.sync.url', function (link) {
1111 var config = api.config.sync.load()
12- var prefix = config.blobsPrefix != null ? config.blobsPrefix : `http://localhost:${config.blobsPort}`
12+ var prefix = config.blobsPrefix != null ? config.blobsPrefix : `http://localhost:${config.ws.port}/blobs/get`
1313 if (link && typeof link.link === 'string') {
1414 link = link.link
1515 }
16- return `${prefix}/${encodeURIComponent(link)}`
16+ return `${prefix}/${link}`
1717 })
1818 }
server-process.jsView
@@ -1,5 +1,4 @@
1-var serveBlobs = require('./lib/serve-blobs')
21 var fs = require('fs')
32 var Path = require('path')
43 var electron = require('electron')
54 var spawn = require('child_process').spawn
@@ -17,8 +16,9 @@
1716 .use(require('scuttlebot/plugins/local'))
1817 .use(require('scuttlebot/plugins/logging'))
1918 .use(require('ssb-query'))
2019 .use(require('ssb-about'))
20+ .use(require('ssb-ws'))
2121 // .use(require('ssb-ebt')) // enable at your own risk!
2222 .use(require('./sbot'))
2323
2424 fixPath()
@@ -28,9 +28,8 @@
2828 sbot: createSbot(ssbConfig),
2929 config: ssbConfig
3030 }
3131 ssbConfig.manifest = context.sbot.getManifest()
32- serveBlobs(context)
3332 fs.writeFileSync(Path.join(ssbConfig.path, 'manifest.json'), JSON.stringify(ssbConfig.manifest))
3433 electron.ipcRenderer.send('server-started', ssbConfig)
3534
3635 // attempt to run git-ssb if it is installed and in path

Built with git-ssb-web