mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-01 04:34:49 -04:00
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.
This commit is contained in:
parent
c57b77f092
commit
07fd959b22
@ -33,6 +33,9 @@ namespace API.Tests
|
|||||||
[InlineData("Dorohedoro v01 (2010) (Digital) (LostNerevarine-Empire).cbz", "1")]
|
[InlineData("Dorohedoro v01 (2010) (Digital) (LostNerevarine-Empire).cbz", "1")]
|
||||||
[InlineData("Dorohedoro v11 (2013) (Digital) (LostNerevarine-Empire).cbz", "11")]
|
[InlineData("Dorohedoro v11 (2013) (Digital) (LostNerevarine-Empire).cbz", "11")]
|
||||||
[InlineData("Dorohedoro v12 (2013) (Digital) (LostNerevarine-Empire).cbz", "12")]
|
[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)
|
public void ParseVolumeTest(string filename, string expected)
|
||||||
{
|
{
|
||||||
Assert.Equal(expected, ParseVolume(filename));
|
Assert.Equal(expected, ParseVolume(filename));
|
||||||
@ -75,6 +78,7 @@ namespace API.Tests
|
|||||||
[InlineData("Chrno_Crusade_Dragon_Age_All_Stars[AS].zip", "")]
|
[InlineData("Chrno_Crusade_Dragon_Age_All_Stars[AS].zip", "")]
|
||||||
[InlineData("Ichiban_Ushiro_no_Daimaou_v04_ch34_[VISCANS].zip", "Ichiban Ushiro no Daimaou")]
|
[InlineData("Ichiban_Ushiro_no_Daimaou_v04_ch34_[VISCANS].zip", "Ichiban Ushiro no Daimaou")]
|
||||||
[InlineData("Rent a Girlfriend v01.cbr", "Rent a Girlfriend")]
|
[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")]
|
//[InlineData("[Tempus Edax Rerum] Epigraph of the Closed Curve - Chapter 6.zip", "Epigraph of the Closed Curve")]
|
||||||
public void ParseSeriesTest(string filename, string expected)
|
public void ParseSeriesTest(string filename, string expected)
|
||||||
{
|
{
|
||||||
@ -103,6 +107,8 @@ namespace API.Tests
|
|||||||
[InlineData("Mujaki no Rakuen Vol12 ch76", "76")]
|
[InlineData("Mujaki no Rakuen Vol12 ch76", "76")]
|
||||||
[InlineData("Beelzebub_01_[Noodles].zip", "1")]
|
[InlineData("Beelzebub_01_[Noodles].zip", "1")]
|
||||||
[InlineData("Yumekui-Merry_DKThias_Chapter21.zip", "21")]
|
[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")]
|
//[InlineData("[Tempus Edax Rerum] Epigraph of the Closed Curve - Chapter 6.zip", "6")]
|
||||||
public void ParseChaptersTest(string filename, string expected)
|
public void ParseChaptersTest(string filename, string expected)
|
||||||
{
|
{
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
using System.IO;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace API.Tests.Services
|
|
||||||
{
|
|
||||||
|
|
||||||
public class ImageProviderTest
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,16 +20,16 @@ namespace API.Comparators
|
|||||||
if (string.IsNullOrEmpty(s2)) return -1;
|
if (string.IsNullOrEmpty(s2)) return -1;
|
||||||
|
|
||||||
//WE style, special case
|
//WE style, special case
|
||||||
bool sp1 = Char.IsLetterOrDigit(s1, 0);
|
var sp1 = Char.IsLetterOrDigit(s1, 0);
|
||||||
bool sp2 = Char.IsLetterOrDigit(s2, 0);
|
var sp2 = Char.IsLetterOrDigit(s2, 0);
|
||||||
if(sp1 && !sp2) return 1;
|
if(sp1 && !sp2) return 1;
|
||||||
if(!sp1 && sp2) return -1;
|
if(!sp1 && sp2) return -1;
|
||||||
|
|
||||||
int i1 = 0, i2 = 0; //current index
|
int i1 = 0, i2 = 0; //current index
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
bool c1 = Char.IsDigit(s1, i1);
|
var c1 = Char.IsDigit(s1, i1);
|
||||||
bool c2 = Char.IsDigit(s2, i2);
|
var c2 = Char.IsDigit(s2, i2);
|
||||||
int r; // temp result
|
int r; // temp result
|
||||||
if(!c1 && !c2)
|
if(!c1 && !c2)
|
||||||
{
|
{
|
||||||
|
@ -61,6 +61,13 @@ namespace API.Controllers
|
|||||||
return Ok(await _unitOfWork.SeriesRepository.GetVolumeDtoAsync(volumeId, user.Id));
|
return 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")]
|
[Authorize(Policy = "RequireAdminRole")]
|
||||||
[HttpPost("scan")]
|
[HttpPost("scan")]
|
||||||
public ActionResult Scan(int libraryId, int seriesId)
|
public ActionResult Scan(int libraryId, int seriesId)
|
||||||
|
13
API/DTOs/MangaFileDto.cs
Normal file
13
API/DTOs/MangaFileDto.cs
Normal file
@ -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; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace API.DTOs
|
namespace API.DTOs
|
||||||
{
|
{
|
||||||
public class VolumeDto
|
public class VolumeDto
|
||||||
@ -9,5 +11,6 @@ namespace API.DTOs
|
|||||||
public byte[] CoverImage { get; set; }
|
public byte[] CoverImage { get; set; }
|
||||||
public int Pages { get; set; }
|
public int Pages { get; set; }
|
||||||
public int PagesRead { get; set; }
|
public int PagesRead { get; set; }
|
||||||
|
public ICollection<MangaFileDto> Files { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,6 +15,8 @@ namespace API.Helpers
|
|||||||
|
|
||||||
CreateMap<Volume, VolumeDto>();
|
CreateMap<Volume, VolumeDto>();
|
||||||
|
|
||||||
|
CreateMap<MangaFile, MangaFileDto>();
|
||||||
|
|
||||||
CreateMap<Series, SeriesDto>();
|
CreateMap<Series, SeriesDto>();
|
||||||
|
|
||||||
CreateMap<Library, LibraryDto>()
|
CreateMap<Library, LibraryDto>()
|
||||||
|
@ -25,5 +25,6 @@ namespace API.Interfaces
|
|||||||
Task<Volume> GetVolumeByIdAsync(int volumeId);
|
Task<Volume> GetVolumeByIdAsync(int volumeId);
|
||||||
Task<Series> GetSeriesByIdAsync(int seriesId);
|
Task<Series> GetSeriesByIdAsync(int seriesId);
|
||||||
|
|
||||||
|
//Task<MangaFileDto> GetVolumeMangaFileDtos(int volumeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -105,28 +105,29 @@ namespace API.Services
|
|||||||
if (!File.Exists(archivePath) || !Parser.Parser.IsArchive(archivePath))
|
if (!File.Exists(archivePath) || !Parser.Parser.IsArchive(archivePath))
|
||||||
{
|
{
|
||||||
_logger.LogError($"Archive {archivePath} could not be found.");
|
_logger.LogError($"Archive {archivePath} could not be found.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Directory.Exists(extractPath))
|
if (Directory.Exists(extractPath))
|
||||||
{
|
{
|
||||||
_logger.LogDebug($"Archive {archivePath} has already been extracted. Returning existing folder.");
|
_logger.LogDebug($"Archive {archivePath} has already been extracted. Returning existing folder.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Stopwatch sw = Stopwatch.StartNew();
|
Stopwatch sw = Stopwatch.StartNew();
|
||||||
using ZipArchive archive = ZipFile.OpenRead(archivePath);
|
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);
|
var needsFlattening = archive.Entries.Count > 0 && !Path.HasExtension(archive.Entries.ElementAt(0).FullName);
|
||||||
if (!archive.HasFiles() && !needsFlattening) return;
|
if (!archive.HasFiles() && !needsFlattening) return;
|
||||||
|
|
||||||
archive.ExtractToDirectory(extractPath);
|
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)
|
if (needsFlattening)
|
||||||
{
|
{
|
||||||
sw = Stopwatch.StartNew();
|
sw = Stopwatch.StartNew();
|
||||||
_logger.LogInformation("Extracted archive is nested in root folder, flattening...");
|
_logger.LogInformation("Extracted archive is nested in root folder, flattening...");
|
||||||
new DirectoryInfo(extractPath).Flatten();
|
new DirectoryInfo(extractPath).Flatten();
|
||||||
_logger.LogInformation($"[OLD] Flattened in {sw.ElapsedMilliseconds} milliseconds");
|
_logger.LogInformation($"Flattened in {sw.ElapsedMilliseconds} milliseconds");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,9 +324,19 @@ namespace API.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogDebug($"Getting Page numbers from {archivePath}");
|
_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>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user