mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
* Added the skeleton code for layout, hooked up Age Rating, Publication Status, and Tags * Tweaked message of Scan service to Finished scan of to better indicate the total scan time * Hooked in foundation for person typeaheads * Fixed people not populating typeaheads on load * For manga/comics, when parsing, set the SeriesSort from ComicInfo if it exists. * Implemented the ability to override and create new genre tags. Code is ready to flush out the rest. * Ability to update metadata from the UI is hooked up. Next is locking. * Updated typeahead to allow for non-multiple usage. Implemented ability to update Language tag in Series Metadata. * Fixed a bug in GetContinuePoint for a case where we have Volumes, Loose Leaf chapters and no read progress. * Added ETag headers on Images to allow for better caching (bookmarks and images in manga reader) * Built out UI code to show locked indication to user * Implemented Series locking and refactored a lot of styles in typeahead to make the lock setting work, plus misc cleanup. * Added locked properties to dtos. Updated typeahead loading indicator to not interfere with close button if present * Hooked up locking flags in UI * Integrated regular field locking/unlocking * Removed some old code * Prevent input group from wrapping * Implemented some basic layout for metadata on volume/chapter card modal. Refactored out all metadata from Chapter object in terms of UI and put into a separate call to ensure speedy delivery and simplicity of code. * Refactored code to hide covers section if not an admin * Implemented ability to modify a chapter/volume cover from the detail modal * Removed a few variables and change cover image modal * Added bookmark to single chapter view * Put a temp fix in for a ngb v12 z-index bug (reported). Bumped ngb to 12.0 stable and fixed some small rendering bugs * loading buttons ftw * Lots of cleanup, looks like the story is finished * Changed action name from Info to Details * Style tweaks * Fixed an issue where Summary would assume it's locked due to a subscription firing on setting the model * Fixed some misc bugs * Code smells Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
115 lines
5.2 KiB
C#
115 lines
5.2 KiB
C#
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using API.Data;
|
|
using API.Entities.Enums;
|
|
using API.Extensions;
|
|
using API.Services;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace API.Controllers
|
|
{
|
|
/// <summary>
|
|
/// Responsible for servicing up images stored in the DB
|
|
/// </summary>
|
|
public class ImageController : BaseApiController
|
|
{
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
private readonly IDirectoryService _directoryService;
|
|
|
|
/// <inheritdoc />
|
|
public ImageController(IUnitOfWork unitOfWork, IDirectoryService directoryService)
|
|
{
|
|
_unitOfWork = unitOfWork;
|
|
_directoryService = directoryService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns cover image for Chapter
|
|
/// </summary>
|
|
/// <param name="chapterId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("chapter-cover")]
|
|
public async Task<ActionResult> GetChapterCoverImage(int chapterId)
|
|
{
|
|
var path = Path.Join(_directoryService.CoverImageDirectory, await _unitOfWork.ChapterRepository.GetChapterCoverImageAsync(chapterId));
|
|
if (string.IsNullOrEmpty(path) || !_directoryService.FileSystem.File.Exists(path)) return BadRequest($"No cover image");
|
|
var format = _directoryService.FileSystem.Path.GetExtension(path).Replace(".", "");
|
|
|
|
Response.AddCacheHeader(path);
|
|
return PhysicalFile(path, "image/" + format, _directoryService.FileSystem.Path.GetFileName(path));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns cover image for Volume
|
|
/// </summary>
|
|
/// <param name="volumeId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("volume-cover")]
|
|
public async Task<ActionResult> GetVolumeCoverImage(int volumeId)
|
|
{
|
|
var path = Path.Join(_directoryService.CoverImageDirectory, await _unitOfWork.VolumeRepository.GetVolumeCoverImageAsync(volumeId));
|
|
if (string.IsNullOrEmpty(path) || !_directoryService.FileSystem.File.Exists(path)) return BadRequest($"No cover image");
|
|
var format = _directoryService.FileSystem.Path.GetExtension(path).Replace(".", "");
|
|
|
|
Response.AddCacheHeader(path);
|
|
return PhysicalFile(path, "image/" + format, _directoryService.FileSystem.Path.GetFileName(path));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns cover image for Series
|
|
/// </summary>
|
|
/// <param name="seriesId">Id of Series</param>
|
|
/// <returns></returns>
|
|
[HttpGet("series-cover")]
|
|
public async Task<ActionResult> GetSeriesCoverImage(int seriesId)
|
|
{
|
|
var path = Path.Join(_directoryService.CoverImageDirectory, await _unitOfWork.SeriesRepository.GetSeriesCoverImageAsync(seriesId));
|
|
if (string.IsNullOrEmpty(path) || !_directoryService.FileSystem.File.Exists(path)) return BadRequest($"No cover image");
|
|
var format = _directoryService.FileSystem.Path.GetExtension(path).Replace(".", "");
|
|
|
|
Response.AddCacheHeader(path);
|
|
return PhysicalFile(path, "image/" + format, _directoryService.FileSystem.Path.GetFileName(path));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns cover image for Collection Tag
|
|
/// </summary>
|
|
/// <param name="collectionTagId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("collection-cover")]
|
|
public async Task<ActionResult> GetCollectionCoverImage(int collectionTagId)
|
|
{
|
|
var path = Path.Join(_directoryService.CoverImageDirectory, await _unitOfWork.CollectionTagRepository.GetCoverImageAsync(collectionTagId));
|
|
if (string.IsNullOrEmpty(path) || !_directoryService.FileSystem.File.Exists(path)) return BadRequest($"No cover image");
|
|
var format = _directoryService.FileSystem.Path.GetExtension(path).Replace(".", "");
|
|
|
|
Response.AddCacheHeader(path);
|
|
return PhysicalFile(path, "image/" + format, _directoryService.FileSystem.Path.GetFileName(path));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns image for a given bookmark page
|
|
/// </summary>
|
|
/// <remarks>This request is served unauthenticated, but user must be passed via api key to validate</remarks>
|
|
/// <param name="chapterId"></param>
|
|
/// <param name="pageNum">Starts at 0</param>
|
|
/// <param name="apiKey">API Key for user. Needed to authenticate request</param>
|
|
/// <returns></returns>
|
|
[HttpGet("bookmark")]
|
|
public async Task<ActionResult> GetBookmarkImage(int chapterId, int pageNum, string apiKey)
|
|
{
|
|
var userId = await _unitOfWork.UserRepository.GetUserIdByApiKeyAsync(apiKey);
|
|
var bookmark = await _unitOfWork.UserRepository.GetBookmarkForPage(pageNum, chapterId, userId);
|
|
if (bookmark == null) return BadRequest("Bookmark does not exist");
|
|
|
|
var bookmarkDirectory =
|
|
(await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.BookmarkDirectory)).Value;
|
|
var file = new FileInfo(Path.Join(bookmarkDirectory, bookmark.FileName));
|
|
var format = Path.GetExtension(file.FullName).Replace(".", "");
|
|
|
|
Response.AddCacheHeader(file.FullName);
|
|
return PhysicalFile(file.FullName, "image/" + format, Path.GetFileName(file.FullName));
|
|
}
|
|
}
|
|
}
|