Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
C# annotationscbzcomicinfocomicscomics-readercross-platformcsharpepubepub-readerfreelinuxmangamedia-servermetadataopdsopds-feedpdfself-hostedubooquitywindows
Fixed some errors being thrown when not needed on Cache.Ensure(). Added ability to send actual mangafile information on the volume() api so we can display to the user.
Joseph Milazzo07fd959b227c
diff --git a/API.Tests/ParserTest.cs b/API.Tests/ParserTest.csindex 55257853c..38d512077 100644--- a/API.Tests/ParserTest.cs+++ b/API.Tests/ParserTest.cs@@ -33,6 +33,9 @@ namespace API.Tests[InlineData("Dorohedoro v01 (2010) (Digital) (LostNerevarine-Empire).cbz", "1")][InlineData("Dorohedoro v11 (2013) (Digital) (LostNerevarine-Empire).cbz", "11")][InlineData("Dorohedoro v12 (2013) (Digital) (LostNerevarine-Empire).cbz", "12")]+ [InlineData("Yumekui_Merry_v01_c01[Bakayarou-Kuu].rar", "1")]+ [InlineData("Yumekui-Merry_DKThias_Chapter11v2.zip", "0")]+public void ParseVolumeTest(string filename, string expected){Assert.Equal(expected, ParseVolume(filename));@@ -75,6 +78,7 @@ namespace API.Tests[InlineData("Chrno_Crusade_Dragon_Age_All_Stars[AS].zip", "")][InlineData("Ichiban_Ushiro_no_Daimaou_v04_ch34_[VISCANS].zip", "Ichiban Ushiro no Daimaou")][InlineData("Rent a Girlfriend v01.cbr", "Rent a Girlfriend")]+ [InlineData("Yumekui_Merry_v01_c01[Bakayarou-Kuu].rar", "Yumekui Merry")]//[InlineData("[Tempus Edax Rerum] Epigraph of the Closed Curve - Chapter 6.zip", "Epigraph of the Closed Curve")]public void ParseSeriesTest(string filename, string expected){@@ -103,6 +107,8 @@ namespace API.Tests[InlineData("Mujaki no Rakuen Vol12 ch76", "76")][InlineData("Beelzebub_01_[Noodles].zip", "1")][InlineData("Yumekui-Merry_DKThias_Chapter21.zip", "21")]+ [InlineData("Yumekui_Merry_v01_c01[Bakayarou-Kuu].rar", "1")]+ [InlineData("Yumekui-Merry_DKThias_Chapter11v2.zip", "11")]//[InlineData("[Tempus Edax Rerum] Epigraph of the Closed Curve - Chapter 6.zip", "6")]public void ParseChaptersTest(string filename, string expected){diff --git a/API.Tests/Services/ImageProviderTest.cs b/API.Tests/Services/ImageProviderTest.csdeleted file mode 100644index 485dc0a5e..000000000--- a/API.Tests/Services/ImageProviderTest.cs+++ /dev/null@@ -1,11 +0,0 @@-using System.IO;-using Xunit;--namespace API.Tests.Services-{-- public class ImageProviderTest- {-- }-}\ No newline at end of filediff --git a/API/Comparators/StringLogicalComparer.cs b/API/Comparators/StringLogicalComparer.csindex f6a8c1249..fe930c45c 100644--- a/API/Comparators/StringLogicalComparer.cs+++ b/API/Comparators/StringLogicalComparer.cs@@ -20,16 +20,16 @@ namespace API.Comparatorsif (string.IsNullOrEmpty(s2)) return -1;//WE style, special case- bool sp1 = Char.IsLetterOrDigit(s1, 0);- bool sp2 = Char.IsLetterOrDigit(s2, 0);+ var sp1 = Char.IsLetterOrDigit(s1, 0);+ var sp2 = Char.IsLetterOrDigit(s2, 0);if(sp1 && !sp2) return 1;if(!sp1 && sp2) return -1;int i1 = 0, i2 = 0; //current indexwhile(true){- bool c1 = Char.IsDigit(s1, i1);- bool c2 = Char.IsDigit(s2, i2);+ var c1 = Char.IsDigit(s1, i1);+ var c2 = Char.IsDigit(s2, i2);int r; // temp resultif(!c1 && !c2){diff --git a/API/Controllers/SeriesController.cs b/API/Controllers/SeriesController.csindex fcd945c7c..4649a2ece 100644--- a/API/Controllers/SeriesController.cs+++ b/API/Controllers/SeriesController.cs@@ -61,6 +61,13 @@ namespace API.Controllersreturn Ok(await _unitOfWork.SeriesRepository.GetVolumeDtoAsync(volumeId, user.Id));}+ // [HttpGet("volume-files")]+ // public async Task<ActionResult<IEnumerable<MangaFileDto>>> GetMangaFiles(int volumeId)+ // {+ // var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());+ // return Ok(await _unitOfWork.SeriesRepository.GetVolumeMangaFileDtos(volumeId));+ // }+[Authorize(Policy = "RequireAdminRole")][HttpPost("scan")]public ActionResult Scan(int libraryId, int seriesId)diff --git a/API/DTOs/MangaFileDto.cs b/API/DTOs/MangaFileDto.csnew file mode 100644index 000000000..8d6535aa6--- /dev/null+++ b/API/DTOs/MangaFileDto.cs@@ -0,0 +1,13 @@+using API.Entities;++namespace API.DTOs+{+ public class MangaFileDto+ {+ public string FilePath { get; set; }+ public int Chapter { get; set; }+ public int NumberOfPages { get; set; }+ public MangaFormat Format { get; set; }++ }+}\ No newline at end of filediff --git a/API/DTOs/VolumeDto.cs b/API/DTOs/VolumeDto.csindex a57465857..22266e710 100644--- a/API/DTOs/VolumeDto.cs+++ b/API/DTOs/VolumeDto.cs@@ -1,4 +1,6 @@+using System.Collections.Generic;+namespace API.DTOs{public class VolumeDto@@ -9,5 +11,6 @@ namespace API.DTOspublic byte[] CoverImage { get; set; }public int Pages { get; set; }public int PagesRead { get; set; }+ public ICollection<MangaFileDto> Files { get; set; }}}\ No newline at end of filediff --git a/API/Helpers/AutoMapperProfiles.cs b/API/Helpers/AutoMapperProfiles.csindex b874d9949..8db743695 100644--- a/API/Helpers/AutoMapperProfiles.cs+++ b/API/Helpers/AutoMapperProfiles.cs@@ -15,6 +15,8 @@ namespace API.HelpersCreateMap<Volume, VolumeDto>();+ CreateMap<MangaFile, MangaFileDto>();+CreateMap<Series, SeriesDto>();CreateMap<Library, LibraryDto>()diff --git a/API/Interfaces/ISeriesRepository.cs b/API/Interfaces/ISeriesRepository.csindex db758b2e5..fedf5c10e 100644--- a/API/Interfaces/ISeriesRepository.cs+++ b/API/Interfaces/ISeriesRepository.cs@@ -25,5 +25,6 @@ namespace API.InterfacesTask<Volume> GetVolumeByIdAsync(int volumeId);Task<Series> GetSeriesByIdAsync(int seriesId);+ //Task<MangaFileDto> GetVolumeMangaFileDtos(int volumeId);}}\ No newline at end of filediff --git a/API/Services/CacheService.cs b/API/Services/CacheService.csindex 0567329ef..778310124 100644--- a/API/Services/CacheService.cs+++ b/API/Services/CacheService.cs@@ -105,28 +105,29 @@ namespace API.Servicesif (!File.Exists(archivePath) || !Parser.Parser.IsArchive(archivePath)){_logger.LogError($"Archive {archivePath} could not be found.");+ return;}if (Directory.Exists(extractPath)){_logger.LogDebug($"Archive {archivePath} has already been extracted. Returning existing folder.");+ return;}Stopwatch sw = Stopwatch.StartNew();using ZipArchive archive = ZipFile.OpenRead(archivePath);- // TODO: Throw error if we couldn't extractvar needsFlattening = archive.Entries.Count > 0 && !Path.HasExtension(archive.Entries.ElementAt(0).FullName);if (!archive.HasFiles() && !needsFlattening) return;archive.ExtractToDirectory(extractPath);- _logger.LogDebug($"[OLD] Extracted archive to {extractPath} in {sw.ElapsedMilliseconds} milliseconds.");+ _logger.LogDebug($"Extracted archive to {extractPath} in {sw.ElapsedMilliseconds} milliseconds.");if (needsFlattening){sw = Stopwatch.StartNew();_logger.LogInformation("Extracted archive is nested in root folder, flattening...");new DirectoryInfo(extractPath).Flatten();- _logger.LogInformation($"[OLD] Flattened in {sw.ElapsedMilliseconds} milliseconds");+ _logger.LogInformation($"Flattened in {sw.ElapsedMilliseconds} milliseconds");}}diff --git a/API/Services/ScannerService.cs b/API/Services/ScannerService.csindex 646640fcf..b697d5880 100644--- a/API/Services/ScannerService.cs+++ b/API/Services/ScannerService.cs@@ -324,9 +324,19 @@ namespace API.Services}_logger.LogDebug($"Getting Page numbers from {archivePath}");++ try+ {+ using ZipArchive archive = ZipFile.OpenRead(archivePath); // ZIPFILE+ return archive.Entries.Count(e => Parser.Parser.IsImage(e.FullName));+ }+ catch (Exception ex)+ {+ _logger.LogError(ex, "There was an exception when reading archive stream.");+ return 0;+ }+- using ZipArchive archive = ZipFile.OpenRead(archivePath); // ZIPFILE- return archive.Entries.Count(e => Parser.Parser.IsImage(e.FullName));}/// <summary>