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);
|
inviteres(req, res);
|
||||||
})
|
})
|
||||||
app.use("/uptime",(req,res)=>{
|
app.use("/uptime",(req,res)=>{
|
||||||
|
console.log(req.query.name)
|
||||||
const uptime=stats.uptime[req.query.name];
|
const uptime=stats.uptime[req.query.name];
|
||||||
|
console.log(req.query.name,uptime,stats.uptime)
|
||||||
res.send(uptime);
|
res.send(uptime);
|
||||||
})
|
})
|
||||||
app.use('/', async (req, res) => {
|
app.use('/', async (req, res) => {
|
||||||
|
|
18
stats.js
18
stats.js
|
@ -4,11 +4,15 @@ let uptimeObject={};
|
||||||
if(fs.existsSync("./uptime.json")){
|
if(fs.existsSync("./uptime.json")){
|
||||||
try{
|
try{
|
||||||
uptimeObject=JSON.parse(fs.readFileSync('./uptime.json', 'utf8'));
|
uptimeObject=JSON.parse(fs.readFileSync('./uptime.json', 'utf8'));
|
||||||
|
|
||||||
}catch{
|
}catch{
|
||||||
uptimeObject={};
|
uptimeObject={};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(uptimeObject["undefined"]){
|
||||||
|
delete uptimeObject["undefined"];
|
||||||
|
updatejson();
|
||||||
|
}
|
||||||
async function observe(instances){
|
async function observe(instances){
|
||||||
const active=new Set();
|
const active=new Set();
|
||||||
async function resolveinstance(instance){
|
async function resolveinstance(instance){
|
||||||
|
@ -113,11 +117,15 @@ function calcStats(instance){
|
||||||
instance.uptime={daytime,weektime,alltime}
|
instance.uptime={daytime,weektime,alltime}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param {string} name
|
* @param {string|Object} instance
|
||||||
* @param {boolean} status
|
* @param {boolean} status
|
||||||
*/
|
*/
|
||||||
function setSatus(instance,status){
|
function setSatus(instance,status){
|
||||||
const name=instance.name;
|
let name=instance.name;
|
||||||
|
if(typeof instance==="string" ){
|
||||||
|
name=instance;
|
||||||
|
}
|
||||||
|
|
||||||
let obj=uptimeObject[name];
|
let obj=uptimeObject[name];
|
||||||
let needSetting=false;
|
let needSetting=false;
|
||||||
if(!obj){
|
if(!obj){
|
||||||
|
@ -133,7 +141,9 @@ function setSatus(instance,status){
|
||||||
obj.push({time:Date.now(),online:status});
|
obj.push({time:Date.now(),online:status});
|
||||||
updatejson();
|
updatejson();
|
||||||
}
|
}
|
||||||
calcStats(instance);
|
if(typeof instance!=="string" ){
|
||||||
|
calcStats(instance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function updatejson(){
|
function updatejson(){
|
||||||
fs.writeFile('./uptime.json',JSON.stringify(uptimeObject),_=>{});
|
fs.writeFile('./uptime.json',JSON.stringify(uptimeObject),_=>{});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue