From 9ecbc3aa79ebc13b47789a056f23f41a73d6e5ce Mon Sep 17 00:00:00 2001 From: "dmit.b" Date: Fri, 8 May 2026 15:21:31 +0300 Subject: [PATCH] Fix: Encode Response body as JSON string in _watch endpoint --- bin/routes/auth_routes.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/routes/auth_routes.dart b/bin/routes/auth_routes.dart index 5e7235f..dbb7796 100644 --- a/bin/routes/auth_routes.dart +++ b/bin/routes/auth_routes.dart @@ -30,6 +30,7 @@ class AuthRoutes { final user = await database.findUserByLogin(login); if (user == null || !BCrypt.checkpw(password, user.pwdHash)) { + await database.createLog(login, 'Failed login attempt'); return Response(401, body: 'Invalid credentials'); } @@ -42,6 +43,7 @@ class AuthRoutes { ); final token = jwt.sign(SecretKey(secret)); + await database.createLog(login, 'Successful login'); return Response(200, body: jsonEncode({ 'user': user.toMap(), 'token': token @@ -56,22 +58,26 @@ class AuthRoutes { final password = data['password']; final user = await database.createUser(login, password); + await database.createLog(login, 'User registration'); return Response(201, body: jsonEncode(user.toMap())); } - Future _watch(Request request) async { + Future _watch(Request request, String login) async { final uniqueId = request.url.queryParameters['unique_id']; if (!database.isValidShareId(uniqueId!)) { + await database.createLog(login, 'Accessed invalid share link'); return Response(404, body: 'Share link not found'); } final position = await database.getLatestPosition(); if (position == null) { + await database.createLog(login, 'Accessed share link - no position'); return Response(404, body: 'No position available'); } - return Response(200, body: position.toJson()); + await database.createLog(login, 'Accessed share link'); + return Response(200, body: jsonEncode(position.toJson())); } } \ No newline at end of file