WIPP
This commit is contained in:
parent
a375adb8b9
commit
c3261bc61a
5 changed files with 101 additions and 106 deletions
12
lib/app.js
12
lib/app.js
|
|
@ -3,11 +3,11 @@ const http = require('http')
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const loop = require('reoccur')
|
const loop = require('reoccur')
|
||||||
|
const argv = require('minimist')(process.argv.slice(2))
|
||||||
|
|
||||||
const routes = require('./routes')
|
const routes = require('./routes')
|
||||||
const plugins = require('./plugins')
|
|
||||||
const logger = require('./logger')
|
const logger = require('./logger')
|
||||||
const argv = require('minimist')(process.argv.slice(2))
|
const poller = require('./poller')
|
||||||
|
|
||||||
const settingsLoader = require('./settings-loader')
|
const settingsLoader = require('./settings-loader')
|
||||||
const options = require('./options')
|
const options = require('./options')
|
||||||
|
|
@ -33,9 +33,8 @@ function runOnce () {
|
||||||
const localApp = express()
|
const localApp = express()
|
||||||
|
|
||||||
return settingsLoader.load()
|
return settingsLoader.load()
|
||||||
.then(() => {
|
.then(settings => {
|
||||||
plugins.startPolling()
|
poller.start(settings)
|
||||||
plugins.startCheckingNotification()
|
|
||||||
|
|
||||||
const httpsServerOptions = {
|
const httpsServerOptions = {
|
||||||
key: fs.readFileSync(options.keyPath),
|
key: fs.readFileSync(options.keyPath),
|
||||||
|
|
@ -56,8 +55,7 @@ function runOnce () {
|
||||||
const opts = {
|
const opts = {
|
||||||
app,
|
app,
|
||||||
localApp,
|
localApp,
|
||||||
devMode,
|
devMode
|
||||||
plugins
|
|
||||||
}
|
}
|
||||||
|
|
||||||
routes.init(opts)
|
routes.init(opts)
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,15 @@ const numeral = require('numeral')
|
||||||
const configManager = require('./config-manager')
|
const configManager = require('./config-manager')
|
||||||
const settingsLoader = require('./settings-loader')
|
const settingsLoader = require('./settings-loader')
|
||||||
const db = require('./postgresql_interface')
|
const db = require('./postgresql_interface')
|
||||||
|
const T = require('./time')
|
||||||
|
const logger = require('./logger')
|
||||||
|
|
||||||
const STALE_STATE = 2 * 60 * 1000
|
const STALE_STATE = 2 * T.minute
|
||||||
const NETWORK_DOWN_TIME = 60 * 1000
|
const NETWORK_DOWN_TIME = T.minute
|
||||||
|
const ALERT_SEND_INTERVAL = T.hour
|
||||||
|
|
||||||
let getBalances
|
let alertFingerprint
|
||||||
|
let lastAlertTime
|
||||||
function init (_getBalances) {
|
|
||||||
getBalances = _getBalances
|
|
||||||
}
|
|
||||||
|
|
||||||
function toInt10 (str) { return parseInt(str, 10) }
|
function toInt10 (str) { return parseInt(str, 10) }
|
||||||
|
|
||||||
|
|
@ -26,6 +26,57 @@ function sameState (a, b) {
|
||||||
return a.note.txId === b.note.txId && a.note.state === b.note.state
|
return a.note.txId === b.note.txId && a.note.state === b.note.state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendNoAlerts (plugins) {
|
||||||
|
const subject = '[Lamassu] All clear'
|
||||||
|
const rec = {
|
||||||
|
sms: {
|
||||||
|
body: subject
|
||||||
|
},
|
||||||
|
email: {
|
||||||
|
subject,
|
||||||
|
body: 'No errors are reported for your machines.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugins.sendMessage(rec)
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkNotification (plugins) {
|
||||||
|
return checkStatus(plugins)
|
||||||
|
.then(alertRec => {
|
||||||
|
const currentAlertFingerprint = buildAlertFingerprint(alertRec)
|
||||||
|
if (!currentAlertFingerprint) {
|
||||||
|
const inAlert = !!alertFingerprint
|
||||||
|
alertFingerprint = null
|
||||||
|
lastAlertTime = null
|
||||||
|
if (inAlert) return sendNoAlerts(plugins)
|
||||||
|
}
|
||||||
|
|
||||||
|
const alertChanged = currentAlertFingerprint === alertFingerprint &&
|
||||||
|
lastAlertTime - Date.now() < ALERT_SEND_INTERVAL
|
||||||
|
if (alertChanged) return
|
||||||
|
|
||||||
|
const subject = alertSubject(alertRec)
|
||||||
|
const rec = {
|
||||||
|
sms: {
|
||||||
|
body: subject
|
||||||
|
},
|
||||||
|
email: {
|
||||||
|
subject,
|
||||||
|
body: printEmailAlerts(alertRec)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alertFingerprint = currentAlertFingerprint
|
||||||
|
lastAlertTime = Date.now()
|
||||||
|
|
||||||
|
return plugins.sendMessage(rec)
|
||||||
|
})
|
||||||
|
.then(results => {
|
||||||
|
if (results && results.length > 0) logger.debug('Successfully sent alerts')
|
||||||
|
})
|
||||||
|
.catch(logger.error)
|
||||||
|
}
|
||||||
|
|
||||||
function checkBalance (rec) {
|
function checkBalance (rec) {
|
||||||
const settings = settingsLoader.settings()
|
const settings = settingsLoader.settings()
|
||||||
const config = configManager.unscoped(settings.config)
|
const config = configManager.unscoped(settings.config)
|
||||||
|
|
@ -35,8 +86,8 @@ function checkBalance (rec) {
|
||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkBalances () {
|
function checkBalances (plugins) {
|
||||||
return getBalances()
|
return plugins.checkBalances()
|
||||||
.then(balances => R.reject(R.isNil, balances.map(checkBalance)))
|
.then(balances => R.reject(R.isNil, balances.map(checkBalance)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,10 +136,10 @@ function devicesAndEvents () {
|
||||||
.then(arr => ({devices: arr[0], events: arr[1]}))
|
.then(arr => ({devices: arr[0], events: arr[1]}))
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkStatus () {
|
function checkStatus (plugins) {
|
||||||
const alerts = {devices: {}, deviceNames: {}}
|
const alerts = {devices: {}, deviceNames: {}}
|
||||||
|
|
||||||
return Promise.all([checkBalances(), devicesAndEvents()])
|
return Promise.all([checkBalances(plugins), devicesAndEvents()])
|
||||||
.then(([balances, rec]) => {
|
.then(([balances, rec]) => {
|
||||||
const devices = rec.devices
|
const devices = rec.devices
|
||||||
const events = rec.events
|
const events = rec.events
|
||||||
|
|
@ -163,16 +214,10 @@ function alertSubject (alertRec) {
|
||||||
return '[Lamassu] Errors reported: ' + alertTypes.join(', ')
|
return '[Lamassu] Errors reported: ' + alertTypes.join(', ')
|
||||||
}
|
}
|
||||||
|
|
||||||
function alertFingerprint (alertRec) {
|
function buildAlertFingerprint (alertRec) {
|
||||||
const subject = alertSubject(alertRec)
|
const subject = alertSubject(alertRec)
|
||||||
if (!subject) return null
|
if (!subject) return null
|
||||||
return crypto.createHash('sha256').update(subject).digest('hex')
|
return crypto.createHash('sha256').update(subject).digest('hex')
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {checkNotification}
|
||||||
init,
|
|
||||||
checkStatus,
|
|
||||||
printEmailAlerts,
|
|
||||||
alertFingerprint,
|
|
||||||
alertSubject
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ const crypto = require('crypto')
|
||||||
const dbm = require('./postgresql_interface')
|
const dbm = require('./postgresql_interface')
|
||||||
const db = require('./db')
|
const db = require('./db')
|
||||||
const logger = require('./logger')
|
const logger = require('./logger')
|
||||||
const notifier = require('./notifier')
|
|
||||||
const T = require('./time')
|
const T = require('./time')
|
||||||
const configManager = require('./config-manager')
|
const configManager = require('./config-manager')
|
||||||
const ticker = require('./ticker')
|
const ticker = require('./ticker')
|
||||||
|
|
@ -16,8 +15,6 @@ const exchange = require('./exchange')
|
||||||
const sms = require('./sms')
|
const sms = require('./sms')
|
||||||
const email = require('./email')
|
const email = require('./email')
|
||||||
|
|
||||||
const CHECK_NOTIFICATION_INTERVAL = 30 * T.seconds
|
|
||||||
const ALERT_SEND_INTERVAL = T.hour
|
|
||||||
const STALE_INCOMING_TX_AGE = T.week
|
const STALE_INCOMING_TX_AGE = T.week
|
||||||
const STALE_LIVE_INCOMING_TX_AGE = 10 * T.minutes
|
const STALE_LIVE_INCOMING_TX_AGE = 10 * T.minutes
|
||||||
const MAX_NOTIFY_AGE = 2 * T.days
|
const MAX_NOTIFY_AGE = 2 * T.days
|
||||||
|
|
@ -34,9 +31,6 @@ const coins = {
|
||||||
ETH: {unitScale: 18}
|
ETH: {unitScale: 18}
|
||||||
}
|
}
|
||||||
|
|
||||||
let alertFingerprint = null
|
|
||||||
let lastAlertTime = null
|
|
||||||
|
|
||||||
function plugins (settings) {
|
function plugins (settings) {
|
||||||
function buildRates (deviceId, tickers) {
|
function buildRates (deviceId, tickers) {
|
||||||
const config = configManager.machineScoped(deviceId, settings.config)
|
const config = configManager.machineScoped(deviceId, settings.config)
|
||||||
|
|
@ -407,56 +401,6 @@ function plugins (settings) {
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendNoAlerts () {
|
|
||||||
const subject = '[Lamassu] All clear'
|
|
||||||
const rec = {
|
|
||||||
sms: {
|
|
||||||
body: subject
|
|
||||||
},
|
|
||||||
email: {
|
|
||||||
subject,
|
|
||||||
body: 'No errors are reported for your machines.'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sendMessage(rec)
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkNotification () {
|
|
||||||
return notifier.checkStatus()
|
|
||||||
.then(alertRec => {
|
|
||||||
const currentAlertFingerprint = notifier.alertFingerprint(alertRec)
|
|
||||||
if (!currentAlertFingerprint) {
|
|
||||||
const inAlert = !!alertFingerprint
|
|
||||||
alertFingerprint = null
|
|
||||||
lastAlertTime = null
|
|
||||||
if (inAlert) return sendNoAlerts()
|
|
||||||
}
|
|
||||||
|
|
||||||
const alertChanged = currentAlertFingerprint === alertFingerprint &&
|
|
||||||
lastAlertTime - Date.now() < ALERT_SEND_INTERVAL
|
|
||||||
if (alertChanged) return
|
|
||||||
|
|
||||||
const subject = notifier.alertSubject(alertRec)
|
|
||||||
const rec = {
|
|
||||||
sms: {
|
|
||||||
body: subject
|
|
||||||
},
|
|
||||||
email: {
|
|
||||||
subject,
|
|
||||||
body: notifier.printEmailAlerts(alertRec)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
alertFingerprint = currentAlertFingerprint
|
|
||||||
lastAlertTime = Date.now()
|
|
||||||
|
|
||||||
return sendMessage(rec)
|
|
||||||
})
|
|
||||||
.then(results => {
|
|
||||||
if (results && results.length > 0) logger.debug('Successfully sent alerts')
|
|
||||||
})
|
|
||||||
.catch(logger.error)
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkDeviceBalances (deviceId) {
|
function checkDeviceBalances (deviceId) {
|
||||||
const config = configManager.machineScoped(deviceId, settings.config)
|
const config = configManager.machineScoped(deviceId, settings.config)
|
||||||
const cryptoCodes = config.cryptoCurrencies
|
const cryptoCodes = config.cryptoCurrencies
|
||||||
|
|
@ -489,12 +433,6 @@ function plugins (settings) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function startCheckingNotification (config) {
|
|
||||||
notifier.init(checkBalances)
|
|
||||||
checkNotification()
|
|
||||||
setInterval(checkNotification, CHECK_NOTIFICATION_INTERVAL)
|
|
||||||
}
|
|
||||||
|
|
||||||
function randomCode () {
|
function randomCode () {
|
||||||
return new BigNumber(crypto.randomBytes(3).toString('hex'), 16).shift(-6).toFixed(6).slice(-6)
|
return new BigNumber(crypto.randomBytes(3).toString('hex'), 16).shift(-6).toFixed(6).slice(-6)
|
||||||
}
|
}
|
||||||
|
|
@ -564,7 +502,6 @@ function plugins (settings) {
|
||||||
sendCoins,
|
sendCoins,
|
||||||
cashOut,
|
cashOut,
|
||||||
dispenseAck,
|
dispenseAck,
|
||||||
startCheckingNotification,
|
|
||||||
getPhoneCode,
|
getPhoneCode,
|
||||||
fetchPhoneTx,
|
fetchPhoneTx,
|
||||||
executeTrades,
|
executeTrades,
|
||||||
|
|
@ -574,7 +511,9 @@ function plugins (settings) {
|
||||||
monitorIncoming,
|
monitorIncoming,
|
||||||
monitorUnnotified,
|
monitorUnnotified,
|
||||||
sweepLiveHD,
|
sweepLiveHD,
|
||||||
sweepOldHD
|
sweepOldHD,
|
||||||
|
sendMessage,
|
||||||
|
checkBalances
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
const plugins = require('./plugins')
|
const plugins = require('./plugins')
|
||||||
|
const notifier = require('./notifier')
|
||||||
const T = require('./time')
|
const T = require('./time')
|
||||||
|
|
||||||
const INCOMING_TX_INTERVAL = 30 * T.seconds
|
const INCOMING_TX_INTERVAL = 30 * T.seconds
|
||||||
|
|
@ -9,6 +10,7 @@ const SWEEP_OLD_HD_INTERVAL = 2 * T.minutes
|
||||||
const TRADE_INTERVAL = 10 * T.seconds
|
const TRADE_INTERVAL = 10 * T.seconds
|
||||||
const PONG_INTERVAL = 10 * T.seconds
|
const PONG_INTERVAL = 10 * T.seconds
|
||||||
const PONG_CLEAR_INTERVAL = 1 * T.day
|
const PONG_CLEAR_INTERVAL = 1 * T.day
|
||||||
|
const CHECK_NOTIFICATION_INTERVAL = 30 * T.seconds
|
||||||
|
|
||||||
let pi
|
let pi
|
||||||
|
|
||||||
|
|
@ -27,6 +29,7 @@ function start (settings) {
|
||||||
pi.monitorUnnotified()
|
pi.monitorUnnotified()
|
||||||
pi.sweepLiveHD()
|
pi.sweepLiveHD()
|
||||||
pi.sweepOldHD()
|
pi.sweepOldHD()
|
||||||
|
notifier.checkNotification(pi)
|
||||||
|
|
||||||
setInterval(() => pi.executeTrades(), TRADE_INTERVAL)
|
setInterval(() => pi.executeTrades(), TRADE_INTERVAL)
|
||||||
setInterval(() => pi.monitorLiveIncoming(), LIVE_INCOMING_TX_INTERVAL)
|
setInterval(() => pi.monitorLiveIncoming(), LIVE_INCOMING_TX_INTERVAL)
|
||||||
|
|
@ -36,6 +39,7 @@ function start (settings) {
|
||||||
setInterval(() => pi.sweepOldHD(), SWEEP_OLD_HD_INTERVAL)
|
setInterval(() => pi.sweepOldHD(), SWEEP_OLD_HD_INTERVAL)
|
||||||
setInterval(() => pi.pong(), PONG_INTERVAL)
|
setInterval(() => pi.pong(), PONG_INTERVAL)
|
||||||
setInterval(() => pi.pongClear(), PONG_CLEAR_INTERVAL)
|
setInterval(() => pi.pongClear(), PONG_CLEAR_INTERVAL)
|
||||||
|
setInterval(() => notifier.checkNotification(pi), CHECK_NOTIFICATION_INTERVAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {start, reload}
|
module.exports = {start, reload}
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,7 @@ const db = require('./db')
|
||||||
const dbm = require('./postgresql_interface')
|
const dbm = require('./postgresql_interface')
|
||||||
const pairing = require('./pairing')
|
const pairing = require('./pairing')
|
||||||
const settingsLoader = require('./settings-loader')
|
const settingsLoader = require('./settings-loader')
|
||||||
|
const plugins = require('./plugins')
|
||||||
let plugins
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init
|
init
|
||||||
|
|
@ -30,12 +29,13 @@ function poll (req, res, next) {
|
||||||
const deviceId = req.deviceId
|
const deviceId = req.deviceId
|
||||||
const deviceTime = req.deviceTime
|
const deviceTime = req.deviceTime
|
||||||
const pid = req.query.pid
|
const pid = req.query.pid
|
||||||
const settings = settingsLoader.settings()
|
const settings = req.settings
|
||||||
const config = configManager.machineScoped(deviceId, settings.config)
|
const config = configManager.machineScoped(deviceId, settings.config)
|
||||||
|
const pi = plugins(settings)
|
||||||
|
|
||||||
pids[deviceId] = {pid, ts: Date.now()}
|
pids[deviceId] = {pid, ts: Date.now()}
|
||||||
|
|
||||||
plugins.pollQueries(deviceTime, deviceId, req.query)
|
pi.pollQueries(deviceTime, deviceId, req.query)
|
||||||
.then(results => {
|
.then(results => {
|
||||||
const cartridges = results.cartridges
|
const cartridges = results.cartridges
|
||||||
|
|
||||||
|
|
@ -77,24 +77,28 @@ function poll (req, res, next) {
|
||||||
|
|
||||||
function trade (req, res, next) {
|
function trade (req, res, next) {
|
||||||
const tx = req.body
|
const tx = req.body
|
||||||
|
const pi = plugins(req.settings)
|
||||||
|
|
||||||
tx.cryptoAtoms = new BigNumber(tx.cryptoAtoms)
|
tx.cryptoAtoms = new BigNumber(tx.cryptoAtoms)
|
||||||
|
|
||||||
plugins.trade(req.deviceId, tx)
|
pi.trade(req.deviceId, tx)
|
||||||
.then(() => cacheAndRespond(req, res))
|
.then(() => cacheAndRespond(req, res))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
function stateChange (req, res, next) {
|
function stateChange (req, res, next) {
|
||||||
plugins.stateChange(req.deviceId, req.deviceTime, req.body)
|
const pi = plugins(req.settings)
|
||||||
|
pi.stateChange(req.deviceId, req.deviceTime, req.body)
|
||||||
.then(() => cacheAndRespond(req, res))
|
.then(() => cacheAndRespond(req, res))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
function send (req, res, next) {
|
function send (req, res, next) {
|
||||||
|
const pi = plugins(req.settings)
|
||||||
const tx = req.body
|
const tx = req.body
|
||||||
tx.cryptoAtoms = new BigNumber(tx.cryptoAtoms)
|
tx.cryptoAtoms = new BigNumber(tx.cryptoAtoms)
|
||||||
|
|
||||||
return plugins.sendCoins(req.deviceId, tx)
|
return pi.sendCoins(req.deviceId, tx)
|
||||||
.then(status => {
|
.then(status => {
|
||||||
const body = {txId: status && status.txId}
|
const body = {txId: status && status.txId}
|
||||||
return cacheAndRespond(req, res, body)
|
return cacheAndRespond(req, res, body)
|
||||||
|
|
@ -103,35 +107,40 @@ function send (req, res, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function cashOut (req, res, next) {
|
function cashOut (req, res, next) {
|
||||||
|
const pi = plugins(req.settings)
|
||||||
logger.info({tx: req.body, cmd: 'cashOut'})
|
logger.info({tx: req.body, cmd: 'cashOut'})
|
||||||
const tx = req.body
|
const tx = req.body
|
||||||
tx.cryptoAtoms = new BigNumber(tx.cryptoAtoms)
|
tx.cryptoAtoms = new BigNumber(tx.cryptoAtoms)
|
||||||
|
|
||||||
return plugins.cashOut(req.deviceId, tx)
|
return pi.cashOut(req.deviceId, tx)
|
||||||
.then(cryptoAddress => cacheAndRespond(req, res, {toAddress: cryptoAddress}))
|
.then(cryptoAddress => cacheAndRespond(req, res, {toAddress: cryptoAddress}))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
function dispenseAck (req, res, next) {
|
function dispenseAck (req, res, next) {
|
||||||
plugins.dispenseAck(req.deviceId, req.body.tx)
|
const pi = plugins(req.settings)
|
||||||
|
pi.dispenseAck(req.deviceId, req.body.tx)
|
||||||
.then(() => cacheAndRespond(req, res))
|
.then(() => cacheAndRespond(req, res))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
function deviceEvent (req, res, next) {
|
function deviceEvent (req, res, next) {
|
||||||
plugins.logEvent(req.deviceId, req.body)
|
const pi = plugins(req.settings)
|
||||||
|
pi.logEvent(req.deviceId, req.body)
|
||||||
.then(() => cacheAndRespond(req, res))
|
.then(() => cacheAndRespond(req, res))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyUser (req, res, next) {
|
function verifyUser (req, res, next) {
|
||||||
plugins.verifyUser(req.body)
|
const pi = plugins(req.settings)
|
||||||
|
pi.verifyUser(req.body)
|
||||||
.then(idResult => cacheAndRespond(req, res, idResult))
|
.then(idResult => cacheAndRespond(req, res, idResult))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyTx (req, res, next) {
|
function verifyTx (req, res, next) {
|
||||||
plugins.verifyTransaction(req.body)
|
const pi = plugins(req.settings)
|
||||||
|
pi.verifyTransaction(req.body)
|
||||||
.then(idResult => cacheAndRespond(req, res, idResult))
|
.then(idResult => cacheAndRespond(req, res, idResult))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
@ -159,9 +168,10 @@ function pair (req, res, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function phoneCode (req, res, next) {
|
function phoneCode (req, res, next) {
|
||||||
|
const pi = plugins(req.settings)
|
||||||
const phone = req.body.phone
|
const phone = req.body.phone
|
||||||
|
|
||||||
return plugins.getPhoneCode(phone)
|
return pi.getPhoneCode(phone)
|
||||||
.then(code => cacheAndRespond(req, res, {code}))
|
.then(code => cacheAndRespond(req, res, {code}))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (err.name === 'BadNumberError') throw httpError('Bad number', 410)
|
if (err.name === 'BadNumberError') throw httpError('Bad number', 410)
|
||||||
|
|
@ -180,7 +190,8 @@ function updatePhone (req, res, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchPhoneTx (req, res, next) {
|
function fetchPhoneTx (req, res, next) {
|
||||||
return plugins.fetchPhoneTx(req.query.phone)
|
const pi = plugins(req.settings)
|
||||||
|
return pi.fetchPhoneTx(req.query.phone)
|
||||||
.then(r => res.json(r))
|
.then(r => res.json(r))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
@ -315,8 +326,6 @@ function authorize (req, res, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function init (opts) {
|
function init (opts) {
|
||||||
plugins = opts.plugins
|
|
||||||
|
|
||||||
const skip = options.logLevel === 'debug'
|
const skip = options.logLevel === 'debug'
|
||||||
? () => false
|
? () => false
|
||||||
: (req, res) => _.includes(req.path, ['/poll', '/state']) && res.statusCode === 200
|
: (req, res) => _.includes(req.path, ['/poll', '/state']) && res.statusCode === 200
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue