A ton of random bugs and polish (#3668)

This commit is contained in:
Joe Milazzo 2025-03-23 17:06:20 -05:00 committed by GitHub
parent b45d92ea5c
commit de651215f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
144 changed files with 852 additions and 848 deletions

View file

@ -73,12 +73,27 @@ public class BookService : IBookService
private const string BookApiUrl = "book-resources?file=";
private readonly PdfComicInfoExtractor _pdfComicInfoExtractor;
/// <summary>
/// Setup the most lenient book parsing options possible as people have some really bad epubs
/// </summary>
public static readonly EpubReaderOptions BookReaderOptions = new()
{
PackageReaderOptions = new PackageReaderOptions
{
IgnoreMissingToc = true,
SkipInvalidManifestItems = true
SkipInvalidManifestItems = true,
},
Epub2NcxReaderOptions = new Epub2NcxReaderOptions
{
IgnoreMissingContentForNavigationPoints = true
},
SpineReaderOptions = new SpineReaderOptions
{
IgnoreMissingManifestItems = true
},
BookCoverReaderOptions = new BookCoverReaderOptions
{
Epub2MetadataIgnoreMissingManifestItem = true
}
};

View file

@ -11,6 +11,7 @@ using API.DTOs.SeriesDetail;
using API.Entities;
using API.Entities.Enums;
using API.Entities.Metadata;
using API.Entities.Person;
using API.Extensions;
using API.Helpers;
using API.Helpers.Builders;
@ -73,7 +74,7 @@ public class SeriesService : ISeriesService
}
/// <summary>
/// Returns the first chapter for a series to extract metadata from (ie Summary, etc)
/// Returns the first chapter for a series to extract metadata from (ie Summary, etc.)
/// </summary>
/// <param name="series">The full series with all volumes and chapters on it</param>
/// <returns></returns>
@ -324,7 +325,7 @@ public class SeriesService : ISeriesService
await _unitOfWork.CommitAsync();
// Trigger code to cleanup tags, collections, people, etc
// Trigger code to clean up tags, collections, people, etc
try
{
await _taskScheduler.CleanupDbEntries();
@ -915,19 +916,19 @@ public class SeriesService : ISeriesService
// Calculate the time differences between consecutive chapters
var timeDifferences = new List<TimeSpan>();
DateTime? previousChapterTime = null;
foreach (var chapter in chapters)
foreach (var chapterCreatedUtc in chapters.Select(c => c.CreatedUtc))
{
if (previousChapterTime.HasValue && (chapter.CreatedUtc - previousChapterTime.Value) <= TimeSpan.FromHours(1))
if (previousChapterTime.HasValue && (chapterCreatedUtc - previousChapterTime.Value) <= TimeSpan.FromHours(1))
{
continue; // Skip this chapter if it's within an hour of the previous one
}
if ((chapter.CreatedUtc - previousChapterTime ?? TimeSpan.Zero) != TimeSpan.Zero)
if ((chapterCreatedUtc - previousChapterTime ?? TimeSpan.Zero) != TimeSpan.Zero)
{
timeDifferences.Add(chapter.CreatedUtc - previousChapterTime ?? TimeSpan.Zero);
timeDifferences.Add(chapterCreatedUtc - previousChapterTime ?? TimeSpan.Zero);
}
previousChapterTime = chapter.CreatedUtc;
previousChapterTime = chapterCreatedUtc;
}
if (timeDifferences.Count < minimumTimeDeltas)

View file

@ -34,7 +34,6 @@ public interface ITaskScheduler
void RefreshSeriesMetadata(int libraryId, int seriesId, bool forceUpdate = false, bool forceColorscape = false);
Task ScanSeries(int libraryId, int seriesId, bool forceUpdate = false);
void AnalyzeFilesForSeries(int libraryId, int seriesId, bool forceUpdate = false);
void AnalyzeFilesForLibrary(int libraryId, bool forceUpdate = false);
void CancelStatsTasks();
Task RunStatCollection();
void CovertAllCoversToEncoding();
@ -267,11 +266,6 @@ public class TaskScheduler : ITaskScheduler
RecurringJob.AddOrUpdate(ReportStatsTaskId, () => _statsService.Send(), Cron.Daily(Rnd.Next(0, 22)), RecurringJobOptions);
}
public void AnalyzeFilesForLibrary(int libraryId, bool forceUpdate = false)
{
_logger.LogInformation("Enqueuing library file analysis for: {LibraryId}", libraryId);
BackgroundJob.Enqueue(() => _wordCountAnalyzerService.ScanLibrary(libraryId, forceUpdate));
}
/// <summary>
/// Upon cancelling stat, we do report to the Stat service that we are no longer going to be reporting

View file

@ -8,6 +8,7 @@ using API.Data;
using API.Data.Repositories;
using API.Entities;
using API.Entities.Enums;
using API.Entities.Person;
using API.Extensions;
using API.SignalR;
using EasyCaching.Core;

View file

@ -708,7 +708,7 @@ public static partial class Parser
return HasSpecialMarker(filePath);
}
public static string ParseMangaSeries(string filename)
private static string ParseMangaSeries(string filename)
{
foreach (var regex in MangaSeriesRegex)
{
@ -716,6 +716,7 @@ public static partial class Parser
var group = matches
.Select(match => match.Groups["Series"])
.FirstOrDefault(group => group.Success && group != Match.Empty);
if (group != null)
{
return CleanTitle(group.Value);

View file

@ -11,6 +11,7 @@ using API.Data.Repositories;
using API.Entities;
using API.Entities.Enums;
using API.Entities.Metadata;
using API.Entities.Person;
using API.Extensions;
using API.Helpers;
using API.Helpers.Builders;

View file

@ -302,7 +302,8 @@ public class ThemeService : IThemeService
var existingThemes = _directoryService.ScanFiles(_directoryService.SiteThemeDirectory, string.Empty);
if (existingThemes.Any(f => Path.GetFileName(f) == dto.CssFile))
{
throw new KavitaException("Cannot download file, file already on disk");
// This can happen if you delete then immediately download (to refresh). We should just delete the old file and download. Users can always rollback their version with github directly
_directoryService.DeleteFiles(existingThemes.Where(f => Path.GetFileName(f) == dto.CssFile));
}
var finalLocation = await DownloadSiteTheme(dto);

View file

@ -346,7 +346,7 @@ public partial class VersionUpdaterService : IVersionUpdaterService
if (DateTime.UtcNow - fileInfo.LastWriteTimeUtc <= CacheDuration)
{
var cachedData = await File.ReadAllTextAsync(_cacheFilePath);
return System.Text.Json.JsonSerializer.Deserialize<IList<UpdateNotificationDto>>(cachedData);
return JsonSerializer.Deserialize<IList<UpdateNotificationDto>>(cachedData);
}
return null;