From c4403de09966313e1c72e2d0d8a68c62a51092e2 Mon Sep 17 00:00:00 2001 From: adjoly Date: Sun, 19 Oct 2025 17:02:27 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20change?= =?UTF-8?q?=20to=20isLogged=20boolean?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/user/ping.md | 2 +- src/api/user/gPing.js | 37 ++++++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/doc/user/ping.md b/doc/user/ping.md index 8051bf1..1e6dded 100644 --- a/doc/user/ping.md +++ b/doc/user/ping.md @@ -36,6 +36,6 @@ Can return: - 200 ```json { - "lastSeenTime": "" + "isLogged": "" } ``` diff --git a/src/api/user/gPing.js b/src/api/user/gPing.js index 2d2d018..b14f003 100644 --- a/src/api/user/gPing.js +++ b/src/api/user/gPing.js @@ -1,21 +1,28 @@ /** - * @param {import('fastify').FastifyRequest} request - * @param {import('fastify').FastifyReply} reply - * @param {import('fastify').FastifyInstance} fastify + * @param {import('fastify').FastifyRequest} request + * @param {import('fastify').FastifyReply} reply + * @param {import('fastify').FastifyInstance} fastify */ export async function gPing(request, reply, fastify, getActivityTime) { - try { - const user = request.params.userId; + try { + const user = request.params.userId; + const time = getActivityTime.get(user); - const time = getActivityTime.get(user); - console.log(time) + if (!time || !time.time) { + return reply.code(404).send({ error: "User not found or no activity time recorded" }); + } - return reply.code(200) - .send({ - lastSeenTime: time.time - }); - } catch (err) { - fastify.log.error(err); - return reply.code(500).send({ error: "Internal server error" }); - } + 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) { + fastify.log.error(err); + return reply.code(500).send({ error: "Internal server error" }); + } }