mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-31 12:14:44 -04:00
* Refactored all the code that opens the reader to use a unified function. Added new library and setup basic pdf reader route. * Progress saving is implemented. Targeting ES6 now. * Customized the toolbar to remove things we don't want, made the download button download with correct filename. Adjusted zoom setting to work well on first load regardless of device. * Stream the pdf file to the UI rather than handling the download ourselves. * Started implementing a custom toolbar. * Fixed up the jump bar calculations * Fixed filtering being broken * Pushing up for Robbie to cleanup the toolbar layout * Added an additional button. Working on logic while robbie takes styling * Tried to fix the code for robbie * Tweaks for fonts * Added button for book mode, but doesn't seem to work after renderer is built * Removed book mode * Removed the old image caching code for pdfs as it's not needed with new reader * Removed the interfaces to extract images from pdf. * Fixed original pagination area not scaling correctly * Integrated series remove events to library detail * Cleaned up the getter naming convention * Cleaned up some of the manga reader code to reduce cluter and improve re-use * Implemented Japanese parser support for volume and chapters. * Fixed a bug where resetting scroll in manga reader wasn't working * Fixed a bug where word count grew on each scan. * Removed unused variable * Ensure we calculate word count on files with their own cache timestamp * Adjusted size of reel headers * Put some code in for moving on original image with keyboard, but it's not in use. * Cleaned up the css for the pdf reader * Cleaned up the code * Tweaked the list item so we show scrollbar now when fully read
95 lines
3.7 KiB
C#
95 lines
3.7 KiB
C#
using System;
|
|
using API.Entities;
|
|
using API.Entities.Interfaces;
|
|
using API.Services;
|
|
|
|
namespace API.Helpers;
|
|
|
|
public interface ICacheHelper
|
|
{
|
|
bool ShouldUpdateCoverImage(string coverPath, MangaFile firstFile, DateTime chapterCreated,
|
|
bool forceUpdate = false,
|
|
bool isCoverLocked = false);
|
|
|
|
bool CoverImageExists(string path);
|
|
|
|
bool HasFileNotChangedSinceCreationOrLastScan(IEntityDate chapter, bool forceUpdate, MangaFile firstFile);
|
|
bool HasFileChangedSinceLastScan(DateTime lastScan, bool forceUpdate, MangaFile firstFile);
|
|
|
|
}
|
|
|
|
public class CacheHelper : ICacheHelper
|
|
{
|
|
private readonly IFileService _fileService;
|
|
|
|
public CacheHelper(IFileService fileService)
|
|
{
|
|
_fileService = fileService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determines whether an entity should regenerate cover image.
|
|
/// </summary>
|
|
/// <remarks>If a cover image is locked but the underlying file has been deleted, this will allow regenerating. </remarks>
|
|
/// <param name="coverPath">This should just be the filename, no path information</param>
|
|
/// <param name="firstFile"></param>
|
|
/// <param name="chapterCreated">When the chapter was created (Not Used)</param>
|
|
/// <param name="forceUpdate">If the user has told us to force the refresh</param>
|
|
/// <param name="isCoverLocked">If cover has been locked by user. This will force false</param>
|
|
/// <returns></returns>
|
|
public bool ShouldUpdateCoverImage(string coverPath, MangaFile firstFile, DateTime chapterCreated, bool forceUpdate = false,
|
|
bool isCoverLocked = false)
|
|
{
|
|
|
|
var fileExists = !string.IsNullOrEmpty(coverPath) && _fileService.Exists(coverPath);
|
|
if (isCoverLocked && fileExists) return false;
|
|
if (forceUpdate) return true;
|
|
if (firstFile == null) return true;
|
|
return (_fileService.HasFileBeenModifiedSince(firstFile.FilePath, firstFile.LastModified)) || !fileExists;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Has the file been modified since last scan or is user forcing an update
|
|
/// </summary>
|
|
/// <param name="chapter"></param>
|
|
/// <param name="forceUpdate"></param>
|
|
/// <param name="firstFile"></param>
|
|
/// <returns></returns>
|
|
public bool HasFileNotChangedSinceCreationOrLastScan(IEntityDate chapter, bool forceUpdate, MangaFile firstFile)
|
|
{
|
|
return firstFile != null &&
|
|
(!forceUpdate &&
|
|
!(_fileService.HasFileBeenModifiedSince(firstFile.FilePath, chapter.Created)
|
|
|| _fileService.HasFileBeenModifiedSince(firstFile.FilePath, firstFile.LastModified)));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Has the file been modified since last scan or is user forcing an update
|
|
/// </summary>
|
|
/// <param name="lastScan"></param>
|
|
/// <param name="forceUpdate"></param>
|
|
/// <param name="firstFile"></param>
|
|
/// <returns></returns>
|
|
public bool HasFileChangedSinceLastScan(DateTime lastScan, bool forceUpdate, MangaFile firstFile)
|
|
{
|
|
if (firstFile == null) return false;
|
|
if (forceUpdate) return true;
|
|
return _fileService.HasFileBeenModifiedSince(firstFile.FilePath, lastScan)
|
|
|| _fileService.HasFileBeenModifiedSince(firstFile.FilePath, firstFile.LastModified);
|
|
// return firstFile != null &&
|
|
// (!forceUpdate &&
|
|
// !(_fileService.HasFileBeenModifiedSince(firstFile.FilePath, lastScan)
|
|
// || _fileService.HasFileBeenModifiedSince(firstFile.FilePath, firstFile.LastModified)));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determines if a given coverImage path exists
|
|
/// </summary>
|
|
/// <param name="path"></param>
|
|
/// <returns></returns>
|
|
public bool CoverImageExists(string path)
|
|
{
|
|
return !string.IsNullOrEmpty(path) && _fileService.Exists(path);
|
|
}
|
|
}
|