handle double dispense WIP
This commit is contained in:
parent
adbd60b5a5
commit
1d323b0647
5 changed files with 107 additions and 3 deletions
|
|
@ -283,8 +283,11 @@ function waitForDispense (req, res) {
|
|||
|
||||
function dispense (req, res) {
|
||||
const tx = req.body.tx
|
||||
const body = {dispense: true}
|
||||
|
||||
return plugins.requestDispense(session(req), tx)
|
||||
.then(() => res.json(200))
|
||||
.then(() => cacheResponse(req, body))
|
||||
.then(() => res.json(body))
|
||||
.catch(err => {
|
||||
logger.error(err)
|
||||
res.sendStatus(500)
|
||||
|
|
@ -318,7 +321,7 @@ function init (localConfig) {
|
|||
app.get('/phone_tx', authMiddleware, fetchPhoneTx)
|
||||
app.post('/register_redeem', authMiddleware, registerRedeem)
|
||||
app.get('/await_dispense', authMiddleware, waitForDispense)
|
||||
app.post('/dispense', authMiddleware, dispense)
|
||||
app.post('/dispense', authMiddleware, cachedResponse, dispense)
|
||||
|
||||
localApp.get('/pid', function (req, res) {
|
||||
var machineFingerprint = req.query.fingerprint
|
||||
|
|
@ -354,3 +357,12 @@ function getFingerprint (req) {
|
|||
return (typeof req.connection.getPeerCertificate === 'function' &&
|
||||
req.connection.getPeerCertificate().fingerprint) || 'unknown'
|
||||
}
|
||||
|
||||
function cachedResponse (req, res, next) {
|
||||
return plugins.cachedResponse(session(req), req.path, req.method)
|
||||
.then(r => r.body ? res.json(r.body) : next())
|
||||
}
|
||||
|
||||
function cacheResponse (req, body) {
|
||||
return plugins.cacheResponse(session(req), req.path, req.method, body)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue