Browse Source

update to sbot 6.0.0

Paul Frazee 5 years ago
parent
commit
3dd31eee7d
4 changed files with 58 additions and 55 deletions
  1. 45
    33
      app/index.js
  2. 6
    7
      app/lib/blobs.js
  3. 3
    12
      app/lib/muxrpc-ipc.js
  4. 4
    3
      package.json

+ 45
- 33
app/index.js View File

@@ -1,44 +1,56 @@
1
-var app = require('app')
1
+var app  = require('app')
2 2
 var Menu = require('menu')
3 3
 var path = require('path')
4 4
 var http = require('http')
5 5
 
6
-var config = require('ssb-config')
7
-var windows = require('./lib/windows')
6
+var windows    = require('./lib/windows')
7
+var config     = require('ssb-config')
8
+var ssbKeys    = require('ssb-keys')
9
+var createSbot = require('scuttlebot')
10
+  .use(require('scuttlebot/plugins/master'))
11
+  .use(require('scuttlebot/plugins/gossip'))
12
+  .use(require('scuttlebot/plugins/friends'))
13
+  .use(require('scuttlebot/plugins/replicate'))
14
+  .use(require('scuttlebot/plugins/blobs'))
15
+  .use(require('scuttlebot/plugins/invite'))
16
+  .use(require('scuttlebot/plugins/block'))
17
+  .use(require('scuttlebot/plugins/logging'))
18
+  .use(require('scuttlebot/plugins/crypto'))
19
+  .use(require('ssb-patchwork-api'))
8 20
 
9
-// Report crashes to our server.
10
-//require('crash-reporter').start();
21
+config.keys = ssbKeys.loadOrCreateSync(path.join(config.path, 'secret'))
22
+if(config.keys.curve === 'k256')
23
+  throw new Error('k256 curves are no longer supported,'+
24
+                  'please delete' + path.join(config.path, 'secret'))
11 25
 
