Commit 660713a09e56ca4799e4f891a0d70851cd142b51
use ssb-ws instead of serve-blobs.js, support secret blobs
Matt McKegg committed on 4/12/2018, 1:08:14 AMParent: 59a186b48e46c8378f67af13b60fcc8acc3607a9
Files changed
index.js | changed |
lib/serve-blobs.js | deleted |
main-window.js | changed |
package.json | changed |
plugs/blob/sync/url.js | changed |
server-process.js | changed |
index.js | ||
---|---|---|
@@ -131,9 +131,9 @@ | ||
131 | 131 | |
132 | 132 | function setupContext (appName, opts, cb) { |
133 | 133 | ssbConfig = require('ssb-config/inject')(appName, extend({ |
134 | 134 | port: 8008, |
135 | - blobsPort: 7777, | |
135 | + blobsPort: 8989, // matches ssb-ws | |
136 | 136 | friends: { |
137 | 137 | dunbar: 150, |
138 | 138 | hops: 2 // down from 3 |
139 | 139 | } |
lib/serve-blobs.js | ||
---|---|---|
@@ -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.js | ||
---|---|---|
@@ -141,9 +141,9 @@ | ||
141 | 141 | |
142 | 142 | catchLinks(container, (href, external, anchor) => { |
143 | 143 | if (external) { |
144 | 144 | electron.shell.openExternal(href) |
145 | - } else if (ref.isBlob(href)) { | |
145 | + } else if (href && href.startsWith('&')) { // (ref.isBlob(href)) { | |
146 | 146 | electron.shell.openExternal(api.blob.sync.url(href)) |
147 | 147 | } else if (ref.isMsg(href)) { |
148 | 148 | getExternalHandler(href, (err, handler) => { |
149 | 149 | if (!err && handler) { |
package.json | ||
---|---|---|
@@ -36,20 +36,18 @@ | ||
36 | 36 | "i18n": "^0.8.3", |
37 | 37 | "level": "~1.7.0", |
38 | 38 | "lrucache": "^1.0.2", |
39 | 39 | "micro-css": "^2.0.1", |
40 | - "mime-types": "^2.1.15", | |
41 | 40 | "moment": "^2.18.1", |
42 | 41 | "mutant": "^3.21.2", |
43 | 42 | "mutant-pull-reduce": "^1.1.0", |
44 | 43 | "obv": "0.0.1", |
45 | 44 | "patch-settings": "~1.1.0", |
46 | - "patchcore": "~1.24.0", | |
45 | + "patchcore": "~1.24.1", | |
47 | 46 | "pull-abortable": "^4.1.0", |
48 | 47 | "pull-cat": "^1.1.11", |
49 | 48 | "pull-defer": "^0.2.2", |
50 | 49 | "pull-file": "~1.0.0", |
51 | - "pull-identify-filetype": "^1.1.0", | |
52 | 50 | "pull-next": "~1.0.0", |
53 | 51 | "pull-notify": "^0.1.1", |
54 | 52 | "pull-paramap": "^1.2.2", |
55 | 53 | "pull-pause": "~0.0.1", |
@@ -74,8 +72,9 @@ | ||
74 | 72 | "ssb-private": "0.1.4", |
75 | 73 | "ssb-query": "^1.0.0", |
76 | 74 | "ssb-ref": "^2.9.0", |
77 | 75 | "ssb-sort": "^1.0.0", |
76 | + "ssb-ws": "~2.1.1", | |
78 | 77 | "standard": "^11.0.1", |
79 | 78 | "statistics": "^3.3.0", |
80 | 79 | "stream-to-pull-stream": "^1.7.2", |
81 | 80 | "suggest-box": "^2.2.3", |
plugs/blob/sync/url.js | ||
---|---|---|
@@ -8,11 +8,11 @@ | ||
8 | 8 | |
9 | 9 | exports.create = function (api) { |
10 | 10 | return nest('blob.sync.url', function (link) { |
11 | 11 | 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` | |
13 | 13 | if (link && typeof link.link === 'string') { |
14 | 14 | link = link.link |
15 | 15 | } |
16 | - return `${prefix}/${encodeURIComponent(link)}` | |
16 | + return `${prefix}/${link}` | |
17 | 17 | }) |
18 | 18 | } |
server-process.js | ||
---|---|---|
@@ -1,5 +1,4 @@ | ||
1 | -var serveBlobs = require('./lib/serve-blobs') | |
2 | 1 | var fs = require('fs') |
3 | 2 | var Path = require('path') |
4 | 3 | var electron = require('electron') |
5 | 4 | var spawn = require('child_process').spawn |
@@ -17,8 +16,9 @@ | ||
17 | 16 | .use(require('scuttlebot/plugins/local')) |
18 | 17 | .use(require('scuttlebot/plugins/logging')) |
19 | 18 | .use(require('ssb-query')) |
20 | 19 | .use(require('ssb-about')) |
20 | + .use(require('ssb-ws')) | |
21 | 21 | // .use(require('ssb-ebt')) // enable at your own risk! |
22 | 22 | .use(require('./sbot')) |
23 | 23 | |
24 | 24 | fixPath() |
@@ -28,9 +28,8 @@ | ||
28 | 28 | sbot: createSbot(ssbConfig), |
29 | 29 | config: ssbConfig |
30 | 30 | } |
31 | 31 | ssbConfig.manifest = context.sbot.getManifest() |
32 | - serveBlobs(context) | |
33 | 32 | fs.writeFileSync(Path.join(ssbConfig.path, 'manifest.json'), JSON.stringify(ssbConfig.manifest)) |
34 | 33 | electron.ipcRenderer.send('server-started', ssbConfig) |
35 | 34 | |
36 | 35 | // attempt to run git-ssb if it is installed and in path |
Built with git-ssb-web