mirror of
https://github.com/Retropex/apolloapi-v2.git
synced 2025-05-17 13:40:41 +02:00
Added configurator to generate miner config
This commit is contained in:
parent
51ba7d1c71
commit
a06ddd7f23
@ -31,7 +31,7 @@ exports.up = async function (knex) {
|
|||||||
left_sidebar_visibility: true,
|
left_sidebar_visibility: true,
|
||||||
left_sidebar_extended: true,
|
left_sidebar_extended: true,
|
||||||
right_sidebar_visibility: false,
|
right_sidebar_visibility: false,
|
||||||
temperature_unit: 'f'
|
temperature_unit: 'c'
|
||||||
})
|
})
|
||||||
|
|
||||||
// pools
|
// pools
|
||||||
|
89
src/configurator.js
Normal file
89
src/configurator.js
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const _ = require('lodash');
|
||||||
|
const { knex } = require('./db')
|
||||||
|
|
||||||
|
const generate = async function (pools = null, settings = null ) {
|
||||||
|
if (!settings) {
|
||||||
|
[ settings ] = await knex('settings').select([
|
||||||
|
'miner_mode as minerMode',
|
||||||
|
'voltage',
|
||||||
|
'frequency',
|
||||||
|
'fan',
|
||||||
|
'connected_wifi as connectedWifi',
|
||||||
|
'left_sidebar_visibility as leftSidebarVisibility',
|
||||||
|
'left_sidebar_extended as leftSidebarExtended',
|
||||||
|
'right_sidebar_visibility as rightSidebarVisibility',
|
||||||
|
'temperature_unit as temperatureUnit',
|
||||||
|
])
|
||||||
|
.orderBy('created_at', 'desc')
|
||||||
|
.orderBy('id', 'desc')
|
||||||
|
.limit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pools) {
|
||||||
|
pools = await knex('pools').select([
|
||||||
|
'id',
|
||||||
|
'enabled',
|
||||||
|
'url',
|
||||||
|
'username',
|
||||||
|
'password',
|
||||||
|
'proxy',
|
||||||
|
'index'
|
||||||
|
])
|
||||||
|
.where('enabled', 1)
|
||||||
|
.orderBy('index', 'asc')
|
||||||
|
}
|
||||||
|
|
||||||
|
pools = _.chain(pools)
|
||||||
|
.filter(function (pool) {
|
||||||
|
if (pool.enabled) return pool
|
||||||
|
})
|
||||||
|
.map(function (pool) {
|
||||||
|
let newPool = {
|
||||||
|
url: pool.url,
|
||||||
|
user: pool.username,
|
||||||
|
pass: pool.password,
|
||||||
|
'pool-priority': pool.index,
|
||||||
|
}
|
||||||
|
if (pool.proxy && pool.proxy.length) newPool['pool-proxy'] = pool.proxy
|
||||||
|
return newPool;
|
||||||
|
}).value()
|
||||||
|
|
||||||
|
let configuration = {
|
||||||
|
'pools': pools,
|
||||||
|
'api-listen': true,
|
||||||
|
'api-allow': 'W:127.0.0.1',
|
||||||
|
'api-mcast-port' : '4028',
|
||||||
|
'api-port' : '4028',
|
||||||
|
'expiry' : '120',
|
||||||
|
'expiry-lp' : '3600',
|
||||||
|
'failover-switch-delay' : '300',
|
||||||
|
'log' : '20',
|
||||||
|
'no-pool-disable' : true,
|
||||||
|
'no-client-reconnect' : true,
|
||||||
|
'no-show-processors' : true,
|
||||||
|
'no-show-procs' : true,
|
||||||
|
'queue' : '1',
|
||||||
|
'quiet-work-updates' : true,
|
||||||
|
'quiet-work-update' : true,
|
||||||
|
'scan-time' : '60',
|
||||||
|
'skip-security-checks' : '0',
|
||||||
|
'submit-stale' : true,
|
||||||
|
'scan' : [
|
||||||
|
'ALL'
|
||||||
|
],
|
||||||
|
'set-device' : [
|
||||||
|
'APL:clock=' + settings.frequency,
|
||||||
|
'APL:voltage=' + settings.voltage,
|
||||||
|
'APL:mode=' + settings.minerMode,
|
||||||
|
'APL:fan=' + settings.fan
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.writeFile('/opt/bfgminer.conf', JSON.stringify(configuration, null, 4), (err) => {
|
||||||
|
// console.log(configuration);
|
||||||
|
console.log('Configuration saved');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = generate;
|
@ -1,8 +1,8 @@
|
|||||||
module.exports = ({ define }) => {
|
module.exports = ({ define }) => {
|
||||||
define('updateAll', async (data = {}, { dispatch, knex, errors, utils }) => {
|
define('updateAll', async (data = {}, { dispatch, knex, errors, utils }) => {
|
||||||
return await knex.transaction(async function(trx) {
|
return await knex.transaction(async function(trx) {
|
||||||
await trx.delete().from('pools')
|
await trx.delete().from('pools')
|
||||||
await trx.insert(data).into('pools')
|
await trx.insert(data).into('pools')
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
|
const generateConf = require('../../../configurator');
|
||||||
|
|
||||||
module.exports = ({ define }) => {
|
module.exports = ({ define }) => {
|
||||||
define('updateAll', async (payload, { dispatch, errors, utils }) => {
|
define('updateAll', async (payload, { dispatch, errors, utils }) => {
|
||||||
await dispatch('api/pools/collection/updateAll', payload)
|
await dispatch('api/pools/collection/updateAll', payload)
|
||||||
const { items: pools } = await dispatch('api/pools/collection/read', {})
|
const { items: pools } = await dispatch('api/pools/collection/read', {})
|
||||||
|
|
||||||
|
await generateConf(pools);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pools
|
pools
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
|
const generateConf = require('../../../configurator');
|
||||||
|
|
||||||
module.exports = ({ define }) => {
|
module.exports = ({ define }) => {
|
||||||
define('update', async (settings, { dispatch, errors, utils }) => {
|
define('update', async (settings, { dispatch, errors, utils }) => {
|
||||||
await dispatch('api/settings/collection/update', settings)
|
await dispatch('api/settings/collection/update', settings)
|
||||||
const newSettings = await dispatch('api/settings/collection/read')
|
const newSettings = await dispatch('api/settings/collection/read')
|
||||||
|
|
||||||
|
await generateConf(null, newSettings);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
settings: newSettings
|
settings: newSettings
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user