mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-17 00:37:54 +02:00
Add NewtonsoftJson to Swagger
Add RetrieveChaptersJob.cs Add UpdateFilesDownloadedJob.cs Remove DownloadNewChaptersJob.cs and instead use DownloadAvailableChaptersJob.cs
This commit is contained in:
36
API/Schema/Jobs/RetrieveChaptersJob.cs
Normal file
36
API/Schema/Jobs/RetrieveChaptersJob.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using API.Schema.MangaConnectors;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace API.Schema.Jobs;
|
||||
|
||||
public class RetrieveChaptersJob(ulong recurrenceMs, string mangaId, string? parentJobId = null, ICollection<string>? dependsOnJobsIds = null)
|
||||
: Job(TokenGen.CreateToken(typeof(RetrieveChaptersJob)), JobType.RetrieveChaptersJob, recurrenceMs, parentJobId, dependsOnJobsIds)
|
||||
{
|
||||
[MaxLength(64)]
|
||||
public string MangaId { get; init; } = mangaId;
|
||||
|
||||
[JsonIgnore]
|
||||
public Manga? Manga { get; init; }
|
||||
|
||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
||||
{
|
||||
/*
|
||||
* For some reason, directly using Manga from above instead of finding it again causes DBContext to consider
|
||||
* Manga as a new entity and Postgres throws a Duplicate PK exception.
|
||||
* m.MangaConnector does not have this issue (IDK why).
|
||||
*/
|
||||
Manga m = context.Manga.Find(MangaId)!;
|
||||
MangaConnector connector = context.MangaConnectors.Find(m.MangaConnectorId)!;
|
||||
// This gets all chapters that are not downloaded
|
||||
Chapter[] allNewChapters = connector.GetNewChapters(m);
|
||||
|
||||
// This filters out chapters that are not downloaded but already exist in the DB
|
||||
string[] chapterIds = context.Chapters.Where(chapter => chapter.ParentMangaId == m.MangaId).Select(chapter => chapter.ChapterId).ToArray();
|
||||
Chapter[] newChapters = allNewChapters.Where(chapter => !chapterIds.Contains(chapter.ChapterId)).ToArray();
|
||||
context.Chapters.AddRangeAsync(newChapters).Wait();
|
||||
context.SaveChangesAsync().Wait();
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user