v0.7.8 - New Filtering System (#2260)
Co-authored-by: JeanPaulDOT <jp.houssier@gmail.com> Co-authored-by: Francois Wilhelmy <ice_mouton@hotmail.com> Co-authored-by: Gazy Mahomar <gmahomarf@gmail.com> Co-authored-by: Stijn <stijn.biemans@gmail.com> Co-authored-by: 無情天 <kofzhanganguo@126.com> Co-authored-by: Havokdan <havokdan@yahoo.com.br> Co-authored-by: Andre <andruecha32@gmail.com> Co-authored-by: Mateusz <mateuszvx8.96@gmail.com> Co-authored-by: Antonio Sanchez Castellón <angelfx19@gmail.com> Co-authored-by: Duarte Silva <smallflake@protonmail.com> Co-authored-by: LeeWan1210 <dldhks456@live.com> Co-authored-by: aleixcox <18121624@qq.com> Co-authored-by: Tomas Battistini <tomas.battistini@gmail.com> Co-authored-by: mareczek82 <marek.posiadala@gmail.com> Co-authored-by: Hans Kalisvaart <hans.kalisvaart@gmail.com> Co-authored-by: majora2007 <kavitareader@gmail.com> Co-authored-by: afermar <adrian.fm@protonmail.com> Co-authored-by: oxygen44k <iiccpp@outlook.com> Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: Hadrien b <hadrien.1997@gmail.com> Co-authored-by: Robbie Davis <robbie@therobbiedavis.com> Co-authored-by: Andre Smith <Hobogrammer@users.noreply.github.com> Co-authored-by: Safu Wan <safu@yahoo.com> Co-authored-by: sibeck <sibeck.clown@gmail.com> Co-authored-by: Florestano Pepe <florestano.pepe@gmail.com> Co-authored-by: 书签 <shuqian.emu@gmail.com> Co-authored-by: Stéphane Dupont <aleistor@gmail.com> Co-authored-by: gallegonovato <fran-carro@hotmail.es> Co-authored-by: AlienHack <the4got10@windowslive.com> Co-authored-by: 周書丞 <tmrsm_chan@hotmail.com> Co-authored-by: Andre Smith <andrepsmithjr@gmail.com> Co-authored-by: xe1st <dnzkckali@gmail.com> Co-authored-by: Jiří Heger <jiri.heger@gmail.com> Co-authored-by: DR <weblate-kavita.snowflake668@slmail.me> Co-authored-by: Mathieu Ares <matguitarist@gmail.com> Co-authored-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Co-authored-by: Gazy Mahomar <gmahomarf@users.noreply.github.com> Co-authored-by: Elias Jakob <elias.jakob100@gmail.com> Co-authored-by: Christian Zanon <chri8431@libero.it> Co-authored-by: Eryk Michalak <gnu.ewm@protonmail.com> Co-authored-by: Hoshino0881118 <hoshino0881118@gmail.com>
This commit is contained in:
parent
bdaadbecfc
commit
979508047c
221 changed files with 23403 additions and 6863 deletions
|
@ -104,7 +104,7 @@ public class ScrobblingService : IScrobblingService
|
|||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// An automated job that will run against all user's tokens and validate if they are still active
|
||||
/// </summary>
|
||||
/// <remarks>This service can validate without license check as the task which calls will be guarded</remarks>
|
||||
/// <returns></returns>
|
||||
|
@ -115,6 +115,7 @@ public class ScrobblingService : IScrobblingService
|
|||
foreach (var user in users)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -184,17 +185,13 @@ public class ScrobblingService : IScrobblingService
|
|||
public async Task ScrobbleReviewUpdate(int userId, int seriesId, string reviewTitle, string reviewBody)
|
||||
{
|
||||
if (!await _licenseService.HasActiveLicense()) return;
|
||||
var token = await GetTokenForProvider(userId, ScrobbleProvider.AniList);
|
||||
if (await HasTokenExpired(token, ScrobbleProvider.AniList))
|
||||
{
|
||||
throw new KavitaException(await _localizationService.Translate(userId, "unable-to-register-k+"));
|
||||
}
|
||||
|
||||
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId, SeriesIncludes.Metadata | SeriesIncludes.Library);
|
||||
if (series == null) throw new KavitaException(await _localizationService.Translate(userId, "series-doesnt-exist"));
|
||||
var library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(series.LibraryId);
|
||||
if (library is not {AllowScrobbling: true}) return;
|
||||
if (library.Type == LibraryType.Comic) return;
|
||||
|
||||
_logger.LogInformation("Processing Scrobbling review event for {UserId} on {SeriesName}", userId, series.Name);
|
||||
if (await CheckIfCanScrobble(userId, seriesId, series)) return;
|
||||
|
||||
var existingEvt = await _unitOfWork.ScrobbleRepository.GetEvent(userId, series.Id,
|
||||
ScrobbleEventType.Review);
|
||||
|
@ -229,17 +226,12 @@ public class ScrobblingService : IScrobblingService
|
|||
public async Task ScrobbleRatingUpdate(int userId, int seriesId, float rating)
|
||||
{
|
||||
if (!await _licenseService.HasActiveLicense()) return;
|
||||
var token = await GetTokenForProvider(userId, ScrobbleProvider.AniList);
|
||||
if (await HasTokenExpired(token, ScrobbleProvider.AniList))
|
||||
{
|
||||
throw new KavitaException(await _localizationService.Translate(userId, "anilist-cred-expired"));
|
||||
}
|
||||
|
||||
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId, SeriesIncludes.Metadata | SeriesIncludes.Library);
|
||||
if (series == null) throw new KavitaException(await _localizationService.Translate(userId, "series-doesnt-exist"));
|
||||
var library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(series.LibraryId);
|
||||
if (library is not {AllowScrobbling: true}) return;
|
||||
if (library.Type == LibraryType.Comic) return;
|
||||
|
||||
_logger.LogInformation("Processing Scrobbling rating event for {UserId} on {SeriesName}", userId, series.Name);
|
||||
if (await CheckIfCanScrobble(userId, seriesId, series)) return;
|
||||
|
||||
var existingEvt = await _unitOfWork.ScrobbleRepository.GetEvent(userId, series.Id,
|
||||
ScrobbleEventType.ScoreUpdated);
|
||||
|
@ -273,22 +265,12 @@ public class ScrobblingService : IScrobblingService
|
|||
public async Task ScrobbleReadingUpdate(int userId, int seriesId)
|
||||
{
|
||||
if (!await _licenseService.HasActiveLicense()) return;
|
||||
var token = await GetTokenForProvider(userId, ScrobbleProvider.AniList);
|
||||
if (await HasTokenExpired(token, ScrobbleProvider.AniList))
|
||||
{
|
||||
throw new KavitaException(await _localizationService.Translate(userId, "anilist-cred-expired"));
|
||||
}
|
||||
|
||||
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId, SeriesIncludes.Metadata | SeriesIncludes.Library);
|
||||
if (series == null) throw new KavitaException(await _localizationService.Translate(userId, "series-doesnt-exist"));
|
||||
if (await _unitOfWork.UserRepository.HasHoldOnSeries(userId, seriesId))
|
||||
{
|
||||
_logger.LogInformation("Series {SeriesName} is on UserId {UserId}'s hold list. Not scrobbling", series.Name, userId);
|
||||
return;
|
||||
}
|
||||
var library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(series.LibraryId);
|
||||
if (library is not {AllowScrobbling: true}) return;
|
||||
if (library.Type == LibraryType.Comic) return;
|
||||
|
||||
_logger.LogInformation("Processing Scrobbling reading event for {UserId} on {SeriesName}", userId, series.Name);
|
||||
if (await CheckIfCanScrobble(userId, seriesId, series)) return;
|
||||
|
||||
var existingEvt = await _unitOfWork.ScrobbleRepository.GetEvent(userId, series.Id,
|
||||
ScrobbleEventType.ChapterRead);
|
||||
|
@ -338,17 +320,12 @@ public class ScrobblingService : IScrobblingService
|
|||
public async Task ScrobbleWantToReadUpdate(int userId, int seriesId, bool onWantToRead)
|
||||
{
|
||||
if (!await _licenseService.HasActiveLicense()) return;
|
||||
var token = await GetTokenForProvider(userId, ScrobbleProvider.AniList);
|
||||
if (await HasTokenExpired(token, ScrobbleProvider.AniList))
|
||||
{
|
||||
throw new KavitaException(await _localizationService.Translate(userId, "anilist-cred-expired"));
|
||||
}
|
||||
|
||||
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId, SeriesIncludes.Metadata | SeriesIncludes.Library);
|
||||
if (series == null) throw new KavitaException(await _localizationService.Translate(userId, "series-doesnt-exist"));
|
||||
var library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(series.LibraryId);
|
||||
if (library is not {AllowScrobbling: true}) return;
|
||||
if (library.Type == LibraryType.Comic) return;
|
||||
|
||||
_logger.LogInformation("Processing Scrobbling want-to-read event for {UserId} on {SeriesName}", userId, series.Name);
|
||||
if (await CheckIfCanScrobble(userId, seriesId, series)) return;
|
||||
|
||||
var existing = await _unitOfWork.ScrobbleRepository.Exists(userId, series.Id,
|
||||
onWantToRead ? ScrobbleEventType.AddWantToRead : ScrobbleEventType.RemoveWantToRead);
|
||||
|
@ -369,6 +346,21 @@ 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)
|
||||
{
|
||||
if (await _unitOfWork.UserRepository.HasHoldOnSeries(userId, seriesId))
|
||||
{
|
||||
_logger.LogInformation("Series {SeriesName} is on UserId {UserId}'s hold list. Not scrobbling", series.Name,
|
||||
userId);
|
||||
return true;
|
||||
}
|
||||
|
||||
var library = await _unitOfWork.LibraryRepository.GetLibraryForIdAsync(series.LibraryId);
|
||||
if (library is not {AllowScrobbling: true}) return true;
|
||||
if (library.Type == LibraryType.Comic) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private async Task<int> GetRateLimit(string license, string aniListToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(aniListToken)) return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue