diff --git a/api/algorithms.js b/api/algorithms.js index b734995..8c65e78 100644 --- a/api/algorithms.js +++ b/api/algorithms.js @@ -1,5 +1,3 @@ -const sendJson = require('./util/send-json'); - const ANTMINER_S19_PRO_WATTAGE = 3250; const RTX_3090_WATTAGE = 285; const INNOSILICON_A6_PLUS_WATTAGE = 2100; @@ -69,5 +67,5 @@ const getAlgorithms = () => [ } ]; -module.exports = getAlgorithms; -module.exports.handler = () => sendJson(getAlgorithms); +module.exports = async (request, response) => response.json(await getAlgorithms()); +module.exports.getAlgorithms = getAlgorithms; \ No newline at end of file diff --git a/api/coins.js b/api/coins.js index b0e856b..57bd04b 100644 --- a/api/coins.js +++ b/api/coins.js @@ -1,5 +1,4 @@ const fetch = require('isomorphic-fetch'); -const sendJson = require('./util/send-json'); const getData = async endpoint => fetch( `https://whattomine.com/${endpoint}.json` @@ -31,5 +30,5 @@ const getCoinData = async () => { return coins; }; -module.exports = getCoinData; -module.exports.handler = () => sendJson(getCoinData); +module.exports = async (request, response) => response.json(await getCoinData()); +module.exports.getCoinData = getCoinData; \ No newline at end of file diff --git a/api/data.js b/api/data.js index 09c72dc..87e8e3c 100644 --- a/api/data.js +++ b/api/data.js @@ -1,6 +1,5 @@ -const sendJson = require('./util/send-json'); -const getCoinData = require('./coins'); -const getAlgorithms = require('./algorithms'); +const {getCoinData} = require('./coins'); +const {getAlgorithms} = require('./algorithms'); const algorithms = getAlgorithms(); @@ -23,5 +22,4 @@ const getData = async () => { return data; }; -module.exports = getData; -module.exports.handler = () => sendJson(getData); +module.exports = async (request, response) => response.json(await getData()) diff --git a/api/nicehash.js b/api/nicehash.js deleted file mode 100644 index 7f94887..0000000 --- a/api/nicehash.js +++ /dev/null @@ -1,44 +0,0 @@ -const fetch = require('isomorphic-fetch'); -const sendJson = require('./util/send-json'); - -const SECONDS = 1; -const MINUTES = SECONDS * 60; -const HOURS = MINUTES * 60; -const DAYS = HOURS * 24; - -const getData = async endpoint => fetch( - 'https://api2.nicehash.com/main/api/v2/' + endpoint -).then(res => res.json()); - -const getNiceHashData = async () => { - const [algorithmData, currentValues] = await Promise.all([ - getData('mining/algorithms'), - getData('public/stats/global/current') - ]); - - const algorithms = algorithmData.miningAlgorithms - .map(value => { - const algorithm = { - id: value.order, - name: value.title - }; - - const {marketFactor} = value; - const {displayMarketFactor} = value; - - const values = currentValues.algos.find(algo => algo.a === algorithm.id); - const pricePerHashPerDay = values.p / 100000000; - algorithm.pricePerHashPerSecond = pricePerHashPerDay / DAYS; - algorithm.hashrate = values.s; - - algorithm.priceReadable = (pricePerHashPerDay * marketFactor).toFixed(4) + ` BTC/${displayMarketFactor}/day`; - algorithm.hashrateReadable = (algorithm.hashrate / marketFactor).toFixed(4) + ` ${displayMarketFactor}/s`; - - return algorithm; - }); - - return algorithms; -}; - -module.exports = getNiceHashData; -module.exports.handler = () => sendJson(getNiceHashData); diff --git a/api/util/send-json.js b/api/util/send-json.js deleted file mode 100644 index d320f30..0000000 --- a/api/util/send-json.js +++ /dev/null @@ -1,27 +0,0 @@ -const sendJson = async getData => { - try { - return { - statusCode: 200, - headers: { - 'Access-Control-Allow-Origin': '*', - 'Cache-Control': 'public, s-max-age=600', - 'Content-Type': 'application/json' - }, - body: JSON.stringify(await getData()) - }; - } catch (error) { - return { - statusCode: 500, - headers: { - 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - error: true, - message: error.message - }) - }; - } -}; - -module.exports = sendJson;