fix undefined bug
This commit is contained in:
parent
1cdc6726b4
commit
02af5baaad
2 changed files with 16 additions and 4 deletions
2
index.js
2
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) => {
|
||||
|
|
16
stats.js
16
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();
|
||||
}
|
||||
if(typeof instance!=="string" ){
|
||||
calcStats(instance);
|
||||
}
|
||||
}
|
||||
function updatejson(){
|
||||
fs.writeFile('./uptime.json',JSON.stringify(uptimeObject),_=>{});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue