Release Bugfixes (#2470)
This commit is contained in:
parent
d796d06fd1
commit
bdcd3965fd
14 changed files with 194 additions and 25 deletions
|
@ -175,13 +175,13 @@ public class ScrobblingService : IScrobblingService
|
|||
private async Task<string> GetTokenForProvider(int userId, ScrobbleProvider provider)
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);
|
||||
if (user == null) return null;
|
||||
if (user == null) return string.Empty;
|
||||
|
||||
return provider switch
|
||||
{
|
||||
ScrobbleProvider.AniList => user.AniListAccessToken,
|
||||
_ => string.Empty
|
||||
};
|
||||
} ?? string.Empty;
|
||||
}
|
||||
|
||||
public async Task ScrobbleReviewUpdate(int userId, int seriesId, string reviewTitle, string reviewBody)
|
||||
|
@ -192,11 +192,9 @@ public class ScrobblingService : IScrobblingService
|
|||
if (series == null) throw new KavitaException(await _localizationService.Translate(userId, "series-doesnt-exist"));
|
||||
|
||||
_logger.LogInformation("Processing Scrobbling review event for {UserId} on {SeriesName}", userId, series.Name);
|
||||
if (await CheckIfCanScrobble(userId, seriesId, series)) return;
|
||||
if (await CheckIfCannotScrobble(userId, seriesId, series)) return;
|
||||
|
||||
if (string.IsNullOrEmpty(reviewTitle) || string.IsNullOrEmpty(reviewBody) || (reviewTitle.Length < 2200 ||
|
||||
reviewTitle.Length > 120 ||
|
||||
reviewTitle.Length < 20))
|
||||
if (IsAniListReviewValid(reviewTitle, reviewBody))
|
||||
{
|
||||
_logger.LogDebug(
|
||||
"Rejecting Scrobble event for {Series}. Review is not long enough to meet requirements", series.Name);
|
||||
|
@ -232,6 +230,13 @@ public class ScrobblingService : IScrobblingService
|
|||
_logger.LogDebug("Added Scrobbling Review update on {SeriesName} with Userid {UserId} ", series.Name, userId);
|
||||
}
|
||||
|
||||
private static bool IsAniListReviewValid(string reviewTitle, string reviewBody)
|
||||
{
|
||||
return string.IsNullOrEmpty(reviewTitle) || string.IsNullOrEmpty(reviewBody) || (reviewTitle.Length < 2200 ||
|
||||
reviewTitle.Length > 120 ||
|
||||
reviewTitle.Length < 20);
|
||||
}
|
||||
|
||||
public async Task ScrobbleRatingUpdate(int userId, int seriesId, float rating)
|
||||
{
|
||||
if (!await _licenseService.HasActiveLicense()) return;
|
||||
|
@ -240,7 +245,7 @@ public class ScrobblingService : IScrobblingService
|
|||
if (series == null) throw new KavitaException(await _localizationService.Translate(userId, "series-doesnt-exist"));
|
||||
|
||||
_logger.LogInformation("Processing Scrobbling rating event for {UserId} on {SeriesName}", userId, series.Name);
|
||||
if (await CheckIfCanScrobble(userId, seriesId, series)) return;
|
||||
if (await CheckIfCannotScrobble(userId, seriesId, series)) return;
|
||||
|
||||
var existingEvt = await _unitOfWork.ScrobbleRepository.GetEvent(userId, series.Id,
|
||||
ScrobbleEventType.ScoreUpdated);
|
||||
|
@ -279,7 +284,7 @@ public class ScrobblingService : IScrobblingService
|
|||
if (series == null) throw new KavitaException(await _localizationService.Translate(userId, "series-doesnt-exist"));
|
||||
|
||||
_logger.LogInformation("Processing Scrobbling reading event for {UserId} on {SeriesName}", userId, series.Name);
|
||||
if (await CheckIfCanScrobble(userId, seriesId, series)) return;
|
||||
if (await CheckIfCannotScrobble(userId, seriesId, series)) return;
|
||||
|
||||
var existingEvt = await _unitOfWork.ScrobbleRepository.GetEvent(userId, series.Id,
|
||||
ScrobbleEventType.ChapterRead);
|
||||
|
@ -334,11 +339,11 @@ public class ScrobblingService : IScrobblingService
|
|||
if (series == null) throw new KavitaException(await _localizationService.Translate(userId, "series-doesnt-exist"));
|
||||
|
||||
_logger.LogInformation("Processing Scrobbling want-to-read event for {UserId} on {SeriesName}", userId, series.Name);
|
||||
if (await CheckIfCanScrobble(userId, seriesId, series)) return;
|
||||
if (await CheckIfCannotScrobble(userId, seriesId, series)) return;
|
||||
|
||||
var existing = await _unitOfWork.ScrobbleRepository.Exists(userId, series.Id,
|
||||
onWantToRead ? ScrobbleEventType.AddWantToRead : ScrobbleEventType.RemoveWantToRead);
|
||||
if (existing) return;
|
||||
if (existing) return; // BUG: If I take a series and add to remove from want to read, then add to want to read, Kavita rejects the second as a duplicate, when it's not
|
||||
|
||||
var evt = new ScrobbleEvent()
|
||||
{
|
||||
|
@ -355,7 +360,7 @@ public class ScrobblingService : IScrobblingService
|
|||
_logger.LogDebug("Added Scrobbling WantToRead update on {SeriesName} with Userid {UserId} ", series.Name, userId);
|
||||
}
|
||||
|
||||
private async Task<bool> CheckIfCanScrobble(int userId, int seriesId, Series series)
|
||||
private async Task<bool> CheckIfCannotScrobble(int userId, int seriesId, Series series)
|
||||
{
|
||||
if (await _unitOfWork.UserRepository.HasHoldOnSeries(userId, seriesId))
|
||||
{
|
||||
|
@ -616,7 +621,7 @@ public class ScrobblingService : IScrobblingService
|
|||
await SetAndCheckRateLimit(userRateLimits, user, license.Value);
|
||||
}
|
||||
|
||||
var totalProgress = readEvents.Count + addToWantToRead.Count + removeWantToRead.Count + ratingEvents.Count + decisions.Count + reviewEvents.Count;
|
||||
var totalProgress = readEvents.Count + decisions.Count + ratingEvents.Count + decisions.Count + reviewEvents.Count;
|
||||
|
||||
_logger.LogInformation("Found {TotalEvents} Scrobble Events", totalProgress);
|
||||
try
|
||||
|
@ -693,6 +698,24 @@ public class ScrobblingService : IScrobblingService
|
|||
LocalizedSeriesName = evt.Series.LocalizedName,
|
||||
Year = evt.Series.Metadata.ReleaseYear
|
||||
}));
|
||||
|
||||
// After decisions, we need to mark all the want to read and remove from want to read as completed
|
||||
if (decisions.All(d => d.IsProcessed))
|
||||
{
|
||||
foreach (var scrobbleEvent in addToWantToRead)
|
||||
{
|
||||
scrobbleEvent.IsProcessed = true;
|
||||
scrobbleEvent.ProcessDateUtc = DateTime.UtcNow;
|
||||
_unitOfWork.ScrobbleRepository.Update(scrobbleEvent);
|
||||
}
|
||||
foreach (var scrobbleEvent in removeWantToRead)
|
||||
{
|
||||
scrobbleEvent.IsProcessed = true;
|
||||
scrobbleEvent.ProcessDateUtc = DateTime.UtcNow;
|
||||
_unitOfWork.ScrobbleRepository.Update(scrobbleEvent);
|
||||
}
|
||||
await _unitOfWork.CommitAsync();
|
||||
}
|
||||
}
|
||||
catch (FlurlHttpException)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@ public interface ICleanupService
|
|||
Task CleanupBackups();
|
||||
Task CleanupLogs();
|
||||
void CleanupTemp();
|
||||
Task EnsureChapterProgressIsCapped();
|
||||
/// <summary>
|
||||
/// Responsible to remove Series from Want To Read when user's have fully read the series and the series has Publication Status of Completed or Cancelled.
|
||||
/// </summary>
|
||||
|
@ -89,6 +90,8 @@ public class CleanupService : ICleanupService
|
|||
await DeleteReadingListCoverImages();
|
||||
await SendProgress(0.8F, "Cleaning old logs");
|
||||
await CleanupLogs();
|
||||
await SendProgress(0.9F, "Cleaning progress events that exceed 100%");
|
||||
await EnsureChapterProgressIsCapped();
|
||||
await SendProgress(1F, "Cleanup finished");
|
||||
_logger.LogInformation("Cleanup finished");
|
||||
}
|
||||
|
@ -243,6 +246,17 @@ public class CleanupService : ICleanupService
|
|||
_logger.LogInformation("Temp directory purged");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that each chapter's progress (pages read) is capped at the total pages. This can get out of sync when a chapter is replaced after being read with one with lower page count.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task EnsureChapterProgressIsCapped()
|
||||
{
|
||||
_logger.LogInformation("Cleaning up any progress rows that exceed chapter page count");
|
||||
await _unitOfWork.AppUserProgressRepository.UpdateAllProgressThatAreMoreThanChapterPages();
|
||||
_logger.LogInformation("Cleaning up any progress rows that exceed chapter page count - complete");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This does not cleanup any Series that are not Completed or Cancelled
|
||||
/// </summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue