mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
* adding back side-nav * Event Widget Update (#1098) * Took care of some notes in the code * Fixed an issue where Extra might get flagged as special too early, if in a word like Extraordinary * Moved Tag cleanup code into Scanner service. Added a SplitQuery to another heavy API. Refactored Scan loop to remove parallelism and use async instead. * Lots of rework on the codebase to support detailed messages and easier management of message sending. Need to take a break on this work. * Progress is being made, but slowly. Code is broken in this commit. * Progress is being made, but slowly. Code is broken in this commit. * Fixed merge issue * Fixed unit tests * CoverUpdate is now hooked into new ProgressEvent structure * Refactored code to remove custom observables and have everything use standard messages$ * Refactored a ton of instances to NotificationProgressEvent style and tons of the UI to respect that too. UI is still a bit buggy, but wholistically the work is done. * Working much better. Sometimes events come in too fast. Currently cover update progress doesn't display on UI * Fixed unit tests * Removed SignalREvent to minimize internal event types. Updated the UI to use progress bars. Finished SiteThemeService. * Merged metadata refresh progress events and changed library scan events to merge cleaner in the UI * Changed RefreshMetadataProgress to CoverUpdateProgress to reflect the event better. * Theme Cleanup (#1089) * Fixed e-ink theme not properly applying correctly * Fixed some seed changes. Changed card checkboxes to use our themed ones * Fixed recently added carousel not going to recently-added page * Fixed an issue where no results found would show when searching for a library name * Cleaned up list a bit, typeahead dropdown still needs work * Added a TODO to streamline series-card component * Removed ng-lazyload-image module since we don't use it. We use lazysizes * Darken card on hover * Fixing accordion focus style * ux pass updates - Fixed typeahead width - Fixed changelog download buttons - Fixed a select - Fixed various input box-shadows - Fixed all anchors to only have underline on hover - Added navtab hover and active effects * more ux pass - Fixed spacing on theme cards - Fixed some light theme issues - Exposed text-muted-color for theme card subtitle color * UX pass fixes - Changed back to bright green for primary on dark theme - Changed fa icon to black on e-ink * Merged changelog component * Fixed anchor buttons text decoration * Changed nav tabs to have a background color instead of open active state * When user is not authenticated, make sure we set default theme (dark) * Cleanup on carousel * Updated Users tab to use small buttons with icons to align with Library tab * Cleaned up brand to not underline, removed default link underline on hover in dropdown and pill tabs * Fixed collection detail posters not rendering Co-authored-by: Robbie Davis <robbie@therobbiedavis.com> * Bump versions by dotnet-bump-version. * Tweaked some of the emitting code * Some css, but pretty bad. Robbie please save me * Removed a todo * styling update * Only send filename on FileScanProgress * Some console.log spam cleanup * Various updates * Show events widget activity based on activeEvents * progress bar color updates * Code cleanup Co-authored-by: Robbie Davis <robbie@therobbiedavis.com> * Bump versions by dotnet-bump-version. * Scanner event hub fix (#1099) * Scanner event hub fix - Fixed an issue where the scanner would error when adding a new series because the series didn't have a library name yet. (develop) * Removing library.type * Bump versions by dotnet-bump-version. * Workflow update to add nightly versions (#1100) # Changed - Changed: Changed automated workflow to release individual nightly versions on dockerhub * Bump versions by dotnet-bump-version. * Updating GA to parse version (#1101) * Bump versions by dotnet-bump-version. * GA Fixes (#1103) **Strictly Repo Changes** # Fixed - Fixed: Fixed an issue where patch version was not being added to docker tag. * Bump versions by dotnet-bump-version. * Fixed specials being misaligned (#1106) # Fixed - Fixed: Fixed issue with specials not being properly aligned (develop) * Bump versions by dotnet-bump-version. * Bugfix/ux pass 2 (#1107) * Adding margin bottom to series detail tabs * Styling tag badges with green on dark - Added 3 new css vars * Removing underline from readmore * Fixing see more to be on one line * adding gutter to see more * Changing queue toasts to info * adding api key tooltip * Updating active accordion on user preference. * Fixing search bar and close btn position * Fixed a bug where entering book reader in dark mode then closing out, would leave you in a broken white state. * Fixed broken wiki links Co-authored-by: Joseph Milazzo <joseph.v.milazzo@gmail.com> * Bump versions by dotnet-bump-version. * Series Detail Refactor (#1118) * Fixed a bug where reading list and collection's summary wouldn't render newlines * Moved all the logic in the UI for Series Detail into the backend (messy code). We are averaging 400ms max with much optimizations available. Next step is to refactor out of controller and provide unit tests. * Unit tests for CleanSpecialTitle * Laid out foundation for testing major code in SeriesController. * Refactored code so that read doesn't need to be disabled on page load. SeriesId doesn't need the series to actually load. * Removed old property from Volume * Changed tagbadge font size to rem. * Refactored some methods from SeriesController.cs into SeriesService.cs * UpdateRating unit tested * Wrote unit tests for SeriesDetail * Worked up some code where books are rendered only as volumes. However, looks like I will need to use Chapters to better support series_index as floats. * Refactored Series Detail to change Volume Name on Book libraries to have book name and series_index. * Some cleanup on the code * DeleteMultipleSeries test is hard. Going to skip. * Removed some debug code and make all tabs Books for Book library Type * Bump versions by dotnet-bump-version. * Tachiyomi Bugfix (#1119) * Updated the dependencies for .NET 6.0.2 * Fixed a bad prev chapter logic where we would bleed into chapters from last volume instead of specials. * Fixed the get prev chapter code to properly walk the order according to documentation and updated some bad test cases * Updated side nav to float a bit and added user settings to it. * Refactored the code to hide/show sidenav to be more angular and decoupled * Moved Changelog out of admin dashboard and into a dedicated page in user menu. Added a wiki link from user menu * Introduced a side nav item for rendering each item and refactored code to use it. * Added a filter of side nav when there are more than 10 libraries. Added some themeing overrides for side nav. * Cleaned up the template code for side nav item so if there is no link, we don't generate that html directive * Refactored side nav into a module and migrated a few pipes into a pipe module for easy re-use * Added companion bar on reading list and collection. Updated modules to load pages and make side nav items clickable as anchors, so new tab works. * Moved metadata filter into separate component/module and the button in the companion bar. Needs cleanup. * Finished cleanup and refactoring of metadata filter into separate component. Removed filtering from Collections as it doesn't work and wasn't hooked up. * Tweaked the css on carousel component * Added to library detail and series-detail * Fixes and css vars * Stop destroying sidenav, animaton timing * Integrated side nav on the rest of the pages * Navbar now collapses to icons * mobile sidenav start * more mobile fixes * mobile tweaks * light and e-ink theme updates * white and eink dropdown color fixes * plex inspired side-nav * theme fixes * Making spacing more uniform across app * More fixes * fixing spacing on cards * actionable fix for sidenav * no scroll on mobile when sidenav is open * hide sidenav on pages * Adding card spacing * Adding ability to remove sidenav when in a reader * tidying up sidenav toggles * side-nav mobile updates * fixing up other themes * overlay fixes * Cleaned up the code to make the observables have better names. Removed a bunch of pointless subscriptions. Cleaned up methods that werent needed. Added jsdocs to help ensure the understandability of the 2 states for the side nav. * Integrated a highlight effect on side nav. Fixed a ton of places where the nav was being hidden when it shouldn't. * Fixed where active state wasn't working on all urls * misc fixes - smaller hamburger - z-index fixes - active fixes * Revert "Merge branch 'develop' into feature/side-nav-upgrade" This reverts commit 76b0d15a984692874e0cb57e821686ea703144cf, reversing changes made to b3ed55395473aa35577500596a211ad22a42631b. * Fixing edit-series modal spacing * Give the ability to jump to a library from admin manage libraries page * Fixed a bug with highlighting active item on side nav * Moved localized series title to companion bar via subtitle * Removed old title * Fixed a bug where clicking a link would reload the whole app, styling fixes on filter, fixed issue with initial load not setting active state, adjusted styles on active style. * code cleanup Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
589 lines
24 KiB
C#
589 lines
24 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using API.Data;
|
|
using API.Data.Repositories;
|
|
using API.DTOs;
|
|
using API.DTOs.Reader;
|
|
using API.Entities;
|
|
using API.Extensions;
|
|
using API.Services;
|
|
using API.Services.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace API.Controllers
|
|
{
|
|
/// <summary>
|
|
/// For all things regarding reading, mainly focusing on non-Book related entities
|
|
/// </summary>
|
|
public class ReaderController : BaseApiController
|
|
{
|
|
private readonly ICacheService _cacheService;
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
private readonly ILogger<ReaderController> _logger;
|
|
private readonly IReaderService _readerService;
|
|
private readonly IDirectoryService _directoryService;
|
|
private readonly ICleanupService _cleanupService;
|
|
private readonly IBookmarkService _bookmarkService;
|
|
|
|
/// <inheritdoc />
|
|
public ReaderController(ICacheService cacheService,
|
|
IUnitOfWork unitOfWork, ILogger<ReaderController> logger,
|
|
IReaderService readerService, IDirectoryService directoryService,
|
|
ICleanupService cleanupService, IBookmarkService bookmarkService)
|
|
{
|
|
_cacheService = cacheService;
|
|
_unitOfWork = unitOfWork;
|
|
_logger = logger;
|
|
_readerService = readerService;
|
|
_directoryService = directoryService;
|
|
_cleanupService = cleanupService;
|
|
_bookmarkService = bookmarkService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns an image for a given chapter. Side effect: This will cache the chapter images for reading.
|
|
/// </summary>
|
|
/// <param name="chapterId"></param>
|
|
/// <param name="page"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("image")]
|
|
public async Task<ActionResult> GetImage(int chapterId, int page)
|
|
{
|
|
if (page < 0) page = 0;
|
|
var chapter = await _cacheService.Ensure(chapterId);
|
|
if (chapter == null) return BadRequest("There was an issue finding image file for reading");
|
|
|
|
try
|
|
{
|
|
var path = _cacheService.GetCachedPagePath(chapter, page);
|
|
if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path)) return BadRequest($"No such image for page {page}");
|
|
var format = Path.GetExtension(path).Replace(".", "");
|
|
|
|
Response.AddCacheHeader(path, TimeSpan.FromMinutes(10).Seconds);
|
|
return PhysicalFile(path, "image/" + format, Path.GetFileName(path));
|
|
}
|
|
catch (Exception)
|
|
{
|
|
_cacheService.CleanupChapters(new []{ chapterId });
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns various information about a Chapter. Side effect: This will cache the chapter images for reading.
|
|
/// </summary>
|
|
/// <param name="chapterId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("chapter-info")]
|
|
public async Task<ActionResult<ChapterInfoDto>> GetChapterInfo(int chapterId)
|
|
{
|
|
var chapter = await _cacheService.Ensure(chapterId);
|
|
if (chapter == null) return BadRequest("Could not find Chapter");
|
|
|
|
var dto = await _unitOfWork.ChapterRepository.GetChapterInfoDtoAsync(chapterId);
|
|
if (dto == null) return BadRequest("Please perform a scan on this series or library and try again");
|
|
var mangaFile = (await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(chapterId)).First();
|
|
|
|
return Ok(new ChapterInfoDto()
|
|
{
|
|
ChapterNumber = dto.ChapterNumber,
|
|
VolumeNumber = dto.VolumeNumber,
|
|
VolumeId = dto.VolumeId,
|
|
FileName = Path.GetFileName(mangaFile.FilePath),
|
|
SeriesName = dto.SeriesName,
|
|
SeriesFormat = dto.SeriesFormat,
|
|
SeriesId = dto.SeriesId,
|
|
LibraryId = dto.LibraryId,
|
|
IsSpecial = dto.IsSpecial,
|
|
Pages = dto.Pages,
|
|
ChapterTitle = dto.ChapterTitle ?? string.Empty
|
|
});
|
|
}
|
|
|
|
|
|
[HttpPost("mark-read")]
|
|
public async Task<ActionResult> MarkRead(MarkReadDto markReadDto)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Progress);
|
|
var volumes = await _unitOfWork.VolumeRepository.GetVolumes(markReadDto.SeriesId);
|
|
user.Progresses ??= new List<AppUserProgress>();
|
|
foreach (var volume in volumes)
|
|
{
|
|
_readerService.MarkChaptersAsRead(user, markReadDto.SeriesId, volume.Chapters);
|
|
}
|
|
|
|
_unitOfWork.UserRepository.Update(user);
|
|
|
|
if (await _unitOfWork.CommitAsync())
|
|
{
|
|
return Ok();
|
|
}
|
|
|
|
|
|
return BadRequest("There was an issue saving progress");
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Marks a Series as Unread (progress)
|
|
/// </summary>
|
|
/// <param name="markReadDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("mark-unread")]
|
|
public async Task<ActionResult> MarkUnread(MarkReadDto markReadDto)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Progress);
|
|
var volumes = await _unitOfWork.VolumeRepository.GetVolumes(markReadDto.SeriesId);
|
|
user.Progresses ??= new List<AppUserProgress>();
|
|
foreach (var volume in volumes)
|
|
{
|
|
_readerService.MarkChaptersAsUnread(user, markReadDto.SeriesId, volume.Chapters);
|
|
}
|
|
|
|
_unitOfWork.UserRepository.Update(user);
|
|
|
|
if (await _unitOfWork.CommitAsync())
|
|
{
|
|
return Ok();
|
|
}
|
|
|
|
|
|
return BadRequest("There was an issue saving progress");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks all chapters within a volume as unread
|
|
/// </summary>
|
|
/// <param name="markVolumeReadDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("mark-volume-unread")]
|
|
public async Task<ActionResult> MarkVolumeAsUnread(MarkVolumeReadDto markVolumeReadDto)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Progress);
|
|
|
|
var chapters = await _unitOfWork.ChapterRepository.GetChaptersAsync(markVolumeReadDto.VolumeId);
|
|
_readerService.MarkChaptersAsUnread(user, markVolumeReadDto.SeriesId, chapters);
|
|
|
|
_unitOfWork.UserRepository.Update(user);
|
|
|
|
if (await _unitOfWork.CommitAsync())
|
|
{
|
|
return Ok();
|
|
}
|
|
|
|
return BadRequest("Could not save progress");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks all chapters within a volume as Read
|
|
/// </summary>
|
|
/// <param name="markVolumeReadDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("mark-volume-read")]
|
|
public async Task<ActionResult> MarkVolumeAsRead(MarkVolumeReadDto markVolumeReadDto)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Progress);
|
|
|
|
var chapters = await _unitOfWork.ChapterRepository.GetChaptersAsync(markVolumeReadDto.VolumeId);
|
|
_readerService.MarkChaptersAsRead(user, markVolumeReadDto.SeriesId, chapters);
|
|
|
|
_unitOfWork.UserRepository.Update(user);
|
|
|
|
if (await _unitOfWork.CommitAsync())
|
|
{
|
|
return Ok();
|
|
}
|
|
|
|
return BadRequest("Could not save progress");
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Marks all chapters within a list of volumes as Read. All volumes must belong to the same Series.
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("mark-multiple-read")]
|
|
public async Task<ActionResult> MarkMultipleAsRead(MarkVolumesReadDto dto)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Progress);
|
|
user.Progresses ??= new List<AppUserProgress>();
|
|
|
|
var chapterIds = await _unitOfWork.VolumeRepository.GetChapterIdsByVolumeIds(dto.VolumeIds);
|
|
foreach (var chapterId in dto.ChapterIds)
|
|
{
|
|
chapterIds.Add(chapterId);
|
|
}
|
|
var chapters = await _unitOfWork.ChapterRepository.GetChaptersByIdsAsync(chapterIds);
|
|
_readerService.MarkChaptersAsRead(user, dto.SeriesId, chapters);
|
|
|
|
_unitOfWork.UserRepository.Update(user);
|
|
|
|
if (await _unitOfWork.CommitAsync())
|
|
{
|
|
return Ok();
|
|
}
|
|
|
|
return BadRequest("Could not save progress");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks all chapters within a list of volumes as Unread. All volumes must belong to the same Series.
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("mark-multiple-unread")]
|
|
public async Task<ActionResult> MarkMultipleAsUnread(MarkVolumesReadDto dto)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Progress);
|
|
user.Progresses ??= new List<AppUserProgress>();
|
|
|
|
var chapterIds = await _unitOfWork.VolumeRepository.GetChapterIdsByVolumeIds(dto.VolumeIds);
|
|
foreach (var chapterId in dto.ChapterIds)
|
|
{
|
|
chapterIds.Add(chapterId);
|
|
}
|
|
var chapters = await _unitOfWork.ChapterRepository.GetChaptersByIdsAsync(chapterIds);
|
|
_readerService.MarkChaptersAsUnread(user, dto.SeriesId, chapters);
|
|
|
|
_unitOfWork.UserRepository.Update(user);
|
|
|
|
if (await _unitOfWork.CommitAsync())
|
|
{
|
|
return Ok();
|
|
}
|
|
|
|
return BadRequest("Could not save progress");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks all chapters within a list of series as Read.
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("mark-multiple-series-read")]
|
|
public async Task<ActionResult> MarkMultipleSeriesAsRead(MarkMultipleSeriesAsReadDto dto)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Progress);
|
|
user.Progresses ??= new List<AppUserProgress>();
|
|
|
|
var volumes = await _unitOfWork.VolumeRepository.GetVolumesForSeriesAsync(dto.SeriesIds.ToArray(), true);
|
|
foreach (var volume in volumes)
|
|
{
|
|
_readerService.MarkChaptersAsRead(user, volume.SeriesId, volume.Chapters);
|
|
}
|
|
|
|
_unitOfWork.UserRepository.Update(user);
|
|
|
|
if (await _unitOfWork.CommitAsync())
|
|
{
|
|
return Ok();
|
|
}
|
|
|
|
return BadRequest("Could not save progress");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks all chapters within a list of series as Unread.
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("mark-multiple-series-unread")]
|
|
public async Task<ActionResult> MarkMultipleSeriesAsUnread(MarkMultipleSeriesAsReadDto dto)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Progress);
|
|
user.Progresses ??= new List<AppUserProgress>();
|
|
|
|
var volumes = await _unitOfWork.VolumeRepository.GetVolumesForSeriesAsync(dto.SeriesIds.ToArray(), true);
|
|
foreach (var volume in volumes)
|
|
{
|
|
_readerService.MarkChaptersAsUnread(user, volume.SeriesId, volume.Chapters);
|
|
}
|
|
|
|
_unitOfWork.UserRepository.Update(user);
|
|
|
|
if (await _unitOfWork.CommitAsync())
|
|
{
|
|
return Ok();
|
|
}
|
|
|
|
return BadRequest("Could not save progress");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns Progress (page number) for a chapter for the logged in user
|
|
/// </summary>
|
|
/// <param name="chapterId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("get-progress")]
|
|
public async Task<ActionResult<ProgressDto>> GetProgress(int chapterId)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Progress);
|
|
var progressBookmark = new ProgressDto()
|
|
{
|
|
PageNum = 0,
|
|
ChapterId = chapterId,
|
|
VolumeId = 0,
|
|
SeriesId = 0
|
|
};
|
|
if (user.Progresses == null) return Ok(progressBookmark);
|
|
var progress = user.Progresses.FirstOrDefault(x => x.AppUserId == user.Id && x.ChapterId == chapterId);
|
|
|
|
if (progress != null)
|
|
{
|
|
progressBookmark.SeriesId = progress.SeriesId;
|
|
progressBookmark.VolumeId = progress.VolumeId;
|
|
progressBookmark.PageNum = progress.PagesRead;
|
|
progressBookmark.BookScrollId = progress.BookScrollId;
|
|
}
|
|
return Ok(progressBookmark);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Save page against Chapter for logged in user
|
|
/// </summary>
|
|
/// <param name="progressDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("progress")]
|
|
public async Task<ActionResult> BookmarkProgress(ProgressDto progressDto)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
|
|
|
|
if (await _readerService.SaveReadingProgress(progressDto, user.Id)) return Ok(true);
|
|
|
|
return BadRequest("Could not save progress");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Continue point is the chapter which you should start reading again from. If there is no progress on a series, then the first chapter will be returned (non-special unless only specials).
|
|
/// Otherwise, loop through the chapters and volumes in order to find the next chapter which has progress.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("continue-point")]
|
|
public async Task<ActionResult<ChapterDto>> GetContinuePoint(int seriesId)
|
|
{
|
|
var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
|
|
|
|
return Ok(await _readerService.GetContinuePoint(seriesId, userId));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns if the user has reading progress on the Series
|
|
/// </summary>
|
|
/// <param name="seriesId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("has-progress")]
|
|
public async Task<ActionResult<ChapterDto>> HasProgress(int seriesId)
|
|
{
|
|
var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
|
|
return Ok(await _unitOfWork.AppUserProgressRepository.HasAnyProgressOnSeriesAsync(seriesId, userId));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Marks every chapter that is sorted below the passed number as Read. This will not mark any specials as read.
|
|
/// </summary>
|
|
/// <remarks>This is built for Tachiyomi and is not expected to be called by any other place</remarks>
|
|
/// <returns></returns>
|
|
[HttpPost("mark-chapter-until-as-read")]
|
|
public async Task<ActionResult<bool>> MarkChaptersUntilAsRead(int seriesId, float chapterNumber)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Progress);
|
|
user.Progresses ??= new List<AppUserProgress>();
|
|
|
|
if (chapterNumber < 1.0f)
|
|
{
|
|
// This is a hack to track volume number. We need to map it back by x100
|
|
var volumeNumber = int.Parse($"{chapterNumber * 100f}");
|
|
await _readerService.MarkVolumesUntilAsRead(user, seriesId, volumeNumber);
|
|
}
|
|
else
|
|
{
|
|
await _readerService.MarkChaptersUntilAsRead(user, seriesId, chapterNumber);
|
|
}
|
|
|
|
|
|
_unitOfWork.UserRepository.Update(user);
|
|
|
|
if (!_unitOfWork.HasChanges()) return Ok(true);
|
|
if (await _unitOfWork.CommitAsync()) return Ok(true);
|
|
|
|
await _unitOfWork.RollbackAsync();
|
|
return Ok(false);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns a list of bookmarked pages for a given Chapter
|
|
/// </summary>
|
|
/// <param name="chapterId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("get-bookmarks")]
|
|
public async Task<ActionResult<IEnumerable<BookmarkDto>>> GetBookmarks(int chapterId)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Bookmarks);
|
|
if (user.Bookmarks == null) return Ok(Array.Empty<BookmarkDto>());
|
|
return Ok(await _unitOfWork.UserRepository.GetBookmarkDtosForChapter(user.Id, chapterId));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a list of all bookmarked pages for a User
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("get-all-bookmarks")]
|
|
public async Task<ActionResult<IEnumerable<BookmarkDto>>> GetAllBookmarks()
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Bookmarks);
|
|
if (user.Bookmarks == null) return Ok(Array.Empty<BookmarkDto>());
|
|
return Ok(await _unitOfWork.UserRepository.GetAllBookmarkDtos(user.Id));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes all bookmarks for all chapters linked to a Series
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("remove-bookmarks")]
|
|
public async Task<ActionResult> RemoveBookmarks(RemoveBookmarkForSeriesDto dto)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Bookmarks);
|
|
if (user.Bookmarks == null) return Ok("Nothing to remove");
|
|
try
|
|
{
|
|
var bookmarksToRemove = user.Bookmarks.Where(bmk => bmk.SeriesId == dto.SeriesId).ToList();
|
|
user.Bookmarks = user.Bookmarks.Where(bmk => bmk.SeriesId != dto.SeriesId).ToList();
|
|
_unitOfWork.UserRepository.Update(user);
|
|
|
|
if (await _unitOfWork.CommitAsync())
|
|
{
|
|
try
|
|
{
|
|
await _bookmarkService.DeleteBookmarkFiles(bookmarksToRemove);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "There was an issue cleaning up old bookmarks");
|
|
}
|
|
return Ok();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "There was an exception when trying to clear bookmarks");
|
|
await _unitOfWork.RollbackAsync();
|
|
}
|
|
|
|
return BadRequest("Could not clear bookmarks");
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all bookmarked pages for a given volume
|
|
/// </summary>
|
|
/// <param name="volumeId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("get-volume-bookmarks")]
|
|
public async Task<ActionResult<IEnumerable<BookmarkDto>>> GetBookmarksForVolume(int volumeId)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Bookmarks);
|
|
if (user.Bookmarks == null) return Ok(Array.Empty<BookmarkDto>());
|
|
return Ok(await _unitOfWork.UserRepository.GetBookmarkDtosForVolume(user.Id, volumeId));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all bookmarked pages for a given series
|
|
/// </summary>
|
|
/// <param name="seriesId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("get-series-bookmarks")]
|
|
public async Task<ActionResult<IEnumerable<BookmarkDto>>> GetBookmarksForSeries(int seriesId)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Bookmarks);
|
|
if (user.Bookmarks == null) return Ok(Array.Empty<BookmarkDto>());
|
|
|
|
return Ok(await _unitOfWork.UserRepository.GetBookmarkDtosForSeries(user.Id, seriesId));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bookmarks a page against a Chapter
|
|
/// </summary>
|
|
/// <param name="bookmarkDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("bookmark")]
|
|
public async Task<ActionResult> BookmarkPage(BookmarkDto bookmarkDto)
|
|
{
|
|
// Don't let user save past total pages.
|
|
bookmarkDto.Page = await _readerService.CapPageToChapter(bookmarkDto.ChapterId, bookmarkDto.Page);
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Bookmarks);
|
|
var chapter = await _cacheService.Ensure(bookmarkDto.ChapterId);
|
|
if (chapter == null) return BadRequest("Could not find cached image. Reload and try again.");
|
|
var path = _cacheService.GetCachedPagePath(chapter, bookmarkDto.Page);
|
|
|
|
if (await _bookmarkService.BookmarkPage(user, bookmarkDto, path))
|
|
{
|
|
return Ok();
|
|
}
|
|
|
|
return BadRequest("Could not save bookmark");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes a bookmarked page for a Chapter
|
|
/// </summary>
|
|
/// <param name="bookmarkDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("unbookmark")]
|
|
public async Task<ActionResult> UnBookmarkPage(BookmarkDto bookmarkDto)
|
|
{
|
|
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Bookmarks);
|
|
if (user.Bookmarks == null) return Ok();
|
|
|
|
if (await _bookmarkService.RemoveBookmarkPage(user, bookmarkDto))
|
|
{
|
|
return Ok();
|
|
}
|
|
|
|
return BadRequest("Could not remove bookmark");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the next logical chapter from the series.
|
|
/// </summary>
|
|
/// <example>
|
|
/// V1 → V2 → V3 chapter 0 → V3 chapter 10 → SP 01 → SP 02
|
|
/// </example>
|
|
/// <param name="seriesId"></param>
|
|
/// <param name="volumeId"></param>
|
|
/// <param name="currentChapterId"></param>
|
|
/// <returns>chapter id for next manga</returns>
|
|
[HttpGet("next-chapter")]
|
|
public async Task<ActionResult<int>> GetNextChapter(int seriesId, int volumeId, int currentChapterId)
|
|
{
|
|
var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
|
|
return await _readerService.GetNextChapterIdAsync(seriesId, volumeId, currentChapterId, userId);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns the previous logical chapter from the series.
|
|
/// </summary>
|
|
/// <example>
|
|
/// V1 ← V2 ← V3 chapter 0 ← V3 chapter 10 ← SP 01 ← SP 02
|
|
/// </example>
|
|
/// <param name="seriesId"></param>
|
|
/// <param name="volumeId"></param>
|
|
/// <param name="currentChapterId"></param>
|
|
/// <returns>chapter id for next manga</returns>
|
|
[HttpGet("prev-chapter")]
|
|
public async Task<ActionResult<int>> GetPreviousChapter(int seriesId, int volumeId, int currentChapterId)
|
|
{
|
|
var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
|
|
return await _readerService.GetPrevChapterIdAsync(seriesId, volumeId, currentChapterId, userId);
|
|
}
|
|
|
|
}
|
|
}
|