update to sbot 6.0.0

This commit is contained in:
Paul Frazee 2015-08-03 19:54:30 -05:00
parent 017ae1d419
commit 3dd31eee7d
4 changed files with 58 additions and 55 deletions

View File

@ -1,44 +1,56 @@
var app = require('app') var app = require('app')
var Menu = require('menu') var Menu = require('menu')
var path = require('path') var path = require('path')
var http = require('http') var http = require('http')
var config = require('ssb-config') var windows = require('./lib/windows')
var windows = require('./lib/windows') var config = require('ssb-config')
var ssbKeys = require('ssb-keys')
var createSbot = require('scuttlebot')
.use(require('scuttlebot/plugins/master'))
.use(require('scuttlebot/plugins/gossip'))
.use(require('scuttlebot/plugins/friends'))
.use(require('scuttlebot/plugins/replicate'))
.use(require('scuttlebot/plugins/blobs'))
.use(require('scuttlebot/plugins/invite'))
.use(require('scuttlebot/plugins/block'))
.use(require('scuttlebot/plugins/logging'))
.use(require('scuttlebot/plugins/crypto'))
.use(require('ssb-patchwork-api'))
// Report crashes to our server. config.keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret'))
//require('crash-reporter').start(); if(config.keys.curve === 'k256')
throw new Error('k256 curves are no longer supported,'+
'please delete' + path.join(config.path, 'secret'))
app.on('ready', function ready () { app.on('ready', function () {
// start sbot // start sbot
require('scuttlebot').init(config, function (err, sbot) { var rebuild = false
// register sbot plugins var sbot = createSbot(config)
sbot.use(require('ssb-patchwork-api'))
// setup blob and file serving
var blobs = require('./lib/blobs')(sbot, app.getPath('userDesktop'))
require('protocol').registerProtocol('blob', blobs.protocol)
http.createServer(blobs.server({ serveFiles: false })).listen(7777)
http.createServer(blobs.server({ serveFiles: true })).listen(7778)
// open main window // setup blob and file serving
var mainWindow = windows.open( var blobs = require('./lib/blobs')(sbot, { blobs_dir: path.join(config.path, 'blobs'), checkout_dir: app.getPath('userDesktop') })
'file://' + path.join(__dirname, '../node_modules/ssb-patchwork-ui/main.html'), require('protocol').registerProtocol('blob', blobs.protocol)
sbot, http.createServer(blobs.server({ serveFiles: false })).listen(7777)
blobs, http.createServer(blobs.server({ serveFiles: true })).listen(7778)
{ width: 1030, height: 720 }
)
require('./lib/menu')(mainWindow)
// mainWindow.openDevTools()
// setup menu // open main window
// Menu.setApplicationMenu(Menu.buildFromTemplate([{ var mainWindow = windows.open(
// label: 'Window', 'file://' + path.join(__dirname, '../node_modules/ssb-patchwork-ui/main.html'),
// submenu: [ sbot,
// // { label: 'Open Web App', click: onopen }, blobs,
// { label: 'Quit', click: onquit } { width: 1030, height: 720 }
// ] )
// }])) require('./lib/menu')(mainWindow)
// mainWindow.openDevTools()
// setup menu
// Menu.setApplicationMenu(Menu.buildFromTemplate([{
// label: 'Window',
// submenu: [
// // { label: 'Open Web App', click: onopen },
// { label: 'Quit', click: onquit }
// ]
// }]))
})
}); });

View File

