mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-13 14:57:53 +02:00
Add UpdateCoverJob.cs
Covers get updated on every pull If a Manga has no DownloadAvailableChaptersJob, Cover is removed Add endpoint POST Settings/CleanupCovers that removed covers not associated to any Manga
This commit is contained in:
@ -12,4 +12,5 @@ public enum JobType : byte
|
||||
UpdateChaptersDownloadedJob = 6,
|
||||
MoveMangaLibraryJob = 7,
|
||||
UpdateSingleChapterDownloadedJob = 8,
|
||||
UpdateCoversJob = 9,
|
||||
}
|
65
API/Schema/Jobs/UpdateCoverJob.cs
Normal file
65
API/Schema/Jobs/UpdateCoverJob.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using API.Schema.Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace API.Schema.Jobs;
|
||||
|
||||
public class UpdateCoverJob : Job
|
||||
{
|
||||
[StringLength(64)] [Required] public string MangaId { get; init; }
|
||||
|
||||
private Manga _manga = null!;
|
||||
|
||||
[JsonIgnore]
|
||||
public Manga Manga
|
||||
{
|
||||
get => LazyLoader.Load(this, ref _manga);
|
||||
init => _manga = value;
|
||||
}
|
||||
|
||||
|
||||
public UpdateCoverJob(Manga manga, ulong recurrenceMs, Job? parentJob = null, ICollection<Job>? dependsOnJobs = null)
|
||||
: base(TokenGen.CreateToken(typeof(UpdateCoverJob)), JobType.UpdateCoversJob, recurrenceMs, parentJob, dependsOnJobs)
|
||||
{
|
||||
this.MangaId = manga.MangaId;
|
||||
this.Manga = manga;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EF ONLY!!!
|
||||
/// </summary>
|
||||
internal UpdateCoverJob(ILazyLoader lazyLoader, string jobId, ulong recurrenceMs, string mangaId, string? parentJobId)
|
||||
: base(lazyLoader, jobId, JobType.UpdateCoversJob, recurrenceMs, parentJobId)
|
||||
{
|
||||
this.MangaId = mangaId;
|
||||
}
|
||||
|
||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
||||
{
|
||||
bool keepCover = context.Jobs
|
||||
.Any(job => job.JobType == JobType.DownloadAvailableChaptersJob
|
||||
&& ((DownloadAvailableChaptersJob)job).MangaId == MangaId);
|
||||
if (!keepCover)
|
||||
{
|
||||
if(File.Exists(Manga.CoverFileNameInCache))
|
||||
File.Delete(Manga.CoverFileNameInCache);
|
||||
try
|
||||
{
|
||||
Manga.CoverFileNameInCache = null;
|
||||
context.Jobs.Remove(this);
|
||||
context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateException e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return [new DownloadMangaCoverJob(Manga, this)];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user