diff --git a/API.Tests/ParserTest.cs b/API.Tests/ParserTest.cs index 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.cs deleted file mode 100644 index 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 file diff --git a/API/Comparators/StringLogicalComparer.cs b/API/Comparators/StringLogicalComparer.cs index f6a8c1249..fe930c45c 100644 --- a/API/Comparators/StringLogicalComparer.cs +++ b/API/Comparators/StringLogicalComparer.cs @@ -20,16 +20,16 @@ namespace API.Comparators if (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 index while(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 result if(!c1 && !c2) { diff --git a/API/Controllers/SeriesController.cs b/API/Controllers/SeriesController.cs index fcd945c7c..4649a2ece 100644 --- a/API/Controllers/SeriesController.cs +++ b/API/Controllers/SeriesController.cs @@ -61,6 +61,13 @@ namespace API.Controllers return Ok(await _unitOfWork.SeriesRepository.GetVolumeDtoAsync(volumeId, user.Id)); } + // [HttpGet("volume-files")] + // public async Task>> 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.cs new file mode 100644 index 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 file diff --git a/API/DTOs/VolumeDto.cs b/API/DTOs/VolumeDto.cs index 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.DTOs public byte[] CoverImage { get; set; } public int Pages { get; set; } public int PagesRead { get; set; } + public ICollection Files { get; set; } } } \ No newline at end of file diff --git a/API/Helpers/AutoMapperProfiles.cs b/API/Helpers/AutoMapperProfiles.cs index b874d9949..8db743695 100644 --- a/API/Helpers/AutoMapperProfiles.cs +++ b/API/Helpers/AutoMapperProfiles.cs @@ -15,6 +15,8 @@ namespace API.Helpers CreateMap(); + CreateMap(); + CreateMap(); CreateMap() diff --git a/API/Interfaces/ISeriesRepository.cs b/API/Interfaces/ISeriesRepository.cs index db758b2e5..fedf5c10e 100644 --- a/API/Interfaces/ISeriesRepository.cs +++ b/API/Interfaces/ISeriesRepository.cs @@ -25,5 +25,6 @@ namespace API.Interfaces Task GetVolumeByIdAsync(int volumeId); Task GetSeriesByIdAsync(int seriesId); + //Task GetVolumeMangaFileDtos(int volumeId); } } \ No newline at end of file diff --git a/API/Services/CacheService.cs b/API/Services/CacheService.cs index 0567329ef..778310124 100644 --- a/API/Services/CacheService.cs +++ b/API/Services/CacheService.cs @@ -105,28 +105,29 @@ namespace API.Services if (!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 extract var 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.cs index 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)); } ///