Browse Source

add ext: protocol

Paul Frazee 5 years ago
parent
commit
fe030cb0e0
3 changed files with 20 additions and 1 deletions
  1. 5
    1
      app/index.js
  2. 14
    0
      app/lib/ext-protocol.js
  3. 1
    0
      package.json

+ 5
- 1
app/index.js View File

@@ -3,6 +3,7 @@ var Tray = require('tray')
3 3
 var Menu = require('menu')
4 4
 var shell = require('shell')
5 5
 var BrowserWindow = require('browser-window')
6
+
6 7
 var config = require('ssb-config') 
7 8
 
8 9
 // Report crashes to our server.
@@ -13,7 +14,10 @@ var mainWindow
13 14
 
14 15
 app.on('ready', function ready () {
15 16
   // start sbot
16
-	require('scuttlebot').init(config, function (err, sbot) {
17
+  require('scuttlebot').init(config, function (err, sbot) {
18
+    // register protocols
19
+    require('protocol').registerProtocol('ext', require('./lib/ext-protocol')(config))
20
+
17 21
     // open the web app
18 22
     // shell.openExternal('http://localhost:8008')
19 23
     mainWindow = new BrowserWindow({width: 1000, height: 720})

+ 14
- 0
app/lib/ext-protocol.js View File

@@ -0,0 +1,14 @@
1
+var protocol = require('protocol')
2
+var path = require('path')
3
+var toPath = require('multiblob/util').toPath
4
+
5
+module.exports = function (config) {
6
+  var dir = path.join(config.path, 'blobs')
7
+  return function (request) {
8
+    var id = request.url.split(':')[1]
9
+    if (request.method == 'GET' && id) {
10
+      console.log('loading', id, toPath(dir, id))
11
+      return new protocol.RequestFileJob(toPath(dir, id))
12
+    }
13
+  }
14
+}

+ 1
- 0
package.json View File

@@ -25,6 +25,7 @@
25 25
     "electron-prebuilt": "^0.28.2"
26 26
   },
27 27
   "dependencies": {
28
+    "multiblob": "^1.4.3",
28 29
     "scuttlebot": "^4.2.3",
29 30
     "ssb-config": "^1.0.3"
30 31
   }

Loading…
Cancel
Save