mirror of
				https://github.com/Kareadita/Kavita.git
				synced 2025-11-04 03:27:05 -05:00 
			
		
		
		
	* Started designing the backend localization service * Worked in Transloco for initial PoC * Worked in Transloco for initial PoC * Translated the login screen * translated dashboard screen * Started work on the backend * Fixed a logic bug * translated edit-user screen * Hooked up the backend for having a locale property. * Hooked up the ability to view the available locales and switch to them. * Made the localization service languages be derived from what's in langs/ directory. * Fixed up localization switching * Switched when we check for a license on UI bootstrap * Tweaked some code * Fixed the bug where dashboard wasn't loading and made it so language switching is working. * Fixed a bug on dashboard with languagePath * Converted user-scrobble-history.component.html * Converted spoiler.component.html * Converted review-series-modal.component.html * Converted review-card-modal.component.html * Updated the readme * Translated using Weblate (English) Currently translated at 100.0% (54 of 54 strings) Translation: Kavita/ui Translate-URL: https://hosted.weblate.org/projects/kavita/ui/en/ * Converted review-card.component.html * Deleted dead component * Converted want-to-read.component.html * Added translation using Weblate (Korean) * Translated using Weblate (Spanish) Currently translated at 40.7% (22 of 54 strings) Translation: Kavita/ui Translate-URL: https://hosted.weblate.org/projects/kavita/ui/es/ * Translated using Weblate (Korean) Currently translated at 62.9% (34 of 54 strings) Translation: Kavita/ui Translate-URL: https://hosted.weblate.org/projects/kavita/ui/ko/ * Converted user-preferences.component.html * Translated using Weblate (Korean) Currently translated at 92.5% (50 of 54 strings) Translation: Kavita/ui Translate-URL: https://hosted.weblate.org/projects/kavita/ui/ko/ * Converted user-holds.component.html * Converted theme-manager.component.html * Converted restriction-selector.component.html * Converted manage-devices.component.html * Converted edit-device.component.html * Converted change-password.component.html * Converted change-email.component.html * Converted change-age-restriction.component.html * Converted api-key.component.html * Converted anilist-key.component.html * Converted typeahead.component.html * Converted user-stats-info-cards.component.html * Converted user-stats.component.html * Converted top-readers.component.html * Converted some pipes and ensure translation is loaded before the app. * Finished all but one pipe for localization * Converted directory-picker.component.html * Converted library-access-modal.component.html * Converted a few components * Converted a few components * Converted a few components * Converted a few components * Converted a few components * Merged weblate in * ... -> … update * Updated the readme * Updateded all fonts to be woff2 * Cleaned up some strings to increase re-use * Removed an old flow (that doesn't exist in backend any longer) from when we introduced emails on Kavita. * Converted Series detail * Lots more converted * Lots more converted & hooked up the ability to flatten during prod build the language files. * Lots more converted * Lots more converted & fixed a bunch of broken pipes due to inject() * Lots more converted * Lots more converted * Lots more converted & fixed some bad keys * Lots more converted * Fixed some bugs with admin dasbhoard nested tabs not rendering on first load due to not using onpush change detection * Fixed up some localization errors and fixed forgot password error when the user doesn't have change password permission * Fixed a stupid build issue again * Started adding errors for interceptor and backend. * Finished off manga-reader * More translations * Few fixes * Fixed a bug where character tag badges weren't showing the name on chapter info * All components are translated * All toasts are translated * All confirm/alerts are translated * Trying something new for the backend * Migrated the localization strings for the backend into a new file. * Updated the localization service to be able to do backend localization with fallback to english. * Cleaned up some external reviews code to reduce looping * Localized AccountController.cs * 60% done with controllers * All controllers are done * All KavitaExceptions are covered * Some shakeout fixes * Prep for initial merge * Everything is done except options and basic shakeout proves response times are good. Unit tests are broken. * Fixed up the unit tests * All unit tests are now working * Removed some quantifier * I'm not sure I can support localization for some Volume/Chapter/Book strings within the codebase. --------- Co-authored-by: Robbie Davis <robbie@therobbiedavis.com> Co-authored-by: majora2007 <kavitareader@gmail.com> Co-authored-by: expertjun <jtrobin@naver.com> Co-authored-by: ThePromidius <thepromidiusyt@gmail.com>
		
			
				
	
	
		
			506 lines
		
	
	
		
			20 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			506 lines
		
	
	
		
			20 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System.Collections.Generic;
 | 
						|
