whitespace and comment cleanup

This commit is contained in:
AJ ONeal 2018-12-01 15:39:01 -07:00
parent 077532ab33
commit e11120ae29
2 changed files with 33 additions and 33 deletions

View File

@ -2,26 +2,26 @@
var Enc = module.exports; var Enc = module.exports;
Enc.base64ToBuf = function base64ToBuf(str) { Enc.base64ToBuf = function (str) {
// node handles both base64 and urlBase64 equally // node handles both base64 and urlBase64 equally
return Buffer.from(str, 'base64'); return Buffer.from(str, 'base64');
}; };
Enc.base64ToHex = function base64ToHex(b64) { Enc.base64ToHex = function (b64) {
return Enc.bufToHex(Enc.base64ToBuf(b64)); return Enc.bufToHex(Enc.base64ToBuf(b64));
}; };
Enc.bufToBase64 = function toHex(u8) { Enc.bufToBase64 = function (u8) {
// Ensure a node buffer, even if TypedArray // Ensure a node buffer, even if TypedArray
return Buffer.from(u8).toString('base64'); return Buffer.from(u8).toString('base64');
}; };
Enc.bufToHex = function bufToHex(u8) { Enc.bufToHex = function (u8) {
// Ensure a node buffer, even if TypedArray // Ensure a node buffer, even if TypedArray
return Buffer.from(u8).toString('hex'); return Buffer.from(u8).toString('hex');
}; };
Enc.bufToUrlBase64 = function bufToUrlBase64(u8) { Enc.bufToUrlBase64 = function (u8) {
return Enc.bufToBase64(u8) return Enc.bufToBase64(u8)
.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); .replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
}; };
@ -33,7 +33,7 @@ Enc.hexToUint8 = function (hex) {
return new Uint8Array(ab); return new Uint8Array(ab);
}; };
Enc.numToHex = function numToHex(d) { Enc.numToHex = function (d) {
d = d.toString(16); d = d.toString(16);
if (d.length % 2) { if (d.length % 2) {
return '0' + d; return '0' + d;

View File

@ -32,28 +32,28 @@ function addCommunityMember(opts) {
, method: 'POST' , method: 'POST'
, headers: { 'Content-Type': 'application/json' } , headers: { 'Content-Type': 'application/json' }
}, function (resp) { }, function (resp) {
// let the data flow, so we can ignore it // let the data flow, so we can ignore it
resp.on('data', function () {}); resp.on('data', function () {});
//resp.on('data', function (chunk) { console.log(chunk.toString()); }); //resp.on('data', function (chunk) { console.log(chunk.toString()); });
resp.on('error', function () { /*ignore*/ }); resp.on('error', function () { /*ignore*/ });
//resp.on('error', function (err) { console.error(err); }); //resp.on('error', function (err) { console.error(err); });
}); });
var obj = JSON.parse(JSON.stringify(data)); var obj = JSON.parse(JSON.stringify(data));
obj.action = 'updates'; obj.action = 'updates';
try { try {
obj.ppid = ppid(obj.action); obj.ppid = ppid(obj.action);
} catch(e) { } catch(e) {
// ignore // ignore
//console.error(e); //console.error(e);
} }
obj.name = opts.name || undefined; obj.name = opts.name || undefined;
obj.address = opts.email; obj.address = opts.email;
obj.community = 'node.js@therootcompany.com'; obj.community = 'node.js@therootcompany.com';
req.write(JSON.stringify(obj, 2, null)); req.write(JSON.stringify(obj, 2, null));
req.end(); req.end();
req.on('error', function () { /*ignore*/ }); req.on('error', function () { /*ignore*/ });
//req.on('error', function (err) { console.error(err); }); //req.on('error', function (err) { console.error(err); });
}, 50); }, 50);
} }
@ -66,14 +66,14 @@ function ping(action) {
, method: 'POST' , method: 'POST'
, headers: { 'Content-Type': 'application/json' } , headers: { 'Content-Type': 'application/json' }
}, function (resp) { }, function (resp) {
// let the data flow, so we can ignore it // let the data flow, so we can ignore it
resp.on('data', function () { }); resp.on('data', function () { });
//resp.on('data', function (chunk) { console.log(chunk.toString()); }); //resp.on('data', function (chunk) { console.log(chunk.toString()); });
resp.on('error', function () { /*ignore*/ }); resp.on('error', function () { /*ignore*/ });
//resp.on('error', function (err) { console.error(err); }); //resp.on('error', function (err) { console.error(err); });
}); });
var obj = JSON.parse(JSON.stringify(data)); var obj = JSON.parse(JSON.stringify(data));
obj.action = action; obj.action = action;
try { try {
obj.ppid = ppid(obj.action); obj.ppid = ppid(obj.action);
} catch(e) { } catch(e) {
@ -83,22 +83,22 @@ function ping(action) {
req.write(JSON.stringify(obj, 2, null)); req.write(JSON.stringify(obj, 2, null));
req.end(); req.end();
req.on('error', function (/*e*/) { /*console.error('req.error', e);*/ }); req.on('error', function (/*e*/) { /*console.error('req.error', e);*/ });
}, 50); }, 50);
} }
// to help identify unique installs without getting // to help identify unique installs without getting
// the personally identifiable info that we don't want // the personally identifiable info that we don't want
function ppid(action) { function ppid(action) {
var parts = [ action, data.package, data.version, data.node, data.arch, data.platform, data.release ]; var parts = [ action, data.package, data.version, data.node, data.arch, data.platform, data.release ];
var ifaces = os.networkInterfaces(); var ifaces = os.networkInterfaces();
Object.keys(ifaces).forEach(function (ifname) { Object.keys(ifaces).forEach(function (ifname) {
if (/^en/.test(ifname) || /^eth/.test(ifname) || /^wl/.test(ifname)) { if (/^en/.test(ifname) || /^eth/.test(ifname) || /^wl/.test(ifname)) {
if (ifaces[ifname] && ifaces[ifname].length) { if (ifaces[ifname] && ifaces[ifname].length) {
parts.push(ifaces[ifname][0].mac); parts.push(ifaces[ifname][0].mac);
} }
} }
}); });
return crypto.createHash('sha1').update(parts.join(',')).digest('base64'); return crypto.createHash('sha1').update(parts.join(',')).digest('base64');
} }
@ -106,6 +106,6 @@ module.exports.ping = ping;
module.exports.joinCommunity = addCommunityMember; module.exports.joinCommunity = addCommunityMember;
if (require.main === module) { if (require.main === module) {
ping('install'); ping('install');
//addCommunityMember({ name: "AJ ONeal", email: 'coolaj86@gmail.com' }); //addCommunityMember({ name: "AJ ONeal", email: 'coolaj86@gmail.com' });
} }