mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
* Navigate users to library page instead of home to prevent history block. * Cleaned up the Contributing to describe new code structure * Fixed a critical bug for how we find files for a chapter download (use ChapterId for lookup, not MangaFile.Id). Refactored how downloading works on the UI side to use the backend's filename whenever possible, else provide a custom name (and use backend's extension) for bundled downloads. * Fixed a bug where scroll intersection wasn't working on books without a table of content, even though it should have. * If user is using a direct url and hits an authentication guard, cache the url, allow authentication, then redirect them to said url * Added a transaction for bookmarking due to a rare case (in dev machines) where bookmark progress can duplicate * Re-enabled webtoon preference in reader settings. Refactored gotopage into it's own, dedicated handler to simplify logic. * Moved the prefetching code to occur whenever the page number within infinite scroller changes. This results in an easier to understand functioning. * Fixed isElementVisible() which was not properly calculating element visibility * GoToPage going forwards is working as expected, going backwards is completly broken * After performing a gotopage, make sure we update the scrolling direction based on the delta. * Removed some stuff thats not used, split the prefetching code up into separate functions to prepare for a rewrite. * Reworked prefetching to ensure we have a buffer of pages around ourselves. It is not fully tested, but working much better than previous implementation. Will be enhanced with DOM Pruning. * Cleaned up some old cruft from the backend code * Cleaned up the webtoon page change handler to use setPageNum, which will handle the correct prefetching of next/prev chapter * More cleanup around the codebase * Refactored the code to use a map to keep track of what is loaded or not, which works better than max/min in cases where you jump to a page that doesn't have anything preloaded and loads images out of order * Fixed a bad placement of code for when you are unauthenticated, the code will now redirect to the original location you requested before you had to login. * Some cleanup. Fixed the scrolling issue with prev page, spec seems to not work on intersection observer. using 0.01 instead of 0.0.
101 lines
2.9 KiB
C#
101 lines
2.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using API.DTOs;
|
|
using API.Entities;
|
|
using API.Interfaces;
|
|
using AutoMapper;
|
|
using AutoMapper.QueryableExtensions;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace API.Data
|
|
{
|
|
public class VolumeRepository : IVolumeRepository
|
|
{
|
|
private readonly DataContext _context;
|
|
private readonly IMapper _mapper;
|
|
|
|
public VolumeRepository(DataContext context, IMapper mapper)
|
|
{
|
|
_context = context;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
public void Update(Volume volume)
|
|
{
|
|
_context.Entry(volume).State = EntityState.Modified;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a Chapter for an Id. Includes linked <see cref="MangaFile"/>s.
|
|
/// </summary>
|
|
/// <param name="chapterId"></param>
|
|
/// <returns></returns>
|
|
public async Task<Chapter> GetChapterAsync(int chapterId)
|
|
{
|
|
return await _context.Chapter
|
|
.Include(c => c.Files)
|
|
.SingleOrDefaultAsync(c => c.Id == chapterId);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns Chapters for a volume id.
|
|
/// </summary>
|
|
/// <param name="volumeId"></param>
|
|
/// <returns></returns>
|
|
public async Task<IList<Chapter>> GetChaptersAsync(int volumeId)
|
|
{
|
|
return await _context.Chapter
|
|
.Where(c => c.VolumeId == volumeId)
|
|
.ToListAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the cover image for a chapter id.
|
|
/// </summary>
|
|
/// <param name="chapterId"></param>
|
|
/// <returns></returns>
|
|
public async Task<byte[]> GetChapterCoverImageAsync(int chapterId)
|
|
{
|
|
return await _context.Chapter
|
|
.Where(c => c.Id == chapterId)
|
|
.Select(c => c.CoverImage)
|
|
.AsNoTracking()
|
|
.SingleOrDefaultAsync();
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<ChapterDto> GetChapterDtoAsync(int chapterId)
|
|
{
|
|
var chapter = await _context.Chapter
|
|
.Include(c => c.Files)
|
|
.ProjectTo<ChapterDto>(_mapper.ConfigurationProvider)
|
|
.AsNoTracking()
|
|
.SingleOrDefaultAsync(c => c.Id == chapterId);
|
|
|
|
return chapter;
|
|
}
|
|
|
|
public async Task<IList<MangaFile>> GetFilesForChapter(int chapterId)
|
|
{
|
|
return await _context.MangaFile
|
|
.Where(c => chapterId == c.ChapterId)
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<IList<MangaFile>> GetFilesForVolume(int volumeId)
|
|
{
|
|
return await _context.Chapter
|
|
.Where(c => volumeId == c.VolumeId)
|
|
.Include(c => c.Files)
|
|
.SelectMany(c => c.Files)
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
}
|
|
}
|
|
}
|