diff --git a/app.js b/app.js index 852520e..76ed48d 100644 --- a/app.js +++ b/app.js @@ -205,7 +205,39 @@ app.use('/ext/getbasicstats', function(req,res) { }); app.use('/ext/getlasttxs/:min', function(req, res) { - db.get_last_txs(req, function(data, count) { + var min = req.params.min, start, length; + // split url suffix by forward slash and remove blank entries + var split = req.url.split('/').filter(function(v) { return v; }); + // determine how many parameters were passed + switch (split.length) { + case 2: + // capture start and length + start = split[0]; + length = split[1]; + break; + default: + if (split.length == 1) { + // capture start + start = split[0]; + } else if (split.length > 2) { + // capture start and length + start = split[0]; + length = split[1]; + } + break; + } + + // fix parameters + if (typeof length === 'undefined' || isNaN(length) || length > settings.index.last_txs) + length = settings.index.last_txs; + if (typeof start === 'undefined' || isNaN(start) || start < 0) + start = 0; + if (typeof min === 'undefined' || isNaN(min ) || min < 0) + min = 0; + else + min = (min * 100000000); + + db.get_last_txs(start, length, min, function(data, count) { res.json({"data":data, "recordsTotal": count, "recordsFiltered": count}); }); }); diff --git a/lib/database.js b/lib/database.js index 0f52f87..3c29ec0 100644 --- a/lib/database.js +++ b/lib/database.js @@ -395,17 +395,8 @@ module.exports = { }); }, - get_last_txs: function(req, cb) { - if (typeof req.query.length === 'undefined' || isNaN(req.query.length) || req.query.length > settings.index.last_txs) - req.query.length = settings.index.last_txs; - if (typeof req.query.start === 'undefined' || isNaN(req.query.start) || req.query.start < 0) - req.query.start = 0; - if (typeof req.params.min === 'undefined' || isNaN(req.params.min ) || req.params.min < 0) - req.params.min = 0; - else - req.params.min = (req.params.min * 100000000); - - this.get_last_txs_ajax(req.query.start, req.query.length, req.params.min,function(txs, count) { + get_last_txs: function(start, length, min, cb) { + this.get_last_txs_ajax(start, length, min, function(txs, count) { var data = []; for(i=0; i