diff --git a/app/index.js b/app/index.js index 189d27c..3874972 100644 --- a/app/index.js +++ b/app/index.js @@ -3,6 +3,7 @@ var Tray = require('tray') var Menu = require('menu') var shell = require('shell') var BrowserWindow = require('browser-window') + var config = require('ssb-config') // Report crashes to our server. @@ -13,7 +14,10 @@ var mainWindow app.on('ready', function ready () { // start sbot - require('scuttlebot').init(config, function (err, sbot) { + require('scuttlebot').init(config, function (err, sbot) { + // register protocols + require('protocol').registerProtocol('ext', require('./lib/ext-protocol')(config)) + // open the web app // shell.openExternal('http://localhost:8008') mainWindow = new BrowserWindow({width: 1000, height: 720}) diff --git a/app/lib/ext-protocol.js b/app/lib/ext-protocol.js new file mode 100644 index 0000000..a07d99c --- /dev/null +++ b/app/lib/ext-protocol.js @@ -0,0 +1,14 @@ +var protocol = require('protocol') +var path = require('path') +var toPath = require('multiblob/util').toPath + +module.exports = function (config) { + var dir = path.join(config.path, 'blobs') + return function (request) { + var id = request.url.split(':')[1] + if (request.method == 'GET' && id) { + console.log('loading', id, toPath(dir, id)) + return new protocol.RequestFileJob(toPath(dir, id)) + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index da4c59b..f4292f7 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "electron-prebuilt": "^0.28.2" }, "dependencies": { + "multiblob": "^1.4.3", "scuttlebot": "^4.2.3", "ssb-config": "^1.0.3" }