Compare commits

...

3 commits
v1.0.0 ... main

Author SHA1 Message Date
4f36e1b870
change to 1 second 2025-02-12 00:59:27 -05:00
f79b0d8094
add caching 2025-02-12 00:58:44 -05:00
e29ac278f3
add proper error handling because im stupid 2025-02-12 00:54:08 -05:00

View file

@ -26,13 +26,28 @@ let settings = {
arrayMax
};
let cache = {};
let cacheDate = 0;
if (mode == 'cli') {
main(settings);
} else if (mode == 'site') {
const app = e();
app.get('/top', async (req, res) => {
if ((new Date) - cacheDate < 1000*1) {
res.send(cache);
return;
}
let json = await fetch("https://nbg.dervland.net/api/followjson.php");
json = await json.json();
try {
json = await json.json();
} catch (err) {
json = {};
res.send(JSON.stringify({}));
return;
}
let { ref } = req.query;
@ -63,7 +78,10 @@ if (mode == 'cli') {
dat2[d[0]] = d[1] * 100 + "%";
}
res.send(JSON.stringify(dat2))
cache = JSON.stringify(dat2);
cacheDate = +(new Date);
res.send(cache)
})
app.listen(port);