diff --git a/index.js b/index.js index dab84a2..11e59ed 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,8 @@ +// for testing without killing current version +// PORT=7789 node . +// if validating tests can replace via e.g +// killall onhygi ; nohup node . & + const http = require("http"); const fs = require("fs"); const path = require("path"); @@ -75,6 +80,18 @@ app.get('/', (req, res) => { res.json( quota ) }) +app.get('/currentusage', (req, res) => { + res.json( + quota.map( rule => { + let leftOnRule = { id: rule.id } + let now = Date.now()/1000 + leftOnRule['perHour'] = rule.perHour - usage[rule.id].filter( t => t>now-60*60).length + leftOnRule['perDay'] = rule.perDay - usage[rule.id].filter( t => t>now-60*60*24).length + return leftOnRule + }) + ) +}) + app.get('/check', (req, res) => { console.log('starting check') if (!req.query.url) {