currentusage working with test/restart example

master
Fabien Benetou 2 years ago
parent 2120089421
commit 76afe1d2b3
  1. 17
      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) {

Loading…
Cancel
Save