mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-07-09 03:04:19 -04:00
Fixed issue where chapter based volumes wouldn't properly handle chapter divide when reading a manga.
This commit is contained in:
parent
731e3a9c5e
commit
c2b41b774a
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using API.Comparators;
|
using API.Comparators;
|
||||||
@ -13,17 +11,13 @@ namespace API.Controllers
|
|||||||
{
|
{
|
||||||
public class ReaderController : BaseApiController
|
public class ReaderController : BaseApiController
|
||||||
{
|
{
|
||||||
private readonly ISeriesRepository _seriesRepository;
|
|
||||||
private readonly IDirectoryService _directoryService;
|
private readonly IDirectoryService _directoryService;
|
||||||
private readonly ICacheService _cacheService;
|
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;
|
_directoryService = directoryService;
|
||||||
_cacheService = cacheService;
|
_cacheService = cacheService;
|
||||||
_numericComparer = new NumericComparer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("info")]
|
[HttpGet("info")]
|
||||||
@ -46,11 +40,7 @@ namespace API.Controllers
|
|||||||
// Temp let's iterate the directory each call to get next image
|
// Temp let's iterate the directory each call to get next image
|
||||||
var volume = await _cacheService.Ensure(volumeId);
|
var volume = await _cacheService.Ensure(volumeId);
|
||||||
|
|
||||||
var files = _directoryService.ListFiles(_cacheService.GetCachedPagePath(volume, page));
|
var path = _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 file = await _directoryService.ReadImageAsync(path);
|
var file = await _directoryService.ReadImageAsync(path);
|
||||||
file.Page = page;
|
file.Page = page;
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ namespace API.Entities
|
|||||||
public DateTime Created { get; set; }
|
public DateTime Created { get; set; }
|
||||||
public DateTime LastModified { get; set; }
|
public DateTime LastModified { get; set; }
|
||||||
public byte[] CoverImage { 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 string CachePath {get; set;} // Path where cache is located. Default null, resets to null on deletion.
|
||||||
//public ICollection<AppUserProgress> AppUserProgress { get; set; }
|
//public ICollection<AppUserProgress> AppUserProgress { get; set; }
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using API.Comparators;
|
||||||
using API.Entities;
|
using API.Entities;
|
||||||
using API.Extensions;
|
using API.Extensions;
|
||||||
using API.Interfaces;
|
using API.Interfaces;
|
||||||
@ -14,6 +15,7 @@ namespace API.Services
|
|||||||
private readonly IDirectoryService _directoryService;
|
private readonly IDirectoryService _directoryService;
|
||||||
private readonly ISeriesRepository _seriesRepository;
|
private readonly ISeriesRepository _seriesRepository;
|
||||||
private readonly ILogger<CacheService> _logger;
|
private readonly ILogger<CacheService> _logger;
|
||||||
|
private readonly NumericComparer _numericComparer;
|
||||||
private readonly string _cacheDirectory = Path.GetFullPath(Path.Join(Directory.GetCurrentDirectory(), "../cache/"));
|
private readonly string _cacheDirectory = Path.GetFullPath(Path.Join(Directory.GetCurrentDirectory(), "../cache/"));
|
||||||
|
|
||||||
public CacheService(IDirectoryService directoryService, ISeriesRepository seriesRepository, ILogger<CacheService> logger)
|
public CacheService(IDirectoryService directoryService, ISeriesRepository seriesRepository, ILogger<CacheService> logger)
|
||||||
@ -21,6 +23,7 @@ namespace API.Services
|
|||||||
_directoryService = directoryService;
|
_directoryService = directoryService;
|
||||||
_seriesRepository = seriesRepository;
|
_seriesRepository = seriesRepository;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_numericComparer = new NumericComparer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Volume> Ensure(int volumeId)
|
public async Task<Volume> Ensure(int volumeId)
|
||||||
@ -85,12 +88,21 @@ namespace API.Services
|
|||||||
public string GetCachedPagePath(Volume volume, int page)
|
public string GetCachedPagePath(Volume volume, int page)
|
||||||
{
|
{
|
||||||
// Calculate what chapter the page belongs to
|
// Calculate what chapter the page belongs to
|
||||||
|
var pagesSoFar = 0;
|
||||||
foreach (var mangaFile in volume.Files.OrderBy(f => f.Chapter))
|
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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -114,24 +114,17 @@ namespace API.Services
|
|||||||
|
|
||||||
private Series UpdateSeries(string seriesName, ParserInfo[] infos, bool forceUpdate)
|
private Series UpdateSeries(string seriesName, ParserInfo[] infos, bool forceUpdate)
|
||||||
{
|
{
|
||||||
var series = _seriesRepository.GetSeriesByName(seriesName);
|
var series = _seriesRepository.GetSeriesByName(seriesName) ?? new Series
|
||||||
|
|
||||||
if (series == null)
|
|
||||||
{
|
{
|
||||||
series = new Series
|
Name = seriesName,
|
||||||
{
|
OriginalName = seriesName,
|
||||||
Name = seriesName,
|
SortName = seriesName,
|
||||||
OriginalName = seriesName,
|
Summary = "" // TODO: Check if comicInfo.xml in file and parse metadata out.
|
||||||
SortName = seriesName,
|
};
|
||||||
Summary = "" // TODO: Check if comicInfo.xml in file and parse metadata out.
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
var volumes = UpdateVolumes(series, infos, forceUpdate);
|
var volumes = UpdateVolumes(series, infos, forceUpdate);
|
||||||
series.Volumes = volumes;
|
series.Volumes = volumes;
|
||||||
series.CoverImage = volumes.OrderBy(x => x.Number).FirstOrDefault()?.CoverImage;
|
series.CoverImage = volumes.OrderBy(x => x.Number).FirstOrDefault()?.CoverImage;
|
||||||
//GetFiles()
|
|
||||||
|
|
||||||
return series;
|
return series;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user