UNPKG

btnexus-node

Version:
49 lines (42 loc) 1.31 kB
/** * Ophion Cloud client node * * @author Marc Fiedler * @copyright 2020 Blackout Technologies, all rights reserved, all rights reserved */ // Use Strict mode ECMA Script 5+ "use_strict"; // sys imports const fs = require('fs'); // local imports const findRoot = require('find-root'); module.exports = class ConnectHash{ constructor(){ this.valid = false; const root = findRoot(process.cwd()); var connectHash = process.env.CONNECT_HASH; if( connectHash == undefined ){ try{ // file found, parse it's contents connectHash = fs.readFileSync(root+"/.btnexusrc", "utf-8"); }catch(e){ // no file, no worries.. } } if( connectHash != undefined ){ var buffer = Buffer.from(connectHash, 'base64'); try{ this.data = JSON.parse(buffer.toString('ascii')); Object.assign(this, this.data); this.valid = true; }catch(e){ this.error = "Invalid connect hash! Connect impossible"; } }else{ this.error = "Please provide a valid connect hash from a btNesus instance"; } } isValid(){ return this.valid; } }