using System.Threading.Tasks; using Kavita.API.Database; using Kavita.Models.DTOs.Theme; using Kavita.Models.Entities.Interfaces; using Kavita.Server.Attributes; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Kavita.Server.Controllers; [Authorize] public class ColorScapeController(IUnitOfWork unitOfWork) : BaseApiController { /// /// Returns the color scape for a series /// /// /// [SeriesAccess] [HttpGet("series")] public async Task> GetColorScapeForSeries(int id) { var entity = await unitOfWork.SeriesRepository.GetSeriesDtoByIdAsync(id, UserId); return GetColorSpaceDto(entity); } /// /// Returns the color scape for a volume /// /// /// [VolumeAccess] [HttpGet("volume")] public async Task> GetColorScapeForVolume(int id) { var entity = await unitOfWork.VolumeRepository.GetVolumeDtoAsync(id, UserId); return GetColorSpaceDto(entity); } /// /// Returns the color scape for a chapter /// /// /// [ChapterAccess] [HttpGet("chapter")] public async Task> GetColorScapeForChapter(int id) { var entity = await unitOfWork.ChapterRepository.GetChapterDtoAsync(id, UserId); return GetColorSpaceDto(entity); } private ActionResult GetColorSpaceDto(IHasCoverImage? entity) { if (entity == null) return Ok(ColorScapeDto.Empty); return Ok(new ColorScapeDto(entity.PrimaryColor, entity.SecondaryColor)); } }