diff --git a/index.js b/index.js index 4d31198..b5ddf81 100755 --- a/index.js +++ b/index.js @@ -147,7 +147,9 @@ app.use('/services/oembed', (req, res) => { inviteres(req, res); }) app.use("/uptime",(req,res)=>{ + console.log(req.query.name) const uptime=stats.uptime[req.query.name]; + console.log(req.query.name,uptime,stats.uptime) res.send(uptime); }) app.use('/', async (req, res) => { diff --git a/stats.js b/stats.js index 385ca5e..64ed3d2 100644 --- a/stats.js +++ b/stats.js @@ -4,11 +4,15 @@ let uptimeObject={}; if(fs.existsSync("./uptime.json")){ try{ uptimeObject=JSON.parse(fs.readFileSync('./uptime.json', 'utf8')); + }catch{ uptimeObject={}; } } - +if(uptimeObject["undefined"]){ + delete uptimeObject["undefined"]; + updatejson(); +} async function observe(instances){ const active=new Set(); async function resolveinstance(instance){ @@ -113,11 +117,15 @@ function calcStats(instance){ instance.uptime={daytime,weektime,alltime} } /** - * @param {string} name + * @param {string|Object} instance * @param {boolean} status */ function setSatus(instance,status){ - const name=instance.name; + let name=instance.name; + if(typeof instance==="string" ){ + name=instance; + } + let obj=uptimeObject[name]; let needSetting=false; if(!obj){ @@ -133,7 +141,9 @@ function setSatus(instance,status){ obj.push({time:Date.now(),online:status}); updatejson(); } - calcStats(instance); + if(typeof instance!=="string" ){ + calcStats(instance); + } } function updatejson(){ fs.writeFile('./uptime.json',JSON.stringify(uptimeObject),_=>{});