add ext: protocol

This commit is contained in:
Paul Frazee 2015-06-24 21:23:27 -05:00
parent f3421c4bba
commit fe030cb0e0
3 changed files with 20 additions and 1 deletions

View File

@ -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})

14
app/lib/ext-protocol.js Normal file
View File

@ -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))
}
}
}

View File

@ -25,6 +25,7 @@
"electron-prebuilt": "^0.28.2"
},
"dependencies": {
"multiblob": "^1.4.3",
"scuttlebot": "^4.2.3",
"ssb-config": "^1.0.3"
}