using System; using System.Threading.Tasks; using Kavita.API.Services; using Kavita.API.Store; using Kavita.Models.Entities.User; using Microsoft.AspNetCore.Http; namespace Kavita.Server.Middleware; /// /// If the user is authenticated, will update the field. /// /// This should be last in the stack of middlewares /// public class UpdateUserAsActiveMiddleware(RequestDelegate next) { public async Task InvokeAsync(HttpContext context, IUserContext userContext, IActiveUserTrackerService tracker) { try { var userId = userContext.GetUserId(); if (userId > 0) { tracker.RecordActive(userId.Value); } } catch (Exception) { await next(context); return; } await next(context); } }