using System.Linq;
 | 
						|
using System.Threading.Tasks;
 | 
						|
using API.Constants;
 | 
						|
using API.Data;
 | 
						|
using API.Data.Repositories;
 | 
						|
using API.DTOs;
 | 
						|
using API.DTOs.Filtering;
 | 
						|
using API.DTOs.Metadata;
 | 
						|
using API.DTOs.SeriesDetail;
 | 
						|
using API.Entities;
 | 
						|
using API.Entities.Enums;
 | 
						|
using API.Extensions;
 | 
						|
using API.Helpers;
 | 
						|
using API.Services;
 | 
						|
using API.Services.Plus;
 | 
						|
using EasyCaching.Core;
 | 
						|
using Kavita.Common;
 | 
						|
using Kavita.Common.Extensions;
 | 
						|
using Microsoft.AspNetCore.Authorization;
 | 
						|
using Microsoft.AspNetCore.Http.HttpResults;
 | 
						|
using Microsoft.AspNetCore.Mvc;
 | 
						|
using Microsoft.Extensions.Logging;
 | 
						|
 | 
						|
namespace API.Controllers;
 | 
						|
 | 
						|
public class SeriesController : BaseApiController
 | 
						|
{
 | 
						|
    private readonly ILogger<SeriesController> _logger;
 | 
						|
    private readonly ITaskScheduler _taskScheduler;
 | 
						|
    private readonly IUnitOfWork _unitOfWork;
 | 
						|
    private readonly ISeriesService _seriesService;
 | 
						|
    private readonly ILicenseService _licenseService;
 | 
						|
    private readonly ILocalizationService _localizationService;
 | 
						|
    private readonly IEasyCachingProvider _ratingCacheProvider;
 | 
						|
    private readonly IEasyCachingProvider _reviewCacheProvider;
 | 
						|
    private readonly IEasyCachingProvider _recommendationCacheProvider;
 | 
						|
 | 
						|
 | 
						|
    public SeriesController(ILogger<SeriesController> logger, ITaskScheduler taskScheduler, IUnitOfWork unitOfWork,
 | 
						|
        ISeriesService seriesService, ILicenseService licenseService,
 | 
						|
        IEasyCachingProviderFactory cachingProviderFactory, ILocalizationService localizationService)
 | 
						|
    {
 | 
						|
        _logger = logger;
 | 
						|
        _taskScheduler = taskScheduler;
 | 
						|
        _unitOfWork = unitOfWork;
 | 
						|
        _seriesService = seriesService;
 | 
						|
        _licenseService = licenseService;
 | 
						|
        _localizationService = localizationService;
 | 
						|
 | 
						|
        _ratingCacheProvider = cachingProviderFactory.GetCachingProvider(EasyCacheProfiles.KavitaPlusRatings);
 | 
						|
        _reviewCacheProvider = cachingProviderFactory.GetCachingProvider(EasyCacheProfiles.KavitaPlusReviews);
 | 
						|
        _recommendationCacheProvider = cachingProviderFactory.GetCachingProvider(EasyCacheProfiles.KavitaPlusRecommendations);
 | 
						|
    }
 | 
						|
 | 
						|
    [HttpPost]
 | 
						|
    public async Task<ActionResult<IEnumerable<Series>>> GetSeriesForLibrary(int libraryId, [FromQuery] UserParams userParams, [FromBody] FilterDto filterDto)
 | 
						|
    {
 | 
						|
        var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
 | 
						|
        var series =
 | 
						|
            await _unitOfWork.SeriesRepository.GetSeriesDtoForLibraryIdAsync(libraryId, userId, userParams, filterDto);
 | 
						|
 | 
						|
        // Apply progress/rating information (I can't work out how to do this in initial query)
 | 
						|
        if (series == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "no-series"));
 | 
						|
 | 
						|
        await _unitOfWork.SeriesRepository.AddSeriesModifiers(userId, series);
 | 
						|
 | 
						|
        Response.AddPaginationHeader(series.CurrentPage, series.PageSize, series.TotalCount, series.TotalPages);
 | 
						|
 | 
						|
        return Ok(series);
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Fetches a Series for a given Id
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="seriesId">Series Id to fetch details for</param>
 | 
						|
    /// <returns></returns>
 | 
						|
    /// <exception cref="NoContent">Throws an exception if the series Id does exist</exception>
 | 
						|
    [HttpGet("{seriesId:int}")]
 | 
						|
    public async Task<ActionResult<SeriesDto>> GetSeries(int seriesId)
 | 
						|
    {
 | 
						|
        var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
 | 
						|
        var series = await _unitOfWork.SeriesRepository.GetSeriesDtoByIdAsync(seriesId, userId);
 | 
						|
        if (series == null) return NoContent();
 | 
						|
        return Ok(series);
 | 
						|
    }
 | 
						|
 | 
						|
    [Authorize(Policy = "RequireAdminRole")]
 | 
						|
    [HttpDelete("{seriesId}")]
 | 
						|
    public async Task<ActionResult<bool>> DeleteSeries(int seriesId)
 | 
						|
    {
 | 
						|
        var username = User.GetUsername();
 | 
						|
        _logger.LogInformation("Series {SeriesId} is being deleted by {UserName}", seriesId, username);
 | 
						|
 | 
						|
        return Ok(await _seriesService.DeleteMultipleSeries(new[] {seriesId}));
 | 
						|
    }
 | 
						|
 | 
						|
    [Authorize(Policy = "RequireAdminRole")]
 | 
						|
    [HttpPost("delete-multiple")]
 | 
						|
    public async Task<ActionResult> DeleteMultipleSeries(DeleteSeriesDto dto)
 | 
						|
    {
 | 
						|
        var username = User.GetUsername();
 | 
						|
        _logger.LogInformation("Series {SeriesId} is being deleted by {UserName}", dto.SeriesIds, username);
 | 
						|
 | 
						|
        if (await _seriesService.DeleteMultipleSeries(dto.SeriesIds)) return Ok();
 | 
						|
 | 
						|
        return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-series-delete"));
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Returns All volumes for a series with progress information and Chapters
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="seriesId"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [HttpGet("volumes")]
 | 
						|
    public async Task<ActionResult<IEnumerable<VolumeDto>>> GetVolumes(int seriesId)
 | 
						|
    {
 | 
						|
        var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
 | 
						|
        return Ok(await _unitOfWork.VolumeRepository.GetVolumesDtoAsync(seriesId, userId));
 | 
						|
    }
 | 
						|
 | 
						|
    [HttpGet("volume")]
 | 
						|
    public async Task<ActionResult<VolumeDto?>> GetVolume(int volumeId)
 | 
						|
    {
 | 
						|
        var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
 | 
						|
        var vol = await _unitOfWork.VolumeRepository.GetVolumeDtoAsync(volumeId, userId);
 | 
						|
        if (vol == null) return NoContent();
 | 
						|
        return Ok(vol);
 | 
						|
    }
 | 
						|
 | 
						|
    [HttpGet("chapter")]
 | 
						|
    public async Task<ActionResult<ChapterDto>> GetChapter(int chapterId)
 | 
						|
    {
 | 
						|
        var chapter = await _unitOfWork.ChapterRepository.GetChapterDtoAsync(chapterId);
 | 
						|
        if (chapter == null) return NoContent();
 | 
						|
        return Ok(await _unitOfWork.ChapterRepository.AddChapterModifiers(User.GetUserId(), chapter));
 | 
						|
    }
 | 
						|
 | 
						|
    [HttpGet("chapter-metadata")]
 | 
						|
    public async Task<ActionResult<ChapterMetadataDto>> GetChapterMetadata(int chapterId)
 | 
						|
    {
 | 
						|
        return Ok(await _unitOfWork.ChapterRepository.GetChapterMetadataDtoAsync(chapterId));
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Update the user rating for the given series
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="updateSeriesRatingDto"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [HttpPost("update-rating")]
 | 
						|
    public async Task<ActionResult> UpdateSeriesRating(UpdateSeriesRatingDto updateSeriesRatingDto)
 | 
						|
    {
 | 
						|
        var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Ratings);
 | 
						|
        if (!await _seriesService.UpdateRating(user!, updateSeriesRatingDto))
 | 
						|
            return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-error"));
 | 
						|
        return Ok();
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Updates the Series
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="updateSeries"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [HttpPost("update")]
 | 
						|
    public async Task<ActionResult> UpdateSeries(UpdateSeriesDto updateSeries)
 | 
						|
    {
 | 
						|
        var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(updateSeries.Id);
 | 
						|
        if (series == null)
 | 
						|
            return BadRequest(await _localizationService.Translate(User.GetUserId(), "series-doesnt-exist"));
 | 
						|
 | 
						|
        series.NormalizedName = series.Name.ToNormalized();
 | 
						|
        if (!string.IsNullOrEmpty(updateSeries.SortName?.Trim()))
 | 
						|
        {
 | 
						|
            series.SortName = updateSeries.SortName.Trim();
 | 
						|
        }
 | 
						|
 | 
						|
        series.LocalizedName = updateSeries.LocalizedName?.Trim();
 | 
						|
        series.NormalizedLocalizedName = series.LocalizedName?.ToNormalized();
 | 
						|
 | 
						|
        series.SortNameLocked = updateSeries.SortNameLocked;
 | 
						|
        series.LocalizedNameLocked = updateSeries.LocalizedNameLocked;
 | 
						|
 | 
						|
 | 
						|
        var needsRefreshMetadata = false;
 | 
						|
        // This is when you hit Reset
 | 
						|
        if (series.CoverImageLocked && !updateSeries.CoverImageLocked)
 | 
						|
        {
 | 
						|
            // Trigger a refresh when we are moving from a locked image to a non-locked
 | 
						|
            needsRefreshMetadata = true;
 | 
						|
            series.CoverImage = string.Empty;
 | 
						|
            series.CoverImageLocked = updateSeries.CoverImageLocked;
 | 
						|
        }
 | 
						|
 | 
						|
        _unitOfWork.SeriesRepository.Update(series);
 | 
						|
 | 
						|
        if (await _unitOfWork.CommitAsync())
 | 
						|
        {
 | 
						|
            if (needsRefreshMetadata)
 | 
						|
            {
 | 
						|
                _taskScheduler.RefreshSeriesMetadata(series.LibraryId, series.Id);
 | 
						|
            }
 | 
						|
            return Ok();
 | 
						|
        }
 | 
						|
 | 
						|
        return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-series-update"));
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Gets all recently added series
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="filterDto"></param>
 | 
						|
    /// <param name="userParams"></param>
 | 
						|
    /// <param name="libraryId"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [ResponseCache(CacheProfileName = "Instant")]
 | 
						|
    [HttpPost("recently-added")]
 | 
						|
    public async Task<ActionResult<IEnumerable<SeriesDto>>> GetRecentlyAdded(FilterDto filterDto, [FromQuery] UserParams userParams, [FromQuery] int libraryId = 0)
 | 
						|
    {
 | 
						|
        var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
 | 
						|
        var series =
 | 
						|
            await _unitOfWork.SeriesRepository.GetRecentlyAdded(libraryId, userId, userParams, filterDto);
 | 
						|
 | 
						|
        // Apply progress/rating information (I can't work out how to do this in initial query)
 | 
						|
        if (series == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "no-series"));
 | 
						|
 | 
						|
        await _unitOfWork.SeriesRepository.AddSeriesModifiers(userId, series);
 | 
						|
 | 
						|
        Response.AddPaginationHeader(series.CurrentPage, series.PageSize, series.TotalCount, series.TotalPages);
 | 
						|
 | 
						|
        return Ok(series);
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Returns series that were recently updated, like adding or removing a chapter
 | 
						|
    /// </summary>
 | 
						|
    /// <returns></returns>
 | 
						|
    [ResponseCache(CacheProfileName = "Instant")]
 | 
						|
    [HttpPost("recently-updated-series")]
 | 
						|
    public async Task<ActionResult<IEnumerable<RecentlyAddedItemDto>>> GetRecentlyAddedChapters()
 | 
						|
    {
 | 
						|
        var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
 | 
						|
        return Ok(await _unitOfWork.SeriesRepository.GetRecentlyUpdatedSeries(userId, 20));
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Returns all series for the library
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="filterDto"></param>
 | 
						|
    /// <param name="userParams"></param>
 | 
						|
    /// <param name="libraryId"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [HttpPost("all")]
 | 
						|
    public async Task<ActionResult<IEnumerable<SeriesDto>>> GetAllSeries(FilterDto filterDto, [FromQuery] UserParams userParams, [FromQuery] int libraryId = 0)
 | 
						|
    {
 | 
						|
        var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
 | 
						|
        var series =
 | 
						|
            await _unitOfWork.SeriesRepository.GetSeriesDtoForLibraryIdAsync(libraryId, userId, userParams, filterDto);
 | 
						|
 | 
						|
        // Apply progress/rating information (I can't work out how to do this in initial query)
 | 
						|
        if (series == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "no-series"));
 | 
						|
 | 
						|
        await _unitOfWork.SeriesRepository.AddSeriesModifiers(userId, series);
 | 
						|
 | 
						|
        Response.AddPaginationHeader(series.CurrentPage, series.PageSize, series.TotalCount, series.TotalPages);
 | 
						|
 | 
						|
        return Ok(series);
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Fetches series that are on deck aka have progress on them.
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="filterDto"></param>
 | 
						|
    /// <param name="userParams"></param>
 | 
						|
    /// <param name="libraryId">Default of 0 meaning all libraries</param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [ResponseCache(CacheProfileName = "Instant")]
 | 
						|
    [HttpPost("on-deck")]
 | 
						|
    public async Task<ActionResult<IEnumerable<SeriesDto>>> GetOnDeck(FilterDto filterDto, [FromQuery] UserParams userParams, [FromQuery] int libraryId = 0)
 | 
						|
    {
 | 
						|
        var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
 | 
						|
        var pagedList = await _unitOfWork.SeriesRepository.GetOnDeck(userId, libraryId, userParams, filterDto);
 | 
						|
 | 
						|
        await _unitOfWork.SeriesRepository.AddSeriesModifiers(userId, pagedList);
 | 
						|
 | 
						|
        Response.AddPaginationHeader(pagedList.CurrentPage, pagedList.PageSize, pagedList.TotalCount, pagedList.TotalPages);
 | 
						|
 | 
						|
        return Ok(pagedList);
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Removes a series from displaying on deck until the next read event on that series
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="seriesId"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [HttpPost("remove-from-on-deck")]
 | 
						|
    public async Task<ActionResult> RemoveFromOnDeck([FromQuery] int seriesId)
 | 
						|
    {
 | 
						|
        await _unitOfWork.SeriesRepository.RemoveFromOnDeck(seriesId, User.GetUserId());
 | 
						|
        return Ok();
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Runs a Cover Image Generation task
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="refreshSeriesDto"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [Authorize(Policy = "RequireAdminRole")]
 | 
						|
    [HttpPost("refresh-metadata")]
 | 
						|
    public ActionResult RefreshSeriesMetadata(RefreshSeriesDto refreshSeriesDto)
 | 
						|
    {
 | 
						|
        _taskScheduler.RefreshSeriesMetadata(refreshSeriesDto.LibraryId, refreshSeriesDto.SeriesId, refreshSeriesDto.ForceUpdate);
 | 
						|
        return Ok();
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Scan a series and force each file to be updated. This should be invoked via the User, hence why we force.
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="refreshSeriesDto"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [Authorize(Policy = "RequireAdminRole")]
 | 
						|
    [HttpPost("scan")]
 | 
						|
    public ActionResult ScanSeries(RefreshSeriesDto refreshSeriesDto)
 | 
						|
    {
 | 
						|
        _taskScheduler.ScanSeries(refreshSeriesDto.LibraryId, refreshSeriesDto.SeriesId, refreshSeriesDto.ForceUpdate);
 | 
						|
        return Ok();
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Run a file analysis on the series.
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="refreshSeriesDto"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [Authorize(Policy = "RequireAdminRole")]
 | 
						|
    [HttpPost("analyze")]
 | 
						|
    public ActionResult AnalyzeSeries(RefreshSeriesDto refreshSeriesDto)
 | 
						|
    {
 | 
						|
        _taskScheduler.AnalyzeFilesForSeries(refreshSeriesDto.LibraryId, refreshSeriesDto.SeriesId, refreshSeriesDto.ForceUpdate);
 | 
						|
        return Ok();
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Returns metadata for a given series
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="seriesId"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [HttpGet("metadata")]
 | 
						|
    public async Task<ActionResult<SeriesMetadataDto>> GetSeriesMetadata(int seriesId)
 | 
						|
    {
 | 
						|
        var metadata = await _unitOfWork.SeriesRepository.GetSeriesMetadata(seriesId);
 | 
						|
        return Ok(metadata);
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Update series metadata
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="updateSeriesMetadataDto"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [HttpPost("metadata")]
 | 
						|
    public async Task<ActionResult> UpdateSeriesMetadata(UpdateSeriesMetadataDto updateSeriesMetadataDto)
 | 
						|
    {
 | 
						|
        if (await _seriesService.UpdateSeriesMetadata(updateSeriesMetadataDto))
 | 
						|
        {
 | 
						|
            if (await _licenseService.HasActiveLicense())
 | 
						|
            {
 | 
						|
                _logger.LogDebug("Clearing cache as series weblinks may have changed");
 | 
						|
                await _reviewCacheProvider.RemoveAsync(ReviewController.CacheKey + updateSeriesMetadataDto.SeriesMetadata.SeriesId);
 | 
						|
                await _ratingCacheProvider.RemoveAsync(RatingController.CacheKey + updateSeriesMetadataDto.SeriesMetadata.SeriesId);
 | 
						|
 | 
						|
                var allUsers = (await _unitOfWork.UserRepository.GetAllUsersAsync()).Select(s => s.Id);
 | 
						|
                foreach (var userId in allUsers)
 | 
						|
                {
 | 
						|
                    await _recommendationCacheProvider.RemoveAsync(RecommendedController.CacheKey + $"{updateSeriesMetadataDto.SeriesMetadata.SeriesId}-{userId}");
 | 
						|
                }
 | 
						|
            }
 | 
						|
 | 
						|
            return Ok(await _localizationService.Translate(User.GetUserId(), "series-updated"));
 | 
						|
        }
 | 
						|
 | 
						|
        return BadRequest(await _localizationService.Translate(User.GetUserId(), "update-metadata-fail"));
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Returns all Series grouped by the passed Collection Id with Pagination.
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="collectionId">Collection Id to pull series from</param>
 | 
						|
    /// <param name="userParams">Pagination information</param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [HttpGet("series-by-collection")]
 | 
						|
    public async Task<ActionResult<IEnumerable<SeriesDto>>> GetSeriesByCollectionTag(int collectionId, [FromQuery] UserParams userParams)
 | 
						|
    {
 | 
						|
        var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
 | 
						|
        var series =
 | 
						|
            await _unitOfWork.SeriesRepository.GetSeriesDtoForCollectionAsync(collectionId, userId, userParams);
 | 
						|
 | 
						|
        // Apply progress/rating information (I can't work out how to do this in initial query)
 | 
						|
        if (series == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "no-series-collection"));
 | 
						|
 | 
						|
        await _unitOfWork.SeriesRepository.AddSeriesModifiers(userId, series);
 | 
						|
 | 
						|
        Response.AddPaginationHeader(series.CurrentPage, series.PageSize, series.TotalCount, series.TotalPages);
 | 
						|
 | 
						|
        return Ok(series);
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Fetches Series for a set of Ids. This will check User for permission access and filter out any Ids that don't exist or
 | 
						|
    /// the user does not have access to.
 | 
						|
    /// </summary>
 | 
						|
    /// <returns></returns>
 | 
						|
    [HttpPost("series-by-ids")]
 | 
						|
    public async Task<ActionResult<IEnumerable<SeriesDto>>> GetAllSeriesById(SeriesByIdsDto dto)
 | 
						|
    {
 | 
						|
        if (dto.SeriesIds == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "invalid-payload"));
 | 
						|
        var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
 | 
						|
        return Ok(await _unitOfWork.SeriesRepository.GetSeriesDtoForIdsAsync(dto.SeriesIds, userId));
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Get the age rating for the <see cref="AgeRating"/> enum value
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="ageRating"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    /// <remarks>This is cached for an hour</remarks>
 | 
						|
    [ResponseCache(CacheProfileName = "Month", VaryByQueryKeys = new [] {"ageRating"})]
 | 
						|
    [HttpGet("age-rating")]
 | 
						|
    public async Task<ActionResult<string>> GetAgeRating(int ageRating)
 | 
						|
    {
 | 
						|
        var val = (AgeRating) ageRating;
 | 
						|
        if (val == AgeRating.NotApplicable)
 | 
						|
            return await _localizationService.Translate(User.GetUserId(), "age-restriction-not-applicable");
 | 
						|
 | 
						|
        return Ok(val.ToDescription());
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Get a special DTO for Series Detail page.
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="seriesId"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    /// <remarks>Do not rely on this API externally. May change without hesitation. </remarks>
 | 
						|
    [ResponseCache(CacheProfileName = ResponseCacheProfiles.FiveMinute, VaryByQueryKeys = new [] {"seriesId"})]
 | 
						|
    [HttpGet("series-detail")]
 | 
						|
    public async Task<ActionResult<SeriesDetailDto>> GetSeriesDetailBreakdown(int seriesId)
 | 
						|
    {
 | 
						|
        var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
 | 
						|
        try
 | 
						|
        {
 | 
						|
            return await _seriesService.GetSeriesDetail(seriesId, userId);
 | 
						|
        }
 | 
						|
        catch (KavitaException ex)
 | 
						|
        {
 | 
						|
            return BadRequest(await _localizationService.Translate(User.GetUserId(), ex.Message));
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Fetches the related series for a given series
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="seriesId"></param>
 | 
						|
    /// <param name="relation">Type of Relationship to pull back</param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [HttpGet("related")]
 | 
						|
    public async Task<ActionResult<IEnumerable<SeriesDto>>> GetRelatedSeries(int seriesId, RelationKind relation)
 | 
						|
    {
 | 
						|
        // Send back a custom DTO with each type or maybe sorted in some way
 | 
						|
        var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
 | 
						|
        return Ok(await _unitOfWork.SeriesRepository.GetSeriesForRelationKind(userId, seriesId, relation));
 | 
						|
    }
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Returns all related series against the passed series Id
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="seriesId"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [HttpGet("all-related")]
 | 
						|
    public async Task<ActionResult<RelatedSeriesDto>> GetAllRelatedSeries(int seriesId)
 | 
						|
    {
 | 
						|
        var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
 | 
						|
        return Ok(await _seriesService.GetRelatedSeries(userId, seriesId));
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    /// <summary>
 | 
						|
    /// Update the relations attached to the Series. Does not generate associated Sequel/Prequel pairs on target series.
 | 
						|
    /// </summary>
 | 
						|
    /// <param name="dto"></param>
 | 
						|
    /// <returns></returns>
 | 
						|
    [Authorize(Policy="RequireAdminRole")]
 | 
						|
    [HttpPost("update-related")]
 | 
						|
    public async Task<ActionResult> UpdateRelatedSeries(UpdateRelatedSeriesDto dto)
 | 
						|
    {
 | 
						|
        if (await _seriesService.UpdateRelatedSeries(dto))
 | 
						|
        {
 | 
						|
            return Ok();
 | 
						|
        }
 | 
						|
 | 
						|
        return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-relationship"));
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
 | 
						|
}
 |