Polish Round 2 (#2845)

This commit is contained in:
Joe Milazzo 2024-04-11 17:01:34 -05:00 committed by GitHub
parent c47fec4648
commit 5195f08c2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 63 additions and 22 deletions

View file

@ -30,9 +30,9 @@ public enum LibraryType
[Description("Light Novel")]
LightNovel = 4,
/// <summary>
/// Uses Comic regex for filename parsing, uses ComicVine type of Parsing. Will replace Comic type in future
/// Uses Comic regex for filename parsing, uses Comic Vine type of Parsing. Will replace Comic type in future
/// </summary>
[Description("Comic (ComicVine)")]
[Description("Comic (Comic Vine)")]
ComicVine = 5,
}

View file

@ -108,7 +108,7 @@ public class DeviceService : IDeviceService
public async Task<bool> SendTo(IReadOnlyList<int> chapterIds, int deviceId)
{
var settings = await _unitOfWork.SettingsRepository.GetSettingsDtoAsync();
if (!settings.IsEmailSetup())
if (!settings.IsEmailSetupForSendToDevice())
throw new KavitaException("send-to-kavita-email");
var device = await _unitOfWork.DeviceRepository.GetDeviceById(deviceId);
@ -123,9 +123,16 @@ public class DeviceService : IDeviceService
throw new KavitaException("send-to-size-limit");
device.UpdateLastUsed();
_unitOfWork.DeviceRepository.Update(device);
await _unitOfWork.CommitAsync();
try
{
device.UpdateLastUsed();
_unitOfWork.DeviceRepository.Update(device);
await _unitOfWork.CommitAsync();
}
catch (Exception ex)
{
_logger.LogError(ex, "There was an issue updating device last used time");
}
var success = await _emailService.SendFilesToEmail(new SendToDto()
{

View file

@ -126,7 +126,7 @@ public class ScrobblingService : IScrobblingService
var users = await _unitOfWork.UserRepository.GetAllUsersAsync();
foreach (var user in users)
{
if (string.IsNullOrEmpty(user.AniListAccessToken) || !_tokenService.HasTokenExpired(user.AniListAccessToken)) continue;
if (string.IsNullOrEmpty(user.AniListAccessToken) || !TokenService.HasTokenExpired(user.AniListAccessToken)) continue;
_logger.LogInformation("User {UserName}'s AniList token has expired! They need to regenerate it for scrobbling to work", user.UserName);
await _eventHub.SendMessageToAsync(MessageFactory.ScrobblingKeyExpired,
MessageFactory.ScrobblingKeyExpiredEvent(ScrobbleProvider.AniList), user.Id);
@ -151,7 +151,7 @@ public class ScrobblingService : IScrobblingService
private async Task<bool> HasTokenExpired(string token, ScrobbleProvider provider)
{
if (string.IsNullOrEmpty(token) ||
!_tokenService.HasTokenExpired(token)) return false;
!TokenService.HasTokenExpired(token)) return false;
var license = await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.LicenseKey);
if (string.IsNullOrEmpty(license.Value)) return true;
@ -778,7 +778,7 @@ public class ScrobblingService : IScrobblingService
continue;
}
if (_tokenService.HasTokenExpired(evt.AppUser.AniListAccessToken))
if (TokenService.HasTokenExpired(evt.AppUser.AniListAccessToken))
{
_unitOfWork.ScrobbleRepository.Attach(new ScrobbleError()
{

View file

@ -561,7 +561,7 @@ public class ReadingListService : IReadingListService
// How can we match properly with ComicVine library when year is part of the series unless we do this in 2 passes and see which has a better match
if (!userSeries.Any())
if (userSeries.Count == 0)
{
// Report that no series exist in the reading list
importSummary.Results.Add(new CblBookResult

View file

@ -24,8 +24,7 @@ public interface ITokenService
Task<string> CreateToken(AppUser user);
Task<TokenRequestDto?> ValidateRefreshToken(TokenRequestDto request);
Task<string> CreateRefreshToken(AppUser user);
Task<string> GetJwtFromUser(AppUser user);
bool HasTokenExpired(string token);
Task<string?> GetJwtFromUser(AppUser user);
}
@ -135,18 +134,21 @@ public class TokenService : ITokenService
}
}
public async Task<string> GetJwtFromUser(AppUser user)
public async Task<string?> GetJwtFromUser(AppUser user)
{
var userClaims = await _userManager.GetClaimsAsync(user);
var jwtClaim = userClaims.FirstOrDefault(claim => claim.Type == "jwt");
return jwtClaim?.Value;
}
public bool HasTokenExpired(string? token)
public static bool HasTokenExpired(string? token)
{
if (string.IsNullOrEmpty(token)) return true;
var tokenHandler = new JwtSecurityTokenHandler();
var tokenContent = tokenHandler.ReadJwtToken(token);
return tokenContent.ValidTo >= DateTime.UtcNow;
var validToUtc = tokenContent.ValidTo.ToUniversalTime();
return validToUtc < DateTime.UtcNow;
}
}