@ -7,8 +7,7 @@ var toPull = require('stream-to-pull-stream')
var querystring = require('querystring') var querystring = require('querystring')
var fs = require('fs') var fs = require('fs')
module.exports = function (sbot, checkout_dir) { module.exports = function (sbot, config) {
var blobs_dir = path.join(sbot.config.path, 'blobs')
var fallback_img_path = path.join(__dirname, '../../node_modules/ssbplug-phoenix/img/default-prof-pic.png') var fallback_img_path = path.join(__dirname, '../../node_modules/ssbplug-phoenix/img/default-prof-pic.png')
var nowaitOpts = { nowait: true }, id = function(){} var nowaitOpts = { nowait: true }, id = function(){}
@ -19,7 +18,7 @@ module.exports = function (sbot, checkout_dir) {
// simple fetch // simple fetch
var parsed = url_parse(request.url) var parsed = url_parse(request.url)
if (request.method == 'GET' && parsed) { if (request.method == 'GET' && parsed) {
var filepath = toPath(blobs_dir, parsed.hash) var filepath = toPath(config.blobs_dir, parsed.hash)
try { try {
// check if the file exists // check if the file exists
fs.statSync(filepath) // :HACK: make async when we figure out how to make a protocol-handler support that fs.statSync(filepath) // :HACK: make async when we figure out how to make a protocol-handler support that
@ -44,7 +43,7 @@ module.exports = function (sbot, checkout_dir) {
// check if we have the blob, at the same time find an available filename // check if we have the blob, at the same time find an available filename
var done = multicb() var done = multicb()
fs.stat(toPath(blobs_dir, parsed.hash), done()) fs.stat(toPath(config.blobs_dir, parsed.hash), done())
findCheckoutDst(filename, parsed.hash, done()) findCheckoutDst(filename, parsed.hash, done())
done(function (err, res) { done(function (err, res) {
if (err && err.code == 'ENOENT') if (err && err.code == 'ENOENT')
@ -57,7 +56,7 @@ module.exports = function (sbot, checkout_dir) {
return cb(null, dst) return cb(null, dst)
// copy the file // copy the file
var src = toPath(blobs_dir, parsed.hash) var src = toPath(config.blobs_dir, parsed.hash)
var read = fs.createReadStream(src) var read = fs.createReadStream(src)
var write = fs.createWriteStream(dst) var write = fs.createWriteStream(dst)
read.on('error', done) read.on('error', done)
@ -131,7 +130,7 @@ module.exports = function (sbot, checkout_dir) {
if (n !== 1) name += ' ('+n+')' if (n !== 1) name += ' ('+n+')'
name += parsed.ext name += parsed.ext
n++ n++
return path.join(checkout_dir, name) return path.join(config.checkout_dir, name)
} }
function next () { function next () {
@ -160,7 +159,7 @@ module.exports = function (sbot, checkout_dir) {
} }
// blob url parser // blob url parser
var re = /^blob:([a-z0-9\+\/=]+\.(?:sha256|blake2s))\??(.*)$/i var re = /^blob:&([a-z0-9\+\/=]+\.(?:sha256|blake2s))\??(.*)$/i
var url_parse = var url_parse =
module.exports.url_parse = function (str) { module.exports.url_parse = function (str) {
var parts = re.exec(str) var parts = re.exec(str)

View File

@ -2,7 +2,6 @@ var ipc = require('ipc')
var muxrpc = require('muxrpc') var muxrpc = require('muxrpc')
var pull = require('pull-stream') var pull = require('pull-stream')
var pushable = require('pull-pushable') var pushable = require('pull-pushable')
var Api = require('scuttlebot/lib/api')
var clientApi = { var clientApi = {
navigate: 'async', navigate: 'async',
@ -10,19 +9,11 @@ var clientApi = {
} }
module.exports = function (window, sbot, params) { module.exports = function (window, sbot, params) {
// construct api
var api = Api(sbot)
for (var k in sbot.manifest) {
if (typeof sbot.manifest[k] == 'object')
api[k] = sbot[k] // copy over the plugin APIs
}
// add rpc APIs to window // add rpc APIs to window
window.createRpc = function () { window.createRpc = function () {
// create rpc object // create rpc object
var rpc = window.rpc = muxrpc(clientApi, sbot.manifest, serialize)(api) var rpc = window.rpc = muxrpc(clientApi, sbot.manifest(), serialize)(sbot)
rpc.authorized = { id: sbot.feed.id, role: 'master' } rpc.authorized = { id: sbot.id, role: 'master' }
rpc.permissions({allow: null, deny: null}) rpc.permissions({allow: null, deny: null})
function serialize (stream) { return stream } function serialize (stream) { return stream }
@ -69,7 +60,7 @@ module.exports = function (window, sbot, params) {
// setup helper messages // setup helper messages
ipc.on('fetch-manifest', function(e) { ipc.on('fetch-manifest', function(e) {
if (e.sender == window.webContents) if (e.sender == window.webContents)
e.returnValue = sbot.manifest e.returnValue = sbot.manifest()
}); });
ipc.on('fetch-params', function(e) { ipc.on('fetch-params', function(e) {
if (e.sender == window.webContents) if (e.sender == window.webContents)

View File

@ -28,12 +28,13 @@
"multiblob": "^1.5.0", "multiblob": "^1.5.0",
"multicb": "^1.1.0", "multicb": "^1.1.0",
"muxrpc": "^5.0.1", "muxrpc": "^5.0.1",
"ssb-patchwork-api": "~0.0.1",
"ssb-patchwork-ui": "~0.0.1",
"pull-pushable": "^1.1.4", "pull-pushable": "^1.1.4",
"pull-stream": "^2.27.0", "pull-stream": "^2.27.0",
"scuttlebot": "^4.2.3", "scuttlebot": "^6.0.0",
"ssb-config": "^1.0.3", "ssb-config": "^1.0.3",
"ssb-keys": "^4.0.3",
"ssb-patchwork-api": "~0.0.1",
"ssb-patchwork-ui": "~0.0.1",
"stream-to-pull-stream": "^1.6.1" "stream-to-pull-stream": "^1.6.1"
} }
} }