mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
Implemented the ability to move between volumes (reading) automatically without existing the app. (#198)
This commit is contained in:
parent
2be1630af3
commit
d92e9e7602
@ -239,5 +239,80 @@ namespace API.Controllers
|
||||
|
||||
return BadRequest("Could not save progress");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the next logical volume from the series.
|
||||
/// </summary>
|
||||
/// <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 user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
var volumes = await _unitOfWork.SeriesRepository.GetVolumesDtoAsync(seriesId, user.Id);
|
||||
var currentVolume = await _unitOfWork.SeriesRepository.GetVolumeAsync(volumeId);
|
||||
|
||||
var next = false;
|
||||
if (currentVolume.Number == 0)
|
||||
{
|
||||
foreach (var chapter in currentVolume.Chapters)
|
||||
{
|
||||
if (next)
|
||||
{
|
||||
return Ok(chapter.Id);
|
||||
}
|
||||
if (currentChapterId == chapter.Id) next = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var volume in volumes)
|
||||
{
|
||||
if (volume.Number == currentVolume.Number + 1)
|
||||
{
|
||||
return Ok(volume.Chapters.FirstOrDefault()?.Id);
|
||||
}
|
||||
}
|
||||
return Ok(-1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the previous logical volume from the series.
|
||||
/// </summary>
|
||||
/// <param name="seriesId"></param>
|
||||
/// <param name="volumeId"></param>
|
||||
/// <returns>chapter id for next manga</returns>
|
||||
[HttpGet("prev-chapter")]
|
||||
public async Task<ActionResult<int>> GetPreviousChapter(int seriesId, int volumeId, int currentChapterId)
|
||||
{
|
||||
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
var volumes = await _unitOfWork.SeriesRepository.GetVolumesDtoAsync(seriesId, user.Id);
|
||||
var currentVolume = await _unitOfWork.SeriesRepository.GetVolumeAsync(volumeId);
|
||||
|
||||
var next = false;
|
||||
if (currentVolume.Number == 0)
|
||||
{
|
||||
var chapters = currentVolume.Chapters.Reverse();
|
||||
foreach (var chapter in chapters)
|
||||
{
|
||||
if (next)
|
||||
{
|
||||
return Ok(chapter.Id);
|
||||
}
|
||||
if (currentChapterId == chapter.Id) next = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var volume in volumes.Reverse())
|
||||
{
|
||||
if (volume.Number == currentVolume.Number - 1)
|
||||
{
|
||||
return Ok(volume.Chapters.LastOrDefault()?.Id);
|
||||
}
|
||||
}
|
||||
return Ok(-1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
@ -89,18 +90,7 @@ namespace API.Controllers
|
||||
return Ok(await _unitOfWork.VolumeRepository.GetChapterDtoAsync(chapterId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the next logical volume from the series.
|
||||
/// </summary>
|
||||
/// <param name="seriesId"></param>
|
||||
/// <param name="volumeId"></param>
|
||||
/// <returns>chapter id for next manga</returns>
|
||||
[HttpGet("next-volume")]
|
||||
public async Task<ActionResult<int>> GetNextChapter(int seriesId, int volumeId)
|
||||
{
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpPost("update-rating")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user