Lots of Bugfixes (#2960)
Co-authored-by: Samuel Martins <s@smartins.ch> Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
This commit is contained in:
parent
97ffdd0975
commit
b50fa0fd1e
45 changed files with 563 additions and 282 deletions
|
|
@ -73,7 +73,8 @@ public class BookService : IBookService
|
|||
{
|
||||
PackageReaderOptions = new PackageReaderOptions
|
||||
{
|
||||
IgnoreMissingToc = true
|
||||
IgnoreMissingToc = true,
|
||||
SkipInvalidManifestItems = true
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using API.Data;
|
||||
using API.DTOs.Reader;
|
||||
|
|
@ -51,6 +53,8 @@ public class CacheService : ICacheService
|
|||
private readonly IReadingItemService _readingItemService;
|
||||
private readonly IBookmarkService _bookmarkService;
|
||||
|
||||
private static readonly ConcurrentDictionary<int, SemaphoreSlim> ExtractLocks = new();
|
||||
|
||||
public CacheService(ILogger<CacheService> logger, IUnitOfWork unitOfWork,
|
||||
IDirectoryService directoryService, IReadingItemService readingItemService,
|
||||
IBookmarkService bookmarkService)
|
||||
|
|
@ -166,11 +170,19 @@ public class CacheService : ICacheService
|
|||
var chapter = await _unitOfWork.ChapterRepository.GetChapterAsync(chapterId);
|
||||
var extractPath = GetCachePath(chapterId);
|
||||
|
||||
if (_directoryService.Exists(extractPath)) return chapter;
|
||||
var files = chapter?.Files.ToList();
|
||||
ExtractChapterFiles(extractPath, files, extractPdfToImages);
|
||||
SemaphoreSlim extractLock = ExtractLocks.GetOrAdd(chapterId, id => new SemaphoreSlim(1,1));
|
||||
|
||||
return chapter;
|
||||
await extractLock.WaitAsync();
|
||||
try {
|
||||
if(_directoryService.Exists(extractPath)) return chapter;
|
||||
|
||||
var files = chapter?.Files.ToList();
|
||||
ExtractChapterFiles(extractPath, files, extractPdfToImages);
|
||||
} finally {
|
||||
extractLock.Release();
|
||||
}
|
||||
|
||||
return chapter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -191,15 +203,25 @@ public class CacheService : ICacheService
|
|||
|
||||
if (files.Count > 0 && files[0].Format == MangaFormat.Image)
|
||||
{
|
||||
foreach (var file in files)
|
||||
// Check if all the files are Images. If so, do a directory copy, else do the normal copy
|
||||
if (files.All(f => f.Format == MangaFormat.Image))
|
||||
{
|
||||
if (fileCount > 1)
|
||||
{
|
||||
extraPath = file.Id + string.Empty;
|
||||
}
|
||||
_readingItemService.Extract(file.FilePath, Path.Join(extractPath, extraPath), MangaFormat.Image, files.Count);
|
||||
_directoryService.ExistOrCreate(extractPath);
|
||||
_directoryService.CopyFilesToDirectory(files.Select(f => f.FilePath), extractPath);
|
||||
}
|
||||
_directoryService.Flatten(extractDi.FullName);
|
||||
else
|
||||
{
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (fileCount > 1)
|
||||
{
|
||||
extraPath = file.Id + string.Empty;
|
||||
}
|
||||
_readingItemService.Extract(file.FilePath, Path.Join(extractPath, extraPath), MangaFormat.Image, files.Count);
|
||||
}
|
||||
_directoryService.Flatten(extractDi.FullName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach (var file in files)
|
||||
|
|
|
|||
|
|
@ -439,18 +439,13 @@ public class ImageService : IImageService
|
|||
rows = 1;
|
||||
cols = 2;
|
||||
}
|
||||
else if (coverImages.Count == 3)
|
||||
{
|
||||
rows = 2;
|
||||
cols = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default to 2x2 layout for more than 3 images
|
||||
rows = 2;
|
||||
cols = 2;
|
||||
}
|
||||
|
||||
|
||||
var image = Image.Black(dims.Width, dims.Height);
|
||||
|
||||
var thumbnailWidth = image.Width / cols;
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ public interface IScrobblingService
|
|||
public class ScrobblingService : IScrobblingService
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ITokenService _tokenService;
|
||||
private readonly IEventHub _eventHub;
|
||||
private readonly ILogger<ScrobblingService> _logger;
|
||||
private readonly ILicenseService _licenseService;
|
||||
|
|
@ -99,12 +98,10 @@ public class ScrobblingService : IScrobblingService
|
|||
private const string AccessTokenErrorMessage = "Access Token needs to be rotated to continue scrobbling";
|
||||
|
||||
|
||||
public ScrobblingService(IUnitOfWork unitOfWork, ITokenService tokenService,
|
||||
IEventHub eventHub, ILogger<ScrobblingService> logger, ILicenseService licenseService,
|
||||
ILocalizationService localizationService)
|
||||
public ScrobblingService(IUnitOfWork unitOfWork, IEventHub eventHub, ILogger<ScrobblingService> logger,
|
||||
ILicenseService licenseService, ILocalizationService localizationService)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_tokenService = tokenService;
|
||||
_eventHub = eventHub;
|
||||
_logger = logger;
|
||||
_licenseService = licenseService;
|
||||
|
|
|
|||
|
|
@ -142,10 +142,15 @@ public class SmartCollectionSyncService : ISmartCollectionSyncService
|
|||
// For everything that's not there, link it up for this user.
|
||||
_logger.LogInformation("Starting Sync on {CollectionName} with {SeriesCount} Series", info.Title, info.TotalItems);
|
||||
|
||||
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
|
||||
MessageFactory.SmartCollectionProgressEvent(info.Title, string.Empty, 0, info.TotalItems, ProgressEventType.Started));
|
||||
|
||||
var missingCount = 0;
|
||||
var missingSeries = new StringBuilder();
|
||||
var counter = -1;
|
||||
foreach (var seriesInfo in info.Series.OrderBy(s => s.SeriesName))
|
||||
{
|
||||
counter++;
|
||||
try
|
||||
{
|
||||
// Normalize series name and localized name
|
||||
|
|
@ -164,7 +169,12 @@ public class SmartCollectionSyncService : ISmartCollectionSyncService
|
|||
s.NormalizedLocalizedName == normalizedSeriesName)
|
||||
&& formats.Contains(s.Format));
|
||||
|
||||
if (existingSeries != null) continue;
|
||||
if (existingSeries != null)
|
||||
{
|
||||
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
|
||||
MessageFactory.SmartCollectionProgressEvent(info.Title, seriesInfo.SeriesName, counter, info.TotalItems, ProgressEventType.Updated));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Series not found in the collection, try to find it in the server
|
||||
var newSeries = await _unitOfWork.SeriesRepository.GetSeriesByAnyName(seriesInfo.SeriesName,
|
||||
|
|
@ -196,6 +206,8 @@ public class SmartCollectionSyncService : ISmartCollectionSyncService
|
|||
missingSeries.Append("<br/>");
|
||||
}
|
||||
|
||||
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
|
||||
MessageFactory.SmartCollectionProgressEvent(info.Title, seriesInfo.SeriesName, counter, info.TotalItems, ProgressEventType.Updated));
|
||||
}
|
||||
|
||||
// At this point, all series in the info have been checked and added if necessary
|
||||
|
|
@ -213,6 +225,9 @@ public class SmartCollectionSyncService : ISmartCollectionSyncService
|
|||
|
||||
await _unitOfWork.CollectionTagRepository.UpdateCollectionAgeRating(collection);
|
||||
|
||||
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
|
||||
MessageFactory.SmartCollectionProgressEvent(info.Title, string.Empty, info.TotalItems, info.TotalItems, ProgressEventType.Ended));
|
||||
|
||||
await _eventHub.SendMessageAsync(MessageFactory.CollectionUpdated,
|
||||
MessageFactory.CollectionUpdatedEvent(collection.Id), false);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,17 +33,19 @@ public class WordCountAnalyzerService : IWordCountAnalyzerService
|
|||
private readonly IEventHub _eventHub;
|
||||
private readonly ICacheHelper _cacheHelper;
|
||||
private readonly IReaderService _readerService;
|
||||
private readonly IMediaErrorService _mediaErrorService;
|
||||
|
||||
private const int AverageCharactersPerWord = 5;
|
||||
|
||||
public WordCountAnalyzerService(ILogger<WordCountAnalyzerService> logger, IUnitOfWork unitOfWork, IEventHub eventHub,
|
||||
ICacheHelper cacheHelper, IReaderService readerService)
|
||||
ICacheHelper cacheHelper, IReaderService readerService, IMediaErrorService mediaErrorService)
|
||||
{
|
||||
_logger = logger;
|
||||
_unitOfWork = unitOfWork;
|
||||
_eventHub = eventHub;
|
||||
_cacheHelper = cacheHelper;
|
||||
_readerService = readerService;
|
||||
_mediaErrorService = mediaErrorService;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -188,7 +190,7 @@ public class WordCountAnalyzerService : IWordCountAnalyzerService
|
|||
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
|
||||
MessageFactory.WordCountAnalyzerProgressEvent(series.LibraryId, progress,
|
||||
ProgressEventType.Updated, useFileName ? filePath : series.Name));
|
||||
sum += await GetWordCountFromHtml(bookPage);
|
||||
sum += await GetWordCountFromHtml(bookPage, filePath);
|
||||
pageCounter++;
|
||||
}
|
||||
|
||||
|
|
@ -245,13 +247,23 @@ public class WordCountAnalyzerService : IWordCountAnalyzerService
|
|||
}
|
||||
|
||||
|
||||
private static async Task<int> GetWordCountFromHtml(EpubLocalTextContentFileRef bookFile)
|
||||
private async Task<int> GetWordCountFromHtml(EpubLocalTextContentFileRef bookFile, string filePath)
|
||||
{
|
||||
var doc = new HtmlDocument();
|
||||
doc.LoadHtml(await bookFile.ReadContentAsync());
|
||||
try
|
||||
{
|
||||
var doc = new HtmlDocument();
|
||||
doc.LoadHtml(await bookFile.ReadContentAsync());
|
||||
|
||||
var textNodes = doc.DocumentNode.SelectNodes("//body//text()[not(parent::script)]");
|
||||
return textNodes?.Sum(node => node.InnerText.Count(char.IsLetter)) / AverageCharactersPerWord ?? 0;
|
||||
var textNodes = doc.DocumentNode.SelectNodes("//body//text()[not(parent::script)]");
|
||||
return textNodes?.Sum(node => node.InnerText.Count(char.IsLetter)) / AverageCharactersPerWord ?? 0;
|
||||
}
|
||||
catch (EpubContentException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error when counting words in epub {EpubPath}", filePath);
|
||||
await _mediaErrorService.ReportMediaIssueAsync(filePath, MediaErrorProducer.BookService,
|
||||
$"Invalid Epub Metadata, {bookFile.FilePath} does not exist", ex.Message);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ public class ThemeService : IThemeService
|
|||
themeDtos.Add(dto);
|
||||
}
|
||||
|
||||
_cache.Set(themeDtos, themes, _cacheOptions);
|
||||
_cache.Set(cacheKey, themeDtos, _cacheOptions);
|
||||
|
||||
return themeDtos;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue