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

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