mirror of
https://github.com/KeyZox71/knl_meowscendence.git
synced 2025-12-31 21:56:41 +01:00
「🔨」 fix: change to isLogged boolean
This commit is contained in:
@ -36,6 +36,6 @@ Can return:
|
|||||||
- 200
|
- 200
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"lastSeenTime": "<last seen time>"
|
"isLogged": "<true/false>"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@ -6,13 +6,20 @@
|
|||||||
export async function gPing(request, reply, fastify, getActivityTime) {
|
export async function gPing(request, reply, fastify, getActivityTime) {
|
||||||
try {
|
try {
|
||||||
const user = request.params.userId;
|
const user = request.params.userId;
|
||||||
|
|
||||||
const time = getActivityTime.get(user);
|
const time = getActivityTime.get(user);
|
||||||
console.log(time)
|
|
||||||
|
|
||||||
return reply.code(200)
|
if (!time || !time.time) {
|
||||||
.send({
|
return reply.code(404).send({ error: "User not found or no activity time recorded" });
|
||||||
lastSeenTime: time.time
|
}
|
||||||
|
|
||||||
|
const lastSeenTime = new Date(time.time);
|
||||||
|
const now = new Date();
|
||||||
|
const oneMinuteAgo = new Date(now.getTime() - 60000); // 60,000 ms = 1 minute
|
||||||
|
|
||||||
|
const isActiveInLastMinute = lastSeenTime >= oneMinuteAgo;
|
||||||
|
|
||||||
|
return reply.code(200).send({
|
||||||
|
isLogged: isActiveInLastMinute
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
fastify.log.error(err);
|
fastify.log.error(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user