git ssb

4+

Dominic / scuttlebot



Commit 593a79b4db22884bf30be44d48a33fce2ea3074b

always take a single options arg, for consistency

Dominic Tarr committed on 5/20/2017, 2:01:53 AM
Parent: 3b2dc16dbbbc0325cda645d454ecda892d5c87a5

Files changed

plugins/invite.jschanged
plugins/invite.jsView
@@ -1,4 +1,5 @@
1 +'use strict'
12 var crypto = require('crypto')
23 var ssbKeys = require('ssb-keys')
34 var toAddress = require('../lib/util').toAddress
45 var cont = require('cont')
@@ -26,8 +27,12 @@
2627 function isObject(o) {
2728 return o && 'object' === typeof o
2829 }
2930
31 +function isNumber(n) {
32 + return 'number' === typeof n && !isNaN(n)
33 +}
34 +
3035 module.exports = {
3136 name: 'invite',
3237 version: '1.0.0',
3338 manifest: mdm.manifest(apidoc),
@@ -59,18 +64,19 @@
5964 })
6065 })
6166
6267 return {
63- create: valid.async(function (n, note, cb) {
64- var modern = false
65- if(isObject(n) && n.modern) {
66- n = 1
67- modern = true
68 + create: valid.async(function (opts, cb) {
69 + opts = opts || {}
70 + if(isNumber(opts))
71 + opts = {uses: opts}
72 + else if(isObject(opts)) {
73 + if(opts.modern)
74 + opts.uses = 1
6875 }
69- if(isFunction(note)) {
70- cb = note
71- note = null
72- }
76 + else if(isFunction(opts))
77 + cb = opts, opts = {}
78 +
7379 var addr = server.getAddress()
7480 var host = ref.parseAddress(addr).host
7581 if(!config.allowPrivate && (ip.isPrivate(host) || 'localhost' === host))
7682 return cb(new Error('Server has no public ip address, '
@@ -89,16 +95,16 @@
8995 // store metadata under the generated pubkey
9096 var owner = server.id
9197 codesDB.put(keyCap.id, {
9298 id: keyCap.id,
93- total: +n,
94- note: note,
99 + total: +opts.uses || 1,
100 + note: opts.note,
95101 used: 0,
96102 permissions: {allow: ['invite.use', 'getAddress'], deny: null}
97103 }, function (err) {
98104 // emit the invite code: our server address, plus the key-seed
99105 if(err) cb(err)
100- else if(modern && server.ws && server.ws.getAddress) {
106 + else if(opts.modern && server.ws && server.ws.getAddress) {
101107 cb(null, server.ws.getAddress()+':'+seed.toString('base64'))
102108 }
103109 else {
104110 addr = ref.parseAddress(addr)
@@ -219,5 +225,4 @@
219225 }
220226 }
221227 }
222228
223-

Built with git-ssb-web