mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-03-11 12:35:48 -04:00
Co-authored-by: Joseph Milazzo <joseph.v.milazzo@gmail.com> Co-authored-by: Joe Milazzo <josephmajora@gmail.com>
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Kavita.API.Database;
|
|
using Kavita.API.Services;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Caching.Hybrid;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Kavita.Services;
|
|
|
|
public class AuthKeyService(IDataContext context, ILogger<AuthKeyService> logger, HybridCache cache) : IAuthKeyService
|
|
{
|
|
public async Task UpdateLastAccessedAsync(string authKey, CancellationToken ct = default)
|
|
{
|
|
logger.LogTrace("Updating last accessed Auth key: {AuthKey}", authKey);
|
|
await context.AppUserAuthKey
|
|
.Where(k => k.Key == authKey)
|
|
.ExecuteUpdateAsync(s =>
|
|
s.SetProperty(k => k.LastAccessedAtUtc, DateTime.UtcNow), cancellationToken: ct);
|
|
}
|
|
|
|
public async Task InvalidateAsync(string keyValue, CancellationToken cancellationToken = default)
|
|
{
|
|
var cacheKey = CreateCacheKey(keyValue);
|
|
await cache.RemoveAsync(cacheKey, cancellationToken);
|
|
}
|
|
|
|
public string CreateCacheKey(string keyValue)
|
|
{
|
|
return $"authKey_{keyValue}";
|
|
}
|
|
}
|