2024-12-14 21:53:29 +01:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using API.Schema.MangaConnectors;
|
|
|
|
|
|
|
|
|
|
namespace API.Schema.Jobs;
|
|
|
|
|
|
2025-01-09 01:34:03 +01:00
|
|
|
|
public class DownloadNewChaptersJob(ulong recurrenceMs, string mangaId, string? parentJobId = null, ICollection<string>? dependsOnJobsIds = null)
|
2025-01-25 11:57:54 +01:00
|
|
|
|
: Job(TokenGen.CreateToken(typeof(DownloadNewChaptersJob), ""), JobType.DownloadNewChaptersJob, recurrenceMs, parentJobId, dependsOnJobsIds)
|
2024-12-14 21:53:29 +01:00
|
|
|
|
{
|
|
|
|
|
[MaxLength(64)]
|
|
|
|
|
public string MangaId { get; init; } = mangaId;
|
2025-01-09 01:34:03 +01:00
|
|
|
|
public Manga? Manga { get; init; }
|
2024-12-14 21:53:29 +01:00
|
|
|
|
|
2024-12-17 17:24:25 +01:00
|
|
|
|
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
2024-12-14 21:53:29 +01:00
|
|
|
|
{
|
2025-01-09 01:34:03 +01:00
|
|
|
|
Manga m = Manga ?? context.Manga.Find(MangaId)!;
|
|
|
|
|
MangaConnector connector = m.MangaConnector ?? context.MangaConnectors.Find(m.MangaConnectorId)!;
|
|
|
|
|
Chapter[] newChapters = connector.GetNewChapters(m);
|
2024-12-17 17:24:25 +01:00
|
|
|
|
context.Chapters.AddRangeAsync(newChapters).Wait();
|
2025-01-09 01:34:03 +01:00
|
|
|
|
context.SaveChangesAsync().Wait();
|
2024-12-14 21:53:29 +01:00
|
|
|
|
return newChapters.Select(chapter => new DownloadSingleChapterJob(chapter.ChapterId, this.JobId));
|
|
|
|
|
}
|
|
|
|
|
}
|