mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-07 15:44:16 -04:00
* Tweaked the logging output * Started implementing some basic idea for devices * Updated Email Service with new API routes * Implemented basic DB structure and some APIs to prep for the UI and flows. * Added an abstract class to make Unit testing easier. * Removed dependency we don't need * Updated the UI to be able to show devices and add new devices. Email field will update the platform if the user hasn't interacted with it already. * Added ability to delete a device as well * Basic ability to send files to devices works * Refactored Action code to pass ActionItem back and allow for dynamic children based on an Observable (api). Hooked in ability to send a chapter to a device. There is no logic in the FE to validate type. * Fixed a broken unit test * Implemented the ability to edit a device * Code cleanup * Fixed a bad success message * Fixed broken unit test from updating mock layer
91 lines
3.6 KiB
C#
91 lines
3.6 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 IsFileUnmodifiedSinceCreationOrLastScan(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 not 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 IsFileUnmodifiedSinceCreationOrLastScan(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">Last time the scan was performed on this file</param>
|
|
/// <param name="forceUpdate">Should we ignore any logic and force this to return true</param>
|
|
/// <param name="firstFile">The file in question</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);
|
|
}
|
|
|
|
/// <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);
|
|
}
|
|
}
|