From 76afe1d2b3a07522362a7522a35fe1098b297dc7 Mon Sep 17 00:00:00 2001 From: Utopiah Date: Mon, 8 May 2023 15:43:30 +0200 Subject: [PATCH] currentusage working with test/restart example --- index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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) {