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 path = require('path')
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.
//require('crash-reporter').start();
config.keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret'))
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
require('scuttlebot').init(config, function (err, sbot) {
// register sbot plugins
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)
var rebuild = false
var sbot = createSbot(config)
// open main window
var mainWindow = windows.open(
'file://' + path.join(__dirname, '../node_modules/ssb-patchwork-ui/main.html'),
sbot,
blobs,
{ width: 1030, height: 720 }
)
require('./lib/menu')(mainWindow)
// mainWindow.openDevTools()
// setup blob and file serving
var blobs = require('./lib/blobs')(sbot, { blobs_dir: path.join(config.path, 'blobs'), checkout_dir: 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)
// setup menu
// Menu.setApplicationMenu(Menu.buildFromTemplate([{
// label: 'Window',
// submenu: [
// // { label: 'Open Web App', click: onopen },
// { label: 'Quit', click: onquit }
// ]
// }]))
// open main window
var mainWindow = windows.open(
'file://' + path.join(__dirname, '../node_modules/ssb-patchwork-ui/main.html'),
sbot,
blobs,
{ 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 fs = require('fs')
module.exports = function (sbot, checkout_dir) {
var blobs_dir = path.join(sbot.config.path, 'blobs')
module.exports = function (sbot, config) {
var fallback_img_path = path.join(__dirname, '../../node_modules/ssbplug-phoenix/img/default-prof-pic.png')
var nowaitOpts = { nowait: true }, id = function(){}
@ -19,7 +18,7 @@ module.exports = function (sbot, checkout_dir) {
// simple fetch
var parsed = url_parse(request.url)
if (request.method == 'GET' && parsed) {
var filepath = toPath(blobs_dir, parsed.hash)
var filepath = toPath(config.blobs_dir, parsed.hash)
try {
// check if the file exists
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
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())
done(function (err, res) {
if (err && err.code == 'ENOENT')
@ -57,7 +56,7 @@ module.exports = function (sbot, checkout_dir) {
return cb(null, dst)
// copy the file
var src = toPath(blobs_dir, parsed.hash)
var src = toPath(config.blobs_dir, parsed.hash)
var read = fs.createReadStream(src)
var write = fs.createWriteStream(dst)
read.on('error', done)
@ -131,7 +130,7 @@ module.exports = function (sbot, checkout_dir) {
if (n !== 1) name += ' ('+n+')'
name += parsed.ext
n++
return path.join(checkout_dir, name)
return path.join(config.checkout_dir, name)
}
function next () {
@ -160,7 +159,7 @@ module.exports = function (sbot, checkout_dir) {
}
// blob url parser
var re = /^blob:([a-z0-9\+\/=]+\.(?:sha256|blake2s))\??(.*)$/i
var re = /^blob:&([a-z0-9\+\/=]+\.(?:sha256|blake2s))\??(.*)$/i
var url_parse =
module.exports.url_parse = function (str) {
var parts = re.exec(str)

View File

@ -2,7 +2,6 @@ var ipc = require('ipc')
var muxrpc = require('muxrpc')
var pull = require('pull-stream')
var pushable = require('pull-pushable')
var Api = require('scuttlebot/lib/api')
var clientApi = {
navigate: 'async',
@ -10,19 +9,11 @@ var clientApi = {
}
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
window.createRpc = function () {
// create rpc object
var rpc = window.rpc = muxrpc(clientApi, sbot.manifest, serialize)(api)
rpc.authorized = { id: sbot.feed.id, role: 'master' }
var rpc = window.rpc = muxrpc(clientApi, sbot.manifest(), serialize)(sbot)
rpc.authorized = { id: sbot.id, role: 'master' }
rpc.permissions({allow: null, deny: null})
function serialize (stream) { return stream }
@ -69,7 +60,7 @@ module.exports = function (window, sbot, params) {
// setup helper messages
ipc.on('fetch-manifest', function(e) {
if (e.sender == window.webContents)
e.returnValue = sbot.manifest
e.returnValue = sbot.manifest()
});
ipc.on('fetch-params', function(e) {
if (e.sender == window.webContents)

View File

@ -28,12 +28,13 @@
"multiblob": "^1.5.0",
"multicb": "^1.1.0",
"muxrpc": "^5.0.1",
"ssb-patchwork-api": "~0.0.1",
"ssb-patchwork-ui": "~0.0.1",
"pull-pushable": "^1.1.4",
"pull-stream": "^2.27.0",
"scuttlebot": "^4.2.3",
"scuttlebot": "^6.0.0",
"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"
}
}