Cleaned up ReaderController to match the new method of loading images in FE. Sends the full files rather than base64 encoded string.

This commit is contained in:
Joseph Milazzo 2021-03-09 15:50:17 -06:00
parent c6e1fec9f2
commit 2a8931406d
5 changed files with 38 additions and 52 deletions

View file

@ -30,44 +30,34 @@ namespace API.Controllers
}
[HttpGet("image")]
public async Task<ActionResult<ImageDto>> GetImage(int chapterId, int page)
public async Task<ActionResult> GetImage(int chapterId, int page)
{
// Temp let's iterate the directory each call to get next image
var chapter = await _cacheService.Ensure(chapterId);
if (chapter == null) return BadRequest("There was an issue finding image file for reading");
var (path, mangaFile) = await _cacheService.GetCachedPagePath(chapter, page);
if (string.IsNullOrEmpty(path)) return BadRequest($"No such image for page {page}");
var file = await _directoryService.ReadImageAsync(path);
file.Page = page;
file.MangaFileName = mangaFile.FilePath;
file.NeedsSplitting = file.Width > file.Height;
// TODO: Validate if sending page whole (not base64 encoded) fixes Tablet issue
//Response.Headers.Add("Transfer-Encoding", "gzip");
if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path)) return BadRequest($"No such image for page {page}");
return Ok(file);
var content = await _directoryService.ReadFileAsync(path);
var format = Path.GetExtension(path).Replace(".", "");
// Look into HttpContext.Cache so we can utilize a memorystream for Zip entries (want to limit response time by 300ms)
// Calculates SHA1 Hash for byte[]
using var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
Response.Headers.Add("ETag", string.Concat(sha1.ComputeHash(content).Select(x => x.ToString("X2"))));
Response.Headers.Add("Cache-Control", "private");
return File(content, "image/" + format);
}
[HttpGet("image2")]
public async Task<ActionResult> GetImage2(int chapterId, int page)
{
// Temp let's iterate the directory each call to get next image
var chapter = await _cacheService.Ensure(chapterId);
[HttpGet("chapter-path")]
public async Task<ActionResult<string>> GetImagePath(int chapterId)
{
var chapter = await _cacheService.Ensure(chapterId);
if (chapter == null) return BadRequest("There was an issue finding image file for reading");
var (path, mangaFile) = await _cacheService.GetCachedPagePath(chapter, page);
if (string.IsNullOrEmpty(path)) return BadRequest($"No such image for page {page}");
var file = await _directoryService.ReadImageAsync(path);
file.Page = page;
file.MangaFileName = mangaFile.FilePath;
file.NeedsSplitting = file.Width > file.Height;
// TODO: Validate if sending page whole (not base64 encoded) fixes Tablet issue
return File(file.Content, "image/jpeg", mangaFile.FilePath);
var (path, mangaFile) = await _cacheService.GetCachedPagePath(chapter, 0);
return Ok(mangaFile.FilePath);
}
[HttpGet("get-bookmark")]