|
|
@ -359,6 +359,7 @@ cors(corsOptions), (req, res, next) => { |
|
|
|
RES.start = req.query["start"] |
|
|
|
RES.end = req.query["end"] |
|
|
|
RES.swarmlabname = req.query["swarmlabname"] |
|
|
|
RES.ok = 'ok' |
|
|
|
/* |
|
|
|
* |
|
|
|
* validate |
|
|
@ -389,26 +390,75 @@ cors(corsOptions), (req, res, next) => { |
|
|
|
} else { |
|
|
|
const db = client.db('fluent'); |
|
|
|
//usersession.SOCKET.user = isvalid.user
|
|
|
|
//usersession.SOCKET.scope = isvalid.scope // space delimeter
|
|
|
|
//usersession.SOCKET.token = isvalid.token
|
|
|
|
//db.collection('log', onCollection);
|
|
|
|
console.log(JSON.stringify('mongo connected')) |
|
|
|
var datestart = DateTime.fromISO(RES.start).toISODate() |
|
|
|
var dateend = DateTime.fromISO(RES.end).toISODate() |
|
|
|
var datestart = new Date(RES.start) |
|
|
|
var dateend = new Date(RES.end) |
|
|
|
if(datestart && dateend){ |
|
|
|
var search_term = { $and: [ { date: { $gt: datestart } }, { date: { $lt: dateend } } ] }; |
|
|
|
}else if(datestart){ |
|
|
|
var search_term = { $and: [ { date: { $gt: datestart } } ] }; |
|
|
|
}else if(dateend){ |
|
|
|
var search_term = { $and: [ { date: { $lt: dateend } } ] }; |
|
|
|
console.log(JSON.stringify('mongo ----------------connected')) |
|
|
|
console.log('-----test------- '+JSON.stringify(RES)) |
|
|
|
if ((typeof RES.start !== "undefined") && (typeof RES.end !== "undefined")) { |
|
|
|
if(DateTime.fromISO(RES.start).isValid){ |
|
|
|
var datestart = DateTime.fromISO(RES.start) |
|
|
|
var dateend = DateTime.fromISO(RES.end) |
|
|
|
var search_term = { |
|
|
|
"$and": [ |
|
|
|
{ |
|
|
|
"time": { |
|
|
|
$gte: datestart |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
"time": { |
|
|
|
$lt: dateend |
|
|
|
} |
|
|
|
}, |
|
|
|
] |
|
|
|
} |
|
|
|
}else{ |
|
|
|
RES.ok = 'no' |
|
|
|
} |
|
|
|
}else if(typeof RES.end !== "undefined"){ |
|
|
|
var dateend = DateTime.fromISO(RES.end) |
|
|
|
if(DateTime.fromISO(RES.end).isValid){ |
|
|
|
var search_term = { |
|
|
|
"$and": [ |
|
|
|
{ |
|
|
|
"time": { |
|
|
|
$lt: dateend |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
}else{ |
|
|
|
RES.ok = 'no' |
|
|
|
} |
|
|
|
}else if(typeof RES.start !== "undefined"){ |
|
|
|
var datestart = DateTime.fromISO(RES.start) |
|
|
|
if(DateTime.fromISO(RES.start).isValid){ |
|
|
|
var search_term = { |
|
|
|
"$and": [ |
|
|
|
{ |
|
|
|
"time": { |
|
|
|
$gte: datestart |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
}else{ |
|
|
|
RES.ok = 'no' |
|
|
|
} |
|
|
|
} |
|
|
|
if(RES.ok == 'ok'){ |
|
|
|
//var search_term = '{"$gte": new Date("2020-12-01T00:00:00.000Z") , "$lt": new Date("2020-12-11T16:17:36.470Z") }'
|
|
|
|
//var search_term = {"time" : {$lte : datenow}}
|
|
|
|
var resdataarray = [] |
|
|
|
var resraw = {} |
|
|
|
var reslab = '' |
|
|
|
db.collection('logs').find(search_term, {}).toArray() |
|
|
|
var datestart1 = DateTime.fromISO(RES.start) |
|
|
|
console.log('-----now1------- '+JSON.stringify(search_term)) |
|
|
|
console.log('-----now2------- '+JSON.stringify(datestart1)) |
|
|
|
console.log('-----now3------- '+JSON.stringify(datestart)) |
|
|
|
|
|
|
|
db.collection('logs').find(search_term).toArray() |
|
|
|
//db.collection('logs').find({"time" : {$gt : datestart}}).toArray()
|
|
|
|
.then(item => { |
|
|
|
console.log('item '+JSON.stringify(item)) |
|
|
|
for (let i in item) { |
|
|
|
reslab = item[i].tailed_path |
|
|
|
var segment_array = reslab.split( '/' ); |
|
|
@ -436,16 +486,17 @@ cors(corsOptions), (req, res, next) => { |
|
|
|
RES.error_msg = err |
|
|
|
res.json(RES) |
|
|
|
}) |
|
|
|
} else{ // RES.ok
|
|
|
|
RES.error_msg = 'no date' |
|
|
|
res.json(RES) |
|
|
|
} |
|
|
|
}); |
|
|
|
}else{ |
|
|
|
|
|
|
|
} // error mongo connect
|
|
|
|
}); // mongo connect
|
|
|
|
}else{ // token error
|
|
|
|
RES.data = 'no' |
|
|
|
RES.error_msg = "token err" |
|
|
|
res.json(RES) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
})() |
|
|
|
|
|
|
|
}); |
|
|
|