diff --git a/controllers/listing.js b/controllers/listing.js index 8f7e5b1..1302afd 100644 --- a/controllers/listing.js +++ b/controllers/listing.js @@ -1,5 +1,10 @@ const tor = require('../lib/tor'); +const orderValues = [ + 'consensus_weight', + 'first_seen' +]; + module.exports = (req, res, next) => { let title = 'Top nodes by consensus weight'; @@ -16,13 +21,17 @@ module.exports = (req, res, next) => { if(req.query.p) { query.offset = (query.limit * req.query.p) - query.limit; } + if(req.query.order && orderValues.includes(req.query.order)) { + query.order = req.query.order; + } tor.listNodes(query) .then(nodes => res.render('listing.html', { pageTitle: req.query.s ? `Search: ${req.query.s}` : false, title: title, nodes: nodes, - numOfNodes: query.limit + numOfNodes: query.limit, + orderValues: orderValues })) .catch(err => { if(err.statusCode == 400 && req.query.s) { diff --git a/views/listing.html b/views/listing.html index 5531944..cc979b9 100644 --- a/views/listing.html +++ b/views/listing.html @@ -3,6 +3,15 @@ {% block main %}

{{ title }}

+
+ + + + {% if nodes.length %}