More Polish (#2320)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
parent
cd3a15fa3b
commit
5f11973696
34 changed files with 337 additions and 161 deletions
|
|
@ -191,6 +191,7 @@ public class AccountController : BaseApiController
|
|||
.SingleOrDefaultAsync(x => x.NormalizedUserName == loginDto.Username.ToUpper());
|
||||
}
|
||||
|
||||
_logger.LogInformation("{UserName} attempting to login from {IpAddress}", loginDto.Username, HttpContext.Connection.RemoteIpAddress?.ToString());
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -93,7 +93,6 @@ public class ReviewController : BaseApiController
|
|||
|
||||
if (totalReviews > 10)
|
||||
{
|
||||
//var stepSize = Math.Max(totalReviews / 10, 1); // Calculate step size, ensuring it's at least 1
|
||||
var stepSize = Math.Max((totalReviews - 4) / 8, 1);
|
||||
|
||||
var selectedReviews = new List<UserReviewDto>()
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class SeriesController : BaseApiController
|
|||
private readonly IEasyCachingProvider _reviewCacheProvider;
|
||||
private readonly IEasyCachingProvider _recommendationCacheProvider;
|
||||
private readonly IEasyCachingProvider _externalSeriesCacheProvider;
|
||||
public const string CacheKey = "recommendation_";
|
||||
private const string CacheKey = "recommendation_";
|
||||
|
||||
|
||||
public SeriesController(ILogger<SeriesController> logger, ITaskScheduler taskScheduler, IUnitOfWork unitOfWork,
|
||||
|
|
@ -584,14 +584,14 @@ public class SeriesController : BaseApiController
|
|||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpGet("external-series-detail")]
|
||||
public async Task<ActionResult<ExternalSeriesDto>> GetExternalSeriesInfo(int? aniListId, long? malId)
|
||||
public async Task<ActionResult<ExternalSeriesDto>> GetExternalSeriesInfo(int? aniListId, long? malId, int? seriesId)
|
||||
{
|
||||
if (!await _licenseService.HasActiveLicense())
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
var cacheKey = $"{CacheKey}-{aniListId ?? 0}-{malId ?? 0}";
|
||||
var cacheKey = $"{CacheKey}-{aniListId ?? 0}-{malId ?? 0}-{seriesId ?? 0}";
|
||||
var results = await _externalSeriesCacheProvider.GetAsync<ExternalSeriesDto>(cacheKey);
|
||||
if (results.HasValue)
|
||||
{
|
||||
|
|
@ -600,7 +600,7 @@ public class SeriesController : BaseApiController
|
|||
|
||||
try
|
||||
{
|
||||
var ret = await _externalMetadataService.GetExternalSeriesDetail(aniListId, malId);
|
||||
var ret = await _externalMetadataService.GetExternalSeriesDetail(aniListId, malId, seriesId);
|
||||
await _externalSeriesCacheProvider.SetAsync(cacheKey, ret, TimeSpan.FromMinutes(15));
|
||||
return Ok(ret);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using API.DTOs.Scrobbling;
|
||||
|
||||
namespace API.DTOs.Recommendation;
|
||||
|
||||
|
|
@ -8,7 +9,7 @@ public class ExternalSeriesDetailDto
|
|||
public int? AniListId { get; set; }
|
||||
public long? MALId { get; set; }
|
||||
public IList<string> Synonyms { get; set; }
|
||||
public PlusMediaFormat PlusMediaFormat { get; set; }
|
||||
public MediaFormat PlusMediaFormat { get; set; }
|
||||
public string? SiteUrl { get; set; }
|
||||
public string? CoverUrl { get; set; }
|
||||
public IList<string> Genres { get; set; }
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
using System.ComponentModel;
|
||||
|
||||
namespace API.DTOs.Recommendation;
|
||||
|
||||
public enum PlusMediaFormat
|
||||
{
|
||||
[Description("Manga")]
|
||||
Manga = 1,
|
||||
[Description("Comic")]
|
||||
Comic = 2,
|
||||
[Description("LightNovel")]
|
||||
LightNovel = 3,
|
||||
[Description("Book")]
|
||||
Book = 4
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using API.DTOs.Recommendation;
|
||||
|
||||
namespace API.DTOs.Scrobbling;
|
||||
#nullable enable
|
||||
|
|
@ -18,12 +19,20 @@ public enum ScrobbleEventType
|
|||
Review = 4
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents PlusMediaFormat
|
||||
/// </summary>
|
||||
public enum MediaFormat
|
||||
{
|
||||
[Description("Manga")]
|
||||
Manga = 1,
|
||||
[Description("Comic")]
|
||||
Comic = 2,
|
||||
[Description("LightNovel")]
|
||||
LightNovel = 3,
|
||||
Book = 4
|
||||
[Description("Book")]
|
||||
Book = 4,
|
||||
Unknown = 5
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using API.Data;
|
||||
using API.Data.Repositories;
|
||||
using API.DTOs.Recommendation;
|
||||
using API.DTOs.Scrobbling;
|
||||
using API.Entities.Enums;
|
||||
using API.Helpers.Builders;
|
||||
using Flurl.Http;
|
||||
|
|
@ -13,9 +15,22 @@ using Microsoft.Extensions.Logging;
|
|||
|
||||
namespace API.Services.Plus;
|
||||
|
||||
/// <summary>
|
||||
/// Used for matching and fetching metadata on a series
|
||||
/// </summary>
|
||||
internal class ExternalMetadataIdsDto
|
||||
{
|
||||
public long? MalId { get; set; }
|
||||
public int? AniListId { get; set; }
|
||||
|
||||
public string? SeriesName { get; set; }
|
||||
public string? LocalizedSeriesName { get; set; }
|
||||
public MediaFormat? PlusMediaFormat { get; set; } = MediaFormat.Unknown;
|
||||
}
|
||||
|
||||
public interface IExternalMetadataService
|
||||
{
|
||||
Task<ExternalSeriesDetailDto> GetExternalSeriesDetail(int? aniListId, long? malId);
|
||||
Task<ExternalSeriesDetailDto> GetExternalSeriesDetail(int? aniListId, long? malId, int? seriesId);
|
||||
}
|
||||
|
||||
public class ExternalMetadataService : IExternalMetadataService
|
||||
|
|
@ -32,7 +47,7 @@ public class ExternalMetadataService : IExternalMetadataService
|
|||
cli.Settings.HttpClientFactory = new UntrustedCertClientFactory());
|
||||
}
|
||||
|
||||
public async Task<ExternalSeriesDetailDto?> GetExternalSeriesDetail(int? aniListId, long? malId)
|
||||
public async Task<ExternalSeriesDetailDto?> GetExternalSeriesDetail(int? aniListId, long? malId, int? seriesId)
|
||||
{
|
||||
if (!aniListId.HasValue && !malId.HasValue)
|
||||
{
|
||||
|
|
@ -40,12 +55,38 @@ public class ExternalMetadataService : IExternalMetadataService
|
|||
}
|
||||
|
||||
var license = (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.LicenseKey)).Value;
|
||||
return await GetSeriesDetail(license, aniListId, malId);
|
||||
return await GetSeriesDetail(license, aniListId, malId, seriesId);
|
||||
|
||||
}
|
||||
|
||||
private async Task<ExternalSeriesDetailDto?> GetSeriesDetail(string license, int? anilistId, long? malId)
|
||||
private async Task<ExternalSeriesDetailDto?> GetSeriesDetail(string license, int? aniListId, long? malId, int? seriesId)
|
||||
{
|
||||
var payload = new ExternalMetadataIdsDto()
|
||||
{
|
||||
AniListId = aniListId,
|
||||
MalId = malId,
|
||||
SeriesName = string.Empty,
|
||||
LocalizedSeriesName = string.Empty
|
||||
};
|
||||
if (seriesId is > 0)
|
||||
{
|
||||
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId.Value, SeriesIncludes.Metadata | SeriesIncludes.Library);
|
||||
if (series != null)
|
||||
{
|
||||
if (payload.AniListId <= 0)
|
||||
{
|
||||
payload.AniListId = ScrobblingService.ExtractId<int>(series.Metadata.WebLinks, ScrobblingService.AniListWeblinkWebsite);
|
||||
}
|
||||
if (payload.MalId <= 0)
|
||||
{
|
||||
payload.MalId = ScrobblingService.ExtractId<long>(series.Metadata.WebLinks, ScrobblingService.MalWeblinkWebsite);
|
||||
}
|
||||
payload.SeriesName = series.Name;
|
||||
payload.LocalizedSeriesName = series.LocalizedName;
|
||||
payload.PlusMediaFormat = ConvertToMediaFormat(series.Library.Type, series.Format);
|
||||
}
|
||||
|
||||
}
|
||||
try
|
||||
{
|
||||
return await (Configuration.KavitaPlusApiUrl + "/api/metadata/series/detail")
|
||||
|
|
@ -56,11 +97,7 @@ public class ExternalMetadataService : IExternalMetadataService
|
|||
.WithHeader("x-kavita-version", BuildInfo.Version)
|
||||
.WithHeader("Content-Type", "application/json")
|
||||
.WithTimeout(TimeSpan.FromSeconds(Configuration.DefaultTimeOutSecs))
|
||||
.PostJsonAsync(new
|
||||
{
|
||||
AnilistId = anilistId,
|
||||
MalId = malId,
|
||||
})
|
||||
.PostJsonAsync(payload)
|
||||
.ReceiveJson<ExternalSeriesDetailDto>();
|
||||
|
||||
}
|
||||
|
|
@ -71,4 +108,15 @@ public class ExternalMetadataService : IExternalMetadataService
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static MediaFormat ConvertToMediaFormat(LibraryType libraryType, MangaFormat seriesFormat)
|
||||
{
|
||||
return libraryType switch
|
||||
{
|
||||
LibraryType.Manga => seriesFormat == MangaFormat.Epub ? MediaFormat.LightNovel : MediaFormat.Manga,
|
||||
LibraryType.Comic => MediaFormat.Comic,
|
||||
LibraryType.Book => MediaFormat.Book,
|
||||
_ => MediaFormat.Unknown
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
|||
using API.Data;
|
||||
using API.Data.Repositories;
|
||||
using API.DTOs.Filtering;
|
||||
using API.DTOs.Recommendation;
|
||||
using API.DTOs.Scrobbling;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
|
|
@ -188,11 +189,19 @@ public class ScrobblingService : IScrobblingService
|
|||
|
||||
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);
|
||||
|
||||
_logger.LogInformation("Processing Scrobbling review event for {UserId} on {SeriesName}", userId, series.Name);
|
||||
if (await CheckIfCanScrobble(userId, seriesId, series)) return;
|
||||
|
||||
if (string.IsNullOrEmpty(reviewTitle) || string.IsNullOrEmpty(reviewBody) || (reviewTitle.Length < 2200 ||
|
||||
reviewTitle.Length > 120 ||
|
||||
reviewTitle.Length < 20))
|
||||
{
|
||||
_logger.LogDebug(
|
||||
"Rejecting Scrobble event for {Series}. Review is not long enough to meet requirements", series.Name);
|
||||
return;
|
||||
}
|
||||
|
||||
var existingEvt = await _unitOfWork.ScrobbleRepository.GetEvent(userId, series.Id,
|
||||
ScrobbleEventType.Review);
|
||||
if (existingEvt is {IsProcessed: false})
|
||||
|
|
@ -695,6 +704,7 @@ public class ScrobblingService : IScrobblingService
|
|||
_logger.LogInformation("Scrobbling Events is complete");
|
||||
}
|
||||
|
||||
|
||||
private async Task<int> ProcessEvents(IEnumerable<ScrobbleEvent> events, IDictionary<int, int> userRateLimits,
|
||||
int usersToScrobble, int progressCounter, int totalProgress, Func<ScrobbleEvent, Task<ScrobbleDto>> createEvent)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ public class StreamService : IStreamService
|
|||
var stream = user?.DashboardStreams.FirstOrDefault(d => d.Id == dto.Id);
|
||||
if (stream == null)
|
||||
throw new KavitaException(await _localizationService.Translate(userId, "dashboard-stream-doesnt-exist"));
|
||||
if (stream.Order == dto.ToPosition) return ;
|
||||
if (stream.Order == dto.ToPosition) return;
|
||||
|
||||
var list = user!.DashboardStreams.ToList();
|
||||
ReorderItems(list, stream.Id, dto.ToPosition);
|
||||
|
|
@ -132,6 +132,7 @@ public class StreamService : IStreamService
|
|||
|
||||
_unitOfWork.UserRepository.Update(user);
|
||||
await _unitOfWork.CommitAsync();
|
||||
if (!stream.Visible) return;
|
||||
await _eventHub.SendMessageToAsync(MessageFactory.DashboardUpdate, MessageFactory.DashboardUpdateEvent(user.Id),
|
||||
user.Id);
|
||||
}
|
||||
|
|
@ -264,9 +265,10 @@ public class StreamService : IStreamService
|
|||
var list = user!.SideNavStreams.ToList();
|
||||
ReorderItems(list, stream.Id, dto.ToPosition);
|
||||
user.SideNavStreams = list;
|
||||
|
||||
_unitOfWork.UserRepository.Update(user);
|
||||
|
||||
await _unitOfWork.CommitAsync();
|
||||
if (!stream.Visible) return;
|
||||
await _eventHub.SendMessageToAsync(MessageFactory.SideNavUpdate, MessageFactory.SideNavUpdateEvent(userId),
|
||||
userId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public static class Parser
|
|||
private static readonly ImmutableArray<string> FormatTagSpecialKeywords = ImmutableArray.Create(
|
||||
"Special", "Reference", "Director's Cut", "Box Set", "Box-Set", "Annual", "Anthology", "Epilogue",
|
||||
"One Shot", "One-Shot", "Prologue", "TPB", "Trade Paper Back", "Omnibus", "Compendium", "Absolute", "Graphic Novel",
|
||||
"GN", "FCBD");
|
||||
"GN", "FCBD", "Giant Size");
|
||||
|
||||
private static readonly char[] LeadingZeroesTrimChars = new[] { '0' };
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue