From 6e18f1ce54e206f66251ea434e575915a3498f3c Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Wed, 24 Aug 2016 20:48:54 -0700 Subject: [PATCH] fix #39 404 for trades.csv --- plugins/server/controllers/data.js | 43 +++++++++++++++--------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/plugins/server/controllers/data.js b/plugins/server/controllers/data.js index 8c581703bd..bf338dece0 100644 --- a/plugins/server/controllers/data.js +++ b/plugins/server/controllers/data.js @@ -8,6 +8,9 @@ module.exports = function container (get, set) { .get('/sim_trades.csv', function (req, res, next) { res.setHeader('Content-Type', 'text/csv') res.write('Type,Time,Asset,Currency,Exchange,Price,Size,RSI,ROI\n') + if (!req.session.secret) { + return res.end() + } get('db.run_states').load(req.query.sim_id, function (err, sim_result) { if (err) return next(err) if (sim_result && sim_result.actions) { @@ -30,31 +33,29 @@ module.exports = function container (get, set) { }) }) .get('/trades.csv', function (req, res, next) { + res.setHeader('Content-Type', 'text/csv') + res.write('Type,Time,Asset,Currency,Exchange,Price,Size,RSI,ROI\n') if (!req.session.secret) { - res.setHeader('Content-Type', 'text/csv') - res.write('Type,Time,Asset,Currency,Exchange,Price,Size,RSI,ROI\n') - res.end() - return + return res.end() } get('db.run_states').load(get('zenbrain:app_name') + '_run', function (err, run_state) { if (err) return next(err) - if (!run_state) return res.renderStatus(404) - res.setHeader('Content-Type', 'text/csv') - res.write('Type,Time,Asset,Currency,Exchange,Price,Size,RSI,ROI\n') - ;(run_state.actions || []).forEach(function (action) { - var line = [ - action.type, - action.time, - action.asset, - action.currency, - action.exchange, - action.price, - action.size, - action.rsi, - action.roi - ].join(',') - res.write(line + '\n') - }) + if (run_state && run_state.actions) { + run_state.actions.forEach(function (action) { + var line = [ + action.type, + action.time, + action.asset, + action.currency, + action.exchange, + action.price, + action.size, + action.rsi, + action.roi + ].join(',') + res.write(line + '\n') + }) + } res.end() }) })