Random Fixes (#3549)

Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
This commit is contained in:
Joe Milazzo 2025-02-15 17:25:18 -06:00 committed by GitHub
parent ea81a2f432
commit 39726f8c4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 425 additions and 107 deletions

View file

@ -16,6 +16,7 @@ using Kavita.Common;
using Microsoft.Extensions.Logging;
using SharpCompress.Archives;
using SharpCompress.Common;
using YamlDotNet.Core;
namespace API.Services;
@ -354,6 +355,14 @@ public class ArchiveService : IArchiveService
foreach (var path in files)
{
var tempPath = Path.Join(tempLocation, _directoryService.FileSystem.Path.GetFileNameWithoutExtension(_directoryService.FileSystem.FileInfo.New(path).Name));
// Image series need different handling
if (Tasks.Scanner.Parser.Parser.IsImage(path))
{
var parentDirectory = _directoryService.FileSystem.DirectoryInfo.New(path).Parent?.Name;
tempPath = Path.Join(tempLocation, parentDirectory ?? _directoryService.FileSystem.FileInfo.New(path).Name);
}
progressCallback(Tuple.Create(_directoryService.FileSystem.FileInfo.New(path).Name, (1.0f * totalFiles) / count));
if (Tasks.Scanner.Parser.Parser.IsArchive(path))
{

View file

@ -173,7 +173,22 @@ public class CacheService : ICacheService
await extractLock.WaitAsync();
try {
if(_directoryService.Exists(extractPath)) return chapter;
if (_directoryService.Exists(extractPath))
{
if (extractPdfToImages)
{
var pdfImages = _directoryService.GetFiles(extractPath,
Tasks.Scanner.Parser.Parser.ImageFileExtensions);
if (pdfImages.Any())
{
return chapter;
}
}
else
{
return chapter;
}
}
var files = chapter?.Files.ToList();
ExtractChapterFiles(extractPath, files, extractPdfToImages);

View file

@ -122,6 +122,7 @@ public class ReaderService : IReaderService
var seenVolume = new Dictionary<int, bool>();
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId);
if (series == null) throw new KavitaException("series-doesnt-exist");
foreach (var chapter in chapters)
{
var userProgress = GetUserProgressForChapter(user, chapter);
@ -135,10 +136,6 @@ public class ReaderService : IReaderService
SeriesId = seriesId,
ChapterId = chapter.Id,
LibraryId = series.LibraryId,
Created = DateTime.Now,
CreatedUtc = DateTime.UtcNow,
LastModified = DateTime.Now,
LastModifiedUtc = DateTime.UtcNow
});
}
else
@ -206,7 +203,7 @@ public class ReaderService : IReaderService
/// <param name="user">Must have Progresses populated</param>
/// <param name="chapter"></param>
/// <returns></returns>
private static AppUserProgress? GetUserProgressForChapter(AppUser user, Chapter chapter)
private AppUserProgress? GetUserProgressForChapter(AppUser user, Chapter chapter)
{
AppUserProgress? userProgress = null;
@ -226,11 +223,12 @@ public class ReaderService : IReaderService
var progresses = user.Progresses.Where(x => x.ChapterId == chapter.Id && x.AppUserId == user.Id).ToList();
if (progresses.Count > 1)
{
user.Progresses = new List<AppUserProgress>
{
user.Progresses.First()
};
var highestProgress = progresses.Max(x => x.PagesRead);
var firstProgress = progresses.OrderBy(p => p.LastModifiedUtc).First();
firstProgress.PagesRead = highestProgress;
user.Progresses = [firstProgress];
userProgress = user.Progresses.First();
_logger.LogInformation("Trying to save progress and multiple progress entries exist, deleting and rewriting with highest progress rate: {@Progress}", userProgress);
}
}
@ -274,10 +272,6 @@ public class ReaderService : IReaderService
ChapterId = progressDto.ChapterId,
LibraryId = progressDto.LibraryId,
BookScrollId = progressDto.BookScrollId,
Created = DateTime.Now,
CreatedUtc = DateTime.UtcNow,
LastModified = DateTime.Now,
LastModifiedUtc = DateTime.UtcNow
});
_unitOfWork.UserRepository.Update(userWithProgress);
}

View file

@ -674,6 +674,12 @@ public class ParseScannedFiles
private static void RemapSeries(IList<ScanResult> scanResults, List<ParserInfo> allInfos, string localizedSeries, string nonLocalizedSeries)
{
// If the series names are identical, no remapping is needed (rare but valid)
if (localizedSeries.ToNormalized().Equals(nonLocalizedSeries.ToNormalized()))
{
return;
}
// Find all infos that need to be remapped from the localized series to the non-localized series
var normalizedLocalizedSeries = localizedSeries.ToNormalized();
var seriesToBeRemapped = allInfos.Where(i => i.Series.ToNormalized().Equals(normalizedLocalizedSeries)).ToList();