12
-app.on('ready', function ready () {
26
+app.on('ready', function () {
13 27
   // start sbot
14
-  require('scuttlebot').init(config, function (err, sbot) {
15
-    // register sbot plugins
16
-    sbot.use(require('ssb-patchwork-api'))
17
-    
18
-    // setup blob and file serving
19
-    var blobs = require('./lib/blobs')(sbot, app.getPath('userDesktop'))
20
-    require('protocol').registerProtocol('blob', blobs.protocol)
21
-    http.createServer(blobs.server({ serveFiles: false })).listen(7777)
22
-    http.createServer(blobs.server({ serveFiles: true })).listen(7778)
28
+  var rebuild = false
29
+  var sbot = createSbot(config)
23 30
 
24
-    // open main window
25
-    var mainWindow = windows.open(
26
-      'file://' + path.join(__dirname, '../node_modules/ssb-patchwork-ui/main.html'),
27
-      sbot,
28
-      blobs,
29
-      { width: 1030, height: 720 }
30
-    )
31
-    require('./lib/menu')(mainWindow)
32
-    // mainWindow.openDevTools()
31
+  // setup blob and file serving
32
+  var blobs = require('./lib/blobs')(sbot, { blobs_dir: path.join(config.path, 'blobs'), checkout_dir: app.getPath('userDesktop') })
33
+  require('protocol').registerProtocol('blob', blobs.protocol)
34
+  http.createServer(blobs.server({ serveFiles: false })).listen(7777)
35
+  http.createServer(blobs.server({ serveFiles: true })).listen(7778)
33 36
 
34
-    // setup menu
35
-    // Menu.setApplicationMenu(Menu.buildFromTemplate([{
36
-    //   label: 'Window',
37
-    //   submenu: [
38
-    //     // { label: 'Open Web App', click: onopen },
39
-    //     { label: 'Quit', click: onquit }
40
-    //   ]
41
-    // }]))
37
+  // open main window
38
+  var mainWindow = windows.open(
39
+    'file://' + path.join(__dirname, '../node_modules/ssb-patchwork-ui/main.html'),
40
+    sbot,
41
+    blobs,
42
+    { width: 1030, height: 720 }
43
+  )
44
+  require('./lib/menu')(mainWindow)
45
+  // mainWindow.openDevTools()
46
+
47
+  // setup menu
48
+  // Menu.setApplicationMenu(Menu.buildFromTemplate([{
49
+  //   label: 'Window',
50
+  //   submenu: [
51
+  //     // { label: 'Open Web App', click: onopen },
52
+  //     { label: 'Quit', click: onquit }
53
+  //   ]
54
+  // }]))
42 55
 
43
-  })
44 56
 });

+ 6
- 7
app/lib/blobs.js View File

@@ -7,8 +7,7 @@ var toPull      = require('stream-to-pull-stream')
7 7
 var querystring = require('querystring')
8 8
 var fs          = require('fs')
9 9
 
10
-module.exports = function (sbot, checkout_dir) {
11
-  var blobs_dir = path.join(sbot.config.path, 'blobs')
10
+module.exports = function (sbot, config) {
12 11
   var fallback_img_path = path.join(__dirname, '../../node_modules/ssbplug-phoenix/img/default-prof-pic.png')
13 12
   var nowaitOpts = { nowait: true }, id = function(){}
14 13
 
@@ -19,7 +18,7 @@ module.exports = function (sbot, checkout_dir) {
19 18
       // simple fetch
20 19
       var parsed = url_parse(request.url)
21 20
       if (request.method == 'GET' && parsed) {
22
-        var filepath = toPath(blobs_dir, parsed.hash)
21
+        var filepath = toPath(config.blobs_dir, parsed.hash)
23 22
         try {
24 23
           // check if the file exists
25 24
           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) {
44 43
 
45 44
       // check if we have the blob, at the same time find an available filename
46 45
       var done = multicb()
47
-      fs.stat(toPath(blobs_dir, parsed.hash), done())
46
+      fs.stat(toPath(config.blobs_dir, parsed.hash), done())
48 47
       findCheckoutDst(filename, parsed.hash, done())
49 48
       done(function (err, res) {
50 49
         if (err && err.code == 'ENOENT')
@@ -57,7 +56,7 @@ module.exports = function (sbot, checkout_dir) {
57 56
           return cb(null, dst)
58 57
 
59 58
         // copy the file
60
-        var src = toPath(blobs_dir, parsed.hash)
59
+        var src = toPath(config.blobs_dir, parsed.hash)
61 60
         var read = fs.createReadStream(src)
62 61
         var write = fs.createWriteStream(dst)
63 62
         read.on('error', done)
@@ -131,7 +130,7 @@ module.exports = function (sbot, checkout_dir) {
131 130
       if (n !== 1) name += ' ('+n+')'
132 131
       name += parsed.ext
133 132
       n++
134
-      return path.join(checkout_dir, name)
133
+      return path.join(config.checkout_dir, name)
135 134
     }
136 135
 
137 136
     function next () {
@@ -160,7 +159,7 @@ module.exports = function (sbot, checkout_dir) {
160 159
 }
161 160
 
162 161
 // blob url parser
163
-var re = /^blob:([a-z0-9\+\/=]+\.(?:sha256|blake2s))\??(.*)$/i
162
+var re = /^blob:&([a-z0-9\+\/=]+\.(?:sha256|blake2s))\??(.*)$/i
164 163
 var url_parse =
165 164
 module.exports.url_parse = function (str) {
166 165
   var parts = re.exec(str)

+ 3
- 12
app/lib/muxrpc-ipc.js View File

@@ -2,7 +2,6 @@ var ipc        = require('ipc')
2 2
 var muxrpc     = require('muxrpc')
3 3
 var pull       = require('pull-stream')
4 4
 var pushable   = require('pull-pushable')
5
-var Api        = require('scuttlebot/lib/api')
6 5
 
7 6
 var clientApi = {
8 7
   navigate: 'async',
@@ -10,19 +9,11 @@ var clientApi = {
10 9
 }
11 10
 
12 11
 module.exports = function (window, sbot, params) {
13
-  // construct api
14
-  var api = Api(sbot)
15
-  for (var k in sbot.manifest) {
16
-    if (typeof sbot.manifest[k] == 'object')
17
-      api[k] = sbot[k] // copy over the plugin APIs
18
-  }
19
-
20
-
21 12
   // add rpc APIs to window
22 13
   window.createRpc = function () {
23 14
     // create rpc object
24
-    var rpc = window.rpc = muxrpc(clientApi, sbot.manifest, serialize)(api)
25
-    rpc.authorized = { id: sbot.feed.id, role: 'master' }
15
+    var rpc = window.rpc = muxrpc(clientApi, sbot.manifest(), serialize)(sbot)
16
+    rpc.authorized = { id: sbot.id, role: 'master' }
26 17
     rpc.permissions({allow: null, deny: null})
27 18
     function serialize (stream) { return stream }
28 19
 
@@ -69,7 +60,7 @@ module.exports = function (window, sbot, params) {
69 60
   // setup helper messages
70 61
   ipc.on('fetch-manifest', function(e) {
71 62
     if (e.sender == window.webContents)
72
-      e.returnValue = sbot.manifest
63
+      e.returnValue = sbot.manifest()
73 64
   });
74 65
   ipc.on('fetch-params', function(e) {
75 66
     if (e.sender == window.webContents)

+ 4
- 3
package.json View File

@@ -28,12 +28,13 @@
28 28
     "multiblob": "^1.5.0",
29 29
     "multicb": "^1.1.0",
30 30
     "muxrpc": "^5.0.1",
31
-    "ssb-patchwork-api": "~0.0.1",
32
-    "ssb-patchwork-ui": "~0.0.1",
33 31
     "pull-pushable": "^1.1.4",
34 32
     "pull-stream": "^2.27.0",
35
-    "scuttlebot": "^4.2.3",
33
+    "scuttlebot": "^6.0.0",
36 34
     "ssb-config": "^1.0.3",
35
+    "ssb-keys": "^4.0.3",
36
+    "ssb-patchwork-api": "~0.0.1",
37
+    "ssb-patchwork-ui": "~0.0.1",
37 38
     "stream-to-pull-stream": "^1.6.1"
38 39
   }
39 40
 }

Loading…
Cancel
Save