Estimated time is coded up.
This commit is contained in:
parent
ab6669703d
commit
64ee5ee459
10 changed files with 38 additions and 51 deletions
|
|
@ -10,4 +10,8 @@ namespace API.Controllers;
|
|||
[Authorize]
|
||||
public class BaseApiController : ControllerBase
|
||||
{
|
||||
public BaseApiController()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,13 +41,12 @@ public class BookController : BaseApiController
|
|||
/// <param name="chapterId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{chapterId}/book-info")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour, VaryByQueryKeys = ["chapterId", "includeWordCounts"])]
|
||||
public async Task<ActionResult<BookInfoDto>> GetBookInfo(int chapterId, bool includeWordCounts = false)
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour, VaryByQueryKeys = ["chapterId"])]
|
||||
public async Task<ActionResult<BookInfoDto>> GetBookInfo(int chapterId)
|
||||
{
|
||||
var dto = await _unitOfWork.ChapterRepository.GetChapterInfoDtoAsync(chapterId);
|
||||
if (dto == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "chapter-doesnt-exist"));
|
||||
var bookTitle = string.Empty;
|
||||
IDictionary<int, int>? pageWordCounts = null;
|
||||
|
||||
switch (dto.SeriesFormat)
|
||||
{
|
||||
|
|
@ -57,11 +56,6 @@ public class BookController : BaseApiController
|
|||
using var book = await EpubReader.OpenBookAsync(mangaFile.FilePath, BookService.LenientBookReaderOptions);
|
||||
bookTitle = book.Title;
|
||||
|
||||
if (includeWordCounts)
|
||||
{
|
||||
// TODO: Cache this in temp/chapterId folder to avoid having to process file each time
|
||||
pageWordCounts = await _bookService.GetWordCountsPerPage(mangaFile.FilePath);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MangaFormat.Pdf:
|
||||
|
|
@ -94,7 +88,6 @@ public class BookController : BaseApiController
|
|||
LibraryId = dto.LibraryId,
|
||||
IsSpecial = dto.IsSpecial,
|
||||
Pages = dto.Pages,
|
||||
PageWordCounts = pageWordCounts
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ using API.Entities.Enums;
|
|||
using API.Extensions;
|
||||
using API.Services;
|
||||
using API.Services.Plus;
|
||||
using API.Services.Tasks.Metadata;
|
||||
using API.SignalR;
|
||||
using Hangfire;
|
||||
using Kavita.Common;
|
||||
|
|
@ -222,7 +223,6 @@ public class ReaderController : BaseApiController
|
|||
/// <param name="chapterId"></param>
|
||||
/// <param name="extractPdf">Should Kavita extract pdf into images. Defaults to false.</param>
|
||||
/// <param name="includeDimensions">Include file dimensions. Only useful for image-based reading</param>
|
||||
/// <param name="includeWordCounts">Include epub word counts per page. Only useful for epub-based reading</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("chapter-info")]
|
||||
[ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour, VaryByQueryKeys = ["chapterId", "extractPdf", "includeDimensions"])]
|
||||
|
|
@ -849,10 +849,18 @@ public class ReaderController : BaseApiController
|
|||
// Patch in the reading progress
|
||||
await _unitOfWork.ChapterRepository.AddChapterModifiers(User.GetUserId(), chapter);
|
||||
|
||||
// TODO: We need to actually use word count from the pages
|
||||
if (series.Format == MangaFormat.Epub)
|
||||
{
|
||||
var progressCount = chapter.WordCount;
|
||||
// Get the word counts for all the pages
|
||||
var pageCounts = await _bookService.GetWordCountsPerPage(chapter.Files.First().FilePath); // TODO: Cache
|
||||
if (pageCounts == null) return _readerService.GetTimeEstimate(series.WordCount, 0, true);
|
||||
|
||||
// Sum character counts only for pages that have been read
|
||||
var totalCharactersRead = pageCounts
|
||||
.Where(kvp => kvp.Key <= chapter.PagesRead)
|
||||
.Sum(kvp => kvp.Value);
|
||||
|
||||
var progressCount = WordCountAnalyzerService.GetWordCount(totalCharactersRead);
|
||||
var wordsLeft = series.WordCount - progressCount;
|
||||
return _readerService.GetTimeEstimate(wordsLeft, 0, true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue