Added a basic cache service to handle interations with the underlying cache implementation. Refactored some code to be more robust.
This commit is contained in:
parent
59a4921ba9
commit
cd8a1d2892
8 changed files with 149 additions and 34 deletions
|
@ -11,16 +11,19 @@ namespace API.Controllers
|
|||
{
|
||||
private readonly ISeriesRepository _seriesRepository;
|
||||
private readonly IDirectoryService _directoryService;
|
||||
private readonly ICacheService _cacheService;
|
||||
|
||||
public ReaderController(ISeriesRepository seriesRepository, IDirectoryService directoryService)
|
||||
public ReaderController(ISeriesRepository seriesRepository, IDirectoryService directoryService, ICacheService cacheService)
|
||||
{
|
||||
_seriesRepository = seriesRepository;
|
||||
_directoryService = directoryService;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
|
||||
[HttpGet("info")]
|
||||
public async Task<ActionResult<int>> GetInformation(int volumeId)
|
||||
{
|
||||
// TODO: This will be refactored out. No longer needed.
|
||||
Volume volume = await _seriesRepository.GetVolumeAsync(volumeId);
|
||||
|
||||
// Assume we always get first Manga File
|
||||
|
@ -28,24 +31,21 @@ namespace API.Controllers
|
|||
{
|
||||
return BadRequest("There are no files in the volume to read.");
|
||||
}
|
||||
|
||||
_cacheService.Ensure(volumeId);
|
||||
|
||||
var filepath = volume.Files.ElementAt(0).FilePath;
|
||||
return Ok(volume.Files.Select(x => x.NumberOfPages).Sum());
|
||||
|
||||
var extractPath = _directoryService.ExtractArchive(filepath, volumeId);
|
||||
if (string.IsNullOrEmpty(extractPath))
|
||||
{
|
||||
return BadRequest("There file is no longer there or has no images. Please rescan.");
|
||||
}
|
||||
|
||||
// NOTE: I'm starting to think this should actually cache the information about Volume/Manga file in the DB.
|
||||
// It will be updated each time this is called which is on open of a manga.
|
||||
return Ok(_directoryService.ListFiles(extractPath).Count());
|
||||
}
|
||||
|
||||
[HttpGet("image")]
|
||||
public async Task<ActionResult<ImageDto>> GetImage(int volumeId, int page)
|
||||
{
|
||||
// Temp let's iterate the directory each call to get next image
|
||||
_cacheService.Ensure(volumeId);
|
||||
|
||||
|
||||
|
||||
var files = _directoryService.ListFiles(_directoryService.GetExtractPath(volumeId));
|
||||
var path = files.ElementAt(page);
|
||||
var file = await _directoryService.ReadImageAsync(path);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue