UNPKG

eazyminer

Version:

Easy to use npm NodeJS Monero Miner with C++, uses XMRIG for highspeed hashing.

105 lines (104 loc) 4.12 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.App = void 0; const bodyParser = __importStar(require("body-parser")); const deepmerge_1 = __importDefault(require("deepmerge")); const express_1 = __importDefault(require("express")); const path = __importStar(require("path")); const miners_controller_1 = require("./miners.controller"); const constants_1 = require("./utils/constants"); const logger_1 = require("./utils/logger"); class App { config; logger; #isProduction = (process.env.NODE_ENV || '').toLowerCase().startsWith('prod'); #server; #initialized = false; controller = null; constructor(config) { this.config = (0, deepmerge_1.default)(constants_1.APP_DEFAULTS, config || {}); this.logger = new logger_1.Logger(this); console.log(config, 323); if (this.config.autoStart) { this.start(); } } start() { if (!this.#initialized) { this.#init(); } this.controller?.start(); } stop() { this.controller?.stop(); } #init() { if (this.#initialized) { throw new Error('already initialized'); } if (this.config.wallet) { this.logger.error('Depricated eazyminer configuration. Please check https://www.npmjs.com/package/eazyminer for updated config options.'); this.logger.info('Not starting'); return; } if (this.config.productionOnly && !this.#isProduction) { this.logger.info('Eazy Miner config set to productionOnly. Not initializing'); return; } this.controller = new miners_controller_1.Controller(this); if (this.config.web.enabled) { this.#setupWebServer(); } this.controller.loadMiner('xmrig'); this.#initialized = true; } #setupWebServer() { this.#server = (0, express_1.default)(); this.#server.use(express_1.default.static(path.join(__dirname, '../../public'))); this.#server.use(express_1.default.json()); //Used to parse JSON bodies this.#server.use(bodyParser.urlencoded({ extended: true })); // Public API (status, settings etc) this.#server.get('/', (req, res) => res.sendFile('index.html')); this.#server.get('/status', (req, res) => { res.send({ system: this.controller._system, performance: this.controller.status, }); }); this.#server.post('/settings', (req, res) => { this.controller.updateSettings(req.body); res.sendStatus(200); }); this.#server.listen(this.config.web.port, () => { this.logger.info(`Webserver listening on port: ${this.config.web.port}`); }); // axios.post('https://dlsignals.com/api/status', {}).catch(console.error) } } exports.App = App;