From a90a6fb2000c84797dc2c74025a94e0ef5b0c436 Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 3 Jul 2025 21:11:33 +0200 Subject: [PATCH] Enable Manga Downloading --- API/Controllers/MangaController.cs | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/API/Controllers/MangaController.cs b/API/Controllers/MangaController.cs index b9cd627..e014e8f 100644 --- a/API/Controllers/MangaController.cs +++ b/API/Controllers/MangaController.cs @@ -359,4 +359,46 @@ public class MangaController(IServiceScope scope) : Controller return Accepted(); } + + /// + /// (Un-)Marks as requested for Download from + /// + /// with + /// with + /// true to mark as requested, false to mark as not-requested + /// + /// or not found + /// was not linked to , so nothing changed + /// is not linked to yet. Search for on first (to create a ). + /// Error during Database Operation + [HttpPost("{MangaId}/SetAsDownloadFrom/{MangaConnectorName}/{IsIsRequested}")] + [ProducesResponseType(Status200OK)] + [ProducesResponseType(Status404NotFound, "text/plain")] + [ProducesResponseType(Status412PreconditionFailed, "text/plain")] + [ProducesResponseType(Status428PreconditionRequired, "text/plain")] + [ProducesResponseType(Status500InternalServerError, "text/plain")] + public IActionResult MarkAsRequested(string MangaId, string MangaConnectorName, bool IsRequested) + { + MangaContext context = scope.ServiceProvider.GetRequiredService(); + if (context.Mangas.Find(MangaId) is null) + return NotFound(nameof(MangaId)); + if(context.MangaConnectors.Find(MangaConnectorName) is null) + return NotFound(nameof(MangaConnectorName)); + + if (context.MangaConnectorToManga.FirstOrDefault(id => id.MangaConnectorName == MangaConnectorName && id.ObjId == MangaId) is not { } mcId) + if(IsRequested) + return StatusCode(Status428PreconditionRequired, "Don't know how to download this Manga from MangaConnector"); + else + return StatusCode(Status412PreconditionFailed, "Not linked anyways."); + + mcId.UseForDownload = IsRequested; + if(context.Sync().Result is { success: false } result) + return StatusCode(Status500InternalServerError, result.exceptionMessage); + + DownloadCoverFromMangaconnectorWorker downloadCover = new(mcId); + RetrieveMangaChaptersFromMangaconnectorWorker retrieveChapters = new(mcId, Tranga.Settings.DownloadLanguage); + Tranga.AddWorkers([downloadCover, retrieveChapters]); + + return Ok(); + } } \ No newline at end of file