mirror of
https://github.com/C9Glax/tranga.git
synced 2025-10-17 10:50:45 +02:00
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using API.MangaConnectors;
|
||||
using API.Schema.ActionsContext;
|
||||
using API.Schema.ActionsContext.Actions;
|
||||
using API.Schema.MangaContext;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -8,16 +11,28 @@ namespace API.Workers.MangaDownloadWorkers;
|
||||
/// Downloads the cover for Manga from Mangaconnector
|
||||
/// </summary>
|
||||
public class DownloadCoverFromMangaconnectorWorker(MangaConnectorId<Manga> mcId, IEnumerable<BaseWorker>? dependsOn = null)
|
||||
: BaseWorkerWithContext<MangaContext>(dependsOn)
|
||||
: BaseWorkerWithContexts(dependsOn)
|
||||
{
|
||||
internal readonly string MangaConnectorIdId = mcId.Key;
|
||||
private readonly string _mangaConnectorIdId = mcId.Key;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
private MangaContext MangaContext = null!;
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
private ActionsContext ActionsContext = null!;
|
||||
|
||||
protected override void SetContexts(IServiceScope serviceScope)
|
||||
{
|
||||
MangaContext = GetContext<MangaContext>(serviceScope);
|
||||
ActionsContext = GetContext<ActionsContext>(serviceScope);
|
||||
}
|
||||
|
||||
protected override async Task<BaseWorker[]> DoWorkInternal()
|
||||
{
|
||||
Log.Debug($"Getting Cover for MangaConnectorId {MangaConnectorIdId}...");
|
||||
Log.Debug($"Getting Cover for MangaConnectorId {_mangaConnectorIdId}...");
|
||||
// Getting MangaConnector info
|
||||
if (await DbContext.MangaConnectorToManga
|
||||
if (await MangaContext.MangaConnectorToManga
|
||||
.Include(id => id.Obj)
|
||||
.FirstOrDefaultAsync(c => c.Key == MangaConnectorIdId, CancellationToken) is not { } mangaConnectorId)
|
||||
.FirstOrDefaultAsync(c => c.Key == _mangaConnectorIdId, CancellationToken) is not { } mangaConnectorId)
|
||||
{
|
||||
Log.Error("Could not get MangaConnectorId.");
|
||||
return []; //TODO Exception?
|
||||
@@ -35,13 +50,17 @@ public class DownloadCoverFromMangaconnectorWorker(MangaConnectorId<Manga> mcId,
|
||||
Log.Error($"Could not get Cover for MangaConnectorId {mangaConnectorId}.");
|
||||
return [];
|
||||
}
|
||||
DbContext.Entry(mangaConnectorId.Obj).Property(m => m.CoverFileNameInCache).CurrentValue = coverFileName;
|
||||
MangaContext.Entry(mangaConnectorId.Obj).Property(m => m.CoverFileNameInCache).CurrentValue = coverFileName;
|
||||
|
||||
if(await DbContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } e)
|
||||
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
|
||||
if(await MangaContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } mangaContextException)
|
||||
Log.Error($"Failed to save database changes: {mangaContextException.exceptionMessage}");
|
||||
|
||||
ActionsContext.Actions.Add(new CoverDownloadedActionRecord(mcId.Obj, coverFileName));
|
||||
if(await MangaContext.Sync(CancellationToken, GetType(), "Download complete") is { success: false } actionsContextException)
|
||||
Log.Error($"Failed to save database changes: {actionsContextException.exceptionMessage}");
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public override string ToString() => $"{base.ToString()} {MangaConnectorIdId}";
|
||||
public override string ToString() => $"{base.ToString()} {_mangaConnectorIdId}";
|
||||
}
|
Reference in New Issue
Block a user