Skip to content

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.

Fixed issue where chapter based volumes wouldn't properly handle chapter divide when reading a manga.

Joseph Milazzoc2b41b774ad3
diff --git a/API/Controllers/ReaderController.cs b/API/Controllers/ReaderController.cs
index 299e5eea6..0e6cb9b4a 100644
--- a/API/Controllers/ReaderController.cs
+++ b/API/Controllers/ReaderController.cs
@@ -1,6 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using API.Comparators;
@@ -13,17 +11,13 @@ namespace API.Controllers
{
public class ReaderController : BaseApiController
{
- private readonly ISeriesRepository _seriesRepository;
private readonly IDirectoryService _directoryService;
private readonly ICacheService _cacheService;
- private readonly NumericComparer _numericComparer;
- public ReaderController(ISeriesRepository seriesRepository, IDirectoryService directoryService, ICacheService cacheService)
+ public ReaderController(IDirectoryService directoryService, ICacheService cacheService)
{
- _seriesRepository = seriesRepository;
_directoryService = directoryService;
_cacheService = cacheService;
- _numericComparer = new NumericComparer();
}
[HttpGet("info")]
@@ -46,11 +40,7 @@ namespace API.Controllers
// Temp let's iterate the directory each call to get next image
var volume = await _cacheService.Ensure(volumeId);
- var files = _directoryService.ListFiles(_cacheService.GetCachedPagePath(volume, page));
- //files.OrderBy(t => t, _numericComparer);
- var array = files.ToArray();
- Array.Sort(array, _numericComparer); // TODO: Find a way to apply numericComparer to IList.
- var path = array.ElementAt(page);
+ var path = _cacheService.GetCachedPagePath(volume, page);
var file = await _directoryService.ReadImageAsync(path);
file.Page = page;
diff --git a/API/Entities/Volume.cs b/API/Entities/Volume.cs
index cc5479c9e..dc0be5223 100644
--- a/API/Entities/Volume.cs
+++ b/API/Entities/Volume.cs
@@ -13,6 +13,7 @@ namespace API.Entities
public DateTime Created { get; set; }
public DateTime LastModified { get; set; }
public byte[] CoverImage { get; set; }
+ //public int Pages { get; set; }
// public string CachePath {get; set;} // Path where cache is located. Default null, resets to null on deletion.
//public ICollection<AppUserProgress> AppUserProgress { get; set; }
diff --git a/API/Services/CacheService.cs b/API/Services/CacheService.cs
index 9bffa16f3..848ebfc16 100644
--- a/API/Services/CacheService.cs
+++ b/API/Services/CacheService.cs
@@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
+using API.Comparators;
using API.Entities;
using API.Extensions;
using API.Interfaces;
@@ -14,6 +15,7 @@ namespace API.Services
private readonly IDirectoryService _directoryService;
private readonly ISeriesRepository _seriesRepository;
private readonly ILogger<CacheService> _logger;
+ private readonly NumericComparer _numericComparer;
private readonly string _cacheDirectory = Path.GetFullPath(Path.Join(Directory.GetCurrentDirectory(), "../cache/"));
public CacheService(IDirectoryService directoryService, ISeriesRepository seriesRepository, ILogger<CacheService> logger)
@@ -21,6 +23,7 @@ namespace API.Services
_directoryService = directoryService;
_seriesRepository = seriesRepository;
_logger = logger;
+ _numericComparer = new NumericComparer();
}
public async Task<Volume> Ensure(int volumeId)
@@ -85,12 +88,21 @@ namespace API.Services
public string GetCachedPagePath(Volume volume, int page)
{
// Calculate what chapter the page belongs to
+ var pagesSoFar = 0;
foreach (var mangaFile in volume.Files.OrderBy(f => f.Chapter))
{
- if (page + 1 < mangaFile.NumberOfPages)
+ if (page + 1 < (mangaFile.NumberOfPages + pagesSoFar))
{
- return GetVolumeCachePath(volume.Id, mangaFile);
+ var path = GetVolumeCachePath(volume.Id, mangaFile);
+
+ var files = _directoryService.ListFiles(path);
+ var array = files.ToArray();
+ Array.Sort(array, _numericComparer); // TODO: Find a way to apply numericComparer to IList.
+
+ return array.ElementAt((page + 1) - pagesSoFar);
}
+
+ pagesSoFar += mangaFile.NumberOfPages;
}
return "";
}
diff --git a/API/Services/DirectoryService.cs b/API/Services/DirectoryService.cs
index 554f241b8..5b70fafb1 100644
--- a/API/Services/DirectoryService.cs
+++ b/API/Services/DirectoryService.cs
@@ -114,24 +114,17 @@ namespace API.Services
private Series UpdateSeries(string seriesName, ParserInfo[] infos, bool forceUpdate)
{
- var series = _seriesRepository.GetSeriesByName(seriesName);
-
- if (series == null)
+ var series = _seriesRepository.GetSeriesByName(seriesName) ?? new Series
{
- series = new Series
- {
- Name = seriesName,
- OriginalName = seriesName,
- SortName = seriesName,
- Summary = "" // TODO: Check if comicInfo.xml in file and parse metadata out.
- };
- }
-
+ Name = seriesName,
+ OriginalName = seriesName,
+ SortName = seriesName,
+ Summary = "" // TODO: Check if comicInfo.xml in file and parse metadata out.
+ };
+
var volumes = UpdateVolumes(series, infos, forceUpdate);
series.Volumes = volumes;
series.CoverImage = volumes.OrderBy(x => x.Number).FirstOrDefault()?.CoverImage;
- //GetFiles()
-
return series;
}