From e8d612557f91da4b707e06569a898aadff8446c4 Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 3 Jul 2025 22:39:06 +0200 Subject: [PATCH] Fix TrangaBaseContext.Sync --- API/Controllers/FileLibraryController.cs | 17 ++++--------- API/Controllers/LibraryConnectorController.cs | 11 +++------ API/Controllers/MangaConnectorController.cs | 9 ++----- API/Controllers/MangaController.cs | 24 ++++--------------- API/Controllers/MetadataFetcherController.cs | 11 +++------ .../NotificationConnectorController.cs | 10 +++----- API/Controllers/QueryController.cs | 6 +---- API/Controllers/SearchController.cs | 4 +--- API/Controllers/SettingsController.cs | 11 ++------- API/Controllers/WorkerController.cs | 2 +- .../MetadataFetchers/MyAnimeList.cs | 2 +- API/Schema/TrangaBaseContext.cs | 4 ++-- API/Tranga.cs | 4 ++-- API/Workers/MoveMangaLibraryWorker.cs | 4 ++-- 14 files changed, 33 insertions(+), 86 deletions(-) diff --git a/API/Controllers/FileLibraryController.cs b/API/Controllers/FileLibraryController.cs index ff0d535..84e52bf 100644 --- a/API/Controllers/FileLibraryController.cs +++ b/API/Controllers/FileLibraryController.cs @@ -9,7 +9,7 @@ namespace API.Controllers; [ApiVersion(2)] [ApiController] [Route("v{v:apiVersion}/[controller]")] -public class FileLibraryController(IServiceScope scope) : Controller +public class FileLibraryController(MangaContext context) : Controller { /// /// Returns all @@ -19,8 +19,6 @@ public class FileLibraryController(IServiceScope scope) : Controller [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetFileLibraries() { - MangaContext context = scope.ServiceProvider.GetRequiredService(); - return Ok(context.FileLibraries.ToArray()); } @@ -35,7 +33,6 @@ public class FileLibraryController(IServiceScope scope) : Controller [ProducesResponseType(Status404NotFound)] public IActionResult GetFileLibrary(string FileLibraryId) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.FileLibraries.Find(FileLibraryId) is not { } library) return NotFound(); @@ -56,14 +53,13 @@ public class FileLibraryController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public IActionResult ChangeLibraryBasePath(string FileLibraryId, [FromBody]string newBasePath) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.FileLibraries.Find(FileLibraryId) is not { } library) return NotFound(); //TODO Path check library.BasePath = newBasePath; - if(context.Sync().Result is { success: false } result) + if(context.Sync() is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); return Ok(); } @@ -83,14 +79,13 @@ public class FileLibraryController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public IActionResult ChangeLibraryName(string FileLibraryId, [FromBody] string newName) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.FileLibraries.Find(FileLibraryId) is not { } library) return NotFound(); //TODO Name check library.LibraryName = newName; - if(context.Sync().Result is { success: false } result) + if(context.Sync() is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); return Ok(); } @@ -106,12 +101,11 @@ public class FileLibraryController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public IActionResult CreateNewLibrary([FromBody]FileLibrary library) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); //TODO Parameter check context.FileLibraries.Add(library); - if(context.Sync().Result is { success: false } result) + if(context.Sync() is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); return Created(); } @@ -128,13 +122,12 @@ public class FileLibraryController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public IActionResult DeleteLocalLibrary(string FileLibraryId) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.FileLibraries.Find(FileLibraryId) is not { } library) return NotFound(); context.FileLibraries.Remove(library); - if(context.Sync().Result is { success: false } result) + if(context.Sync() is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); return Ok(); } diff --git a/API/Controllers/LibraryConnectorController.cs b/API/Controllers/LibraryConnectorController.cs index 4aa30ae..d1f934c 100644 --- a/API/Controllers/LibraryConnectorController.cs +++ b/API/Controllers/LibraryConnectorController.cs @@ -10,7 +10,7 @@ namespace API.Controllers; [ApiVersion(2)] [ApiController] [Route("v{v:apiVersion}/[controller]")] -public class LibraryConnectorController(IServiceScope scope) : Controller +public class LibraryConnectorController(LibraryContext context) : Controller { /// /// Gets all configured @@ -20,8 +20,6 @@ public class LibraryConnectorController(IServiceScope scope) : Controller [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetAllConnectors() { - LibraryContext context = scope.ServiceProvider.GetRequiredService(); - LibraryConnector[] connectors = context.LibraryConnectors.ToArray(); return Ok(connectors); @@ -38,7 +36,6 @@ public class LibraryConnectorController(IServiceScope scope) : Controller [ProducesResponseType(Status404NotFound)] public IActionResult GetConnector(string LibraryConnectorId) { - LibraryContext context = scope.ServiceProvider.GetRequiredService(); if (context.LibraryConnectors.Find(LibraryConnectorId) is not { } connector) return NotFound(); @@ -56,11 +53,10 @@ public class LibraryConnectorController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public IActionResult CreateConnector([FromBody]LibraryConnector libraryConnector) { - LibraryContext context = scope.ServiceProvider.GetRequiredService(); context.LibraryConnectors.Add(libraryConnector); - if(context.Sync().Result is { success: false } result) + if(context.Sync() is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); return Created(); } @@ -78,13 +74,12 @@ public class LibraryConnectorController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public IActionResult DeleteConnector(string LibraryConnectorId) { - LibraryContext context = scope.ServiceProvider.GetRequiredService(); if (context.LibraryConnectors.Find(LibraryConnectorId) is not { } connector) return NotFound(); context.LibraryConnectors.Remove(connector); - if(context.Sync().Result is { success: false } result) + if(context.Sync() is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); return Ok(); } diff --git a/API/Controllers/MangaConnectorController.cs b/API/Controllers/MangaConnectorController.cs index 0487e6a..bf7436f 100644 --- a/API/Controllers/MangaConnectorController.cs +++ b/API/Controllers/MangaConnectorController.cs @@ -10,7 +10,7 @@ namespace API.Controllers; [ApiVersion(2)] [ApiController] [Route("v{v:apiVersion}/[controller]")] -public class MangaConnectorController(IServiceScope scope) : Controller +public class MangaConnectorController(MangaContext context) : Controller { /// /// Get all (Scanlation-Sites) @@ -20,7 +20,6 @@ public class MangaConnectorController(IServiceScope scope) : Controller [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetConnectors() { - MangaContext context = scope.ServiceProvider.GetRequiredService(); return Ok(context.MangaConnectors.Select(c => c.Name).ToArray()); } @@ -35,7 +34,6 @@ public class MangaConnectorController(IServiceScope scope) : Controller [ProducesResponseType(Status404NotFound)] public IActionResult GetConnector(string MangaConnectorName) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if(context.MangaConnectors.Find(MangaConnectorName) is not { } connector) return NotFound(); @@ -50,7 +48,6 @@ public class MangaConnectorController(IServiceScope scope) : Controller [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetEnabledConnectors() { - MangaContext context = scope.ServiceProvider.GetRequiredService(); return Ok(context.MangaConnectors.Where(c => c.Enabled).ToArray()); } @@ -63,7 +60,6 @@ public class MangaConnectorController(IServiceScope scope) : Controller [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetDisabledConnectors() { - MangaContext context = scope.ServiceProvider.GetRequiredService(); return Ok(context.MangaConnectors.Where(c => c.Enabled == false).ToArray()); } @@ -82,13 +78,12 @@ public class MangaConnectorController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public IActionResult SetEnabled(string MangaConnectorName, bool Enabled) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if(context.MangaConnectors.Find(MangaConnectorName) is not { } connector) return NotFound(); connector.Enabled = Enabled; - if(context.Sync().Result is { success: false } result) + if(context.Sync() is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); return Accepted(); } diff --git a/API/Controllers/MangaController.cs b/API/Controllers/MangaController.cs index e014e8f..58fc6a5 100644 --- a/API/Controllers/MangaController.cs +++ b/API/Controllers/MangaController.cs @@ -16,7 +16,7 @@ namespace API.Controllers; [ApiVersion(2)] [ApiController] [Route("v{v:apiVersion}/[controller]")] -public class MangaController(IServiceScope scope) : Controller +public class MangaController(MangaContext context) : Controller { /// /// Returns all cached @@ -26,7 +26,6 @@ public class MangaController(IServiceScope scope) : Controller [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetAllManga() { - MangaContext context = scope.ServiceProvider.GetRequiredService(); Manga[] ret = context.Mangas.ToArray(); return Ok(ret); } @@ -40,7 +39,6 @@ public class MangaController(IServiceScope scope) : Controller [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetManga([FromBody]string[] MangaIds) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); Manga[] ret = context.Mangas.Where(m => MangaIds.Contains(m.Key)).ToArray(); return Ok(ret); } @@ -56,7 +54,6 @@ public class MangaController(IServiceScope scope) : Controller [ProducesResponseType(Status404NotFound)] public IActionResult GetManga(string MangaId) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Mangas.Find(MangaId) is not { } manga) return NotFound(nameof(MangaId)); return Ok(manga); @@ -75,13 +72,12 @@ public class MangaController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public IActionResult DeleteManga(string MangaId) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Mangas.Find(MangaId) is not { } manga) return NotFound(nameof(MangaId)); context.Mangas.Remove(manga); - if(context.Sync().Result is { success: false } result) + if(context.Sync() is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); return Ok(); } @@ -99,7 +95,6 @@ public class MangaController(IServiceScope scope) : Controller [ProducesResponseType(Status404NotFound)] public IActionResult MergeIntoManga(string MangaIdFrom, string MangaIdInto) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Mangas.Find(MangaIdFrom) is not { } from) return NotFound(nameof(MangaIdFrom)); if (context.Mangas.Find(MangaIdInto) is not { } into) @@ -130,7 +125,6 @@ public class MangaController(IServiceScope scope) : Controller [ProducesResponseType(Status503ServiceUnavailable, "text/plain")] public IActionResult GetCover(string MangaId, [FromQuery]int? width, [FromQuery]int? height) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Mangas.Find(MangaId) is not { } manga) return NotFound(nameof(MangaId)); @@ -176,7 +170,6 @@ public class MangaController(IServiceScope scope) : Controller [ProducesResponseType(Status404NotFound)] public IActionResult GetChapters(string MangaId) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Mangas.Find(MangaId) is not { } manga) return NotFound(nameof(MangaId)); @@ -197,7 +190,6 @@ public class MangaController(IServiceScope scope) : Controller [ProducesResponseType(Status404NotFound)] public IActionResult GetChaptersDownloaded(string MangaId) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Mangas.Find(MangaId) is not { } manga) return NotFound(nameof(MangaId)); @@ -221,7 +213,6 @@ public class MangaController(IServiceScope scope) : Controller [ProducesResponseType(Status404NotFound)] public IActionResult GetChaptersNotDownloaded(string MangaId) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Mangas.Find(MangaId) is not { } manga) return NotFound(nameof(MangaId)); @@ -249,7 +240,6 @@ public class MangaController(IServiceScope scope) : Controller [ProducesResponseType(Status503ServiceUnavailable, "text/plain")] public IActionResult GetLatestChapter(string MangaId) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Mangas.Find(MangaId) is not { } manga) return NotFound(nameof(MangaId)); @@ -288,7 +278,6 @@ public class MangaController(IServiceScope scope) : Controller [ProducesResponseType(Status503ServiceUnavailable, "text/plain")] public IActionResult GetLatestChapterDownloaded(string MangaId) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Mangas.Find(MangaId) is not { } manga) return NotFound(nameof(MangaId)); @@ -324,12 +313,11 @@ public class MangaController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public IActionResult IgnoreChaptersBefore(string MangaId, [FromBody]float chapterThreshold) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Mangas.Find(MangaId) is not { } manga) return NotFound(); manga.IgnoreChaptersBefore = chapterThreshold; - if(context.Sync().Result is { success: false } result) + if(context.Sync() is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); return Accepted(); @@ -347,13 +335,12 @@ public class MangaController(IServiceScope scope) : Controller [ProducesResponseType(Status404NotFound)] public IActionResult MoveFolder(string MangaId, string LibraryId) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Mangas.Find(MangaId) is not { } manga) return NotFound(nameof(MangaId)); if(context.FileLibraries.Find(LibraryId) is not { } library) return NotFound(nameof(LibraryId)); - MoveMangaLibraryWorker moveLibrary = new(manga, library, scope); + MoveMangaLibraryWorker moveLibrary = new(manga, library); Tranga.AddWorkers([moveLibrary]); @@ -379,7 +366,6 @@ public class MangaController(IServiceScope scope) : Controller [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) @@ -392,7 +378,7 @@ public class MangaController(IServiceScope scope) : Controller return StatusCode(Status412PreconditionFailed, "Not linked anyways."); mcId.UseForDownload = IsRequested; - if(context.Sync().Result is { success: false } result) + if(context.Sync() is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); DownloadCoverFromMangaconnectorWorker downloadCover = new(mcId); diff --git a/API/Controllers/MetadataFetcherController.cs b/API/Controllers/MetadataFetcherController.cs index 6785df7..6950a3c 100644 --- a/API/Controllers/MetadataFetcherController.cs +++ b/API/Controllers/MetadataFetcherController.cs @@ -11,7 +11,7 @@ namespace API.Controllers; [ApiVersion(2)] [ApiController] [Route("v{v:apiVersion}/[controller]")] -public class MetadataFetcherController(IServiceScope scope) : Controller +public class MetadataFetcherController(MangaContext context) : Controller { /// /// Get all (Metadata-Sites) @@ -32,8 +32,6 @@ public class MetadataFetcherController(IServiceScope scope) : Controller [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetLinkedEntries() { - MangaContext context = scope.ServiceProvider.GetRequiredService(); - return Ok(context.MetadataEntries.ToArray()); } @@ -52,7 +50,6 @@ public class MetadataFetcherController(IServiceScope scope) : Controller [ProducesResponseType(Status404NotFound)] public IActionResult SearchMangaMetadata(string MangaId, string MetadataFetcherName, [FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)]string? searchTerm = null) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if(context.Mangas.Find(MangaId) is not { } manga) return NotFound(); if(Tranga.MetadataFetchers.FirstOrDefault(f => f.Name == MetadataFetcherName) is not { } fetcher) @@ -79,7 +76,6 @@ public class MetadataFetcherController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public IActionResult LinkMangaMetadata(string MangaId, string MetadataFetcherName, [FromBody]string Identifier) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if(context.Mangas.Find(MangaId) is not { } manga) return NotFound(); if(Tranga.MetadataFetchers.FirstOrDefault(f => f.Name == MetadataFetcherName) is not { } fetcher) @@ -88,7 +84,7 @@ public class MetadataFetcherController(IServiceScope scope) : Controller MetadataEntry entry = fetcher.CreateMetadataEntry(manga, Identifier); context.MetadataEntries.Add(entry); - if(context.Sync().Result is { } errorMessage) + if(context.Sync() is { } errorMessage) return StatusCode(Status500InternalServerError, errorMessage); return Ok(entry); } @@ -109,7 +105,6 @@ public class MetadataFetcherController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public IActionResult UnlinkMangaMetadata(string MangaId, string MetadataFetcherName) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if(context.Mangas.Find(MangaId) is null) return NotFound(); if(Tranga.MetadataFetchers.FirstOrDefault(f => f.Name == MetadataFetcherName) is null) @@ -119,7 +114,7 @@ public class MetadataFetcherController(IServiceScope scope) : Controller context.Remove(entry); - if(context.Sync().Result is { success: false } result) + if(context.Sync() is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); return Ok(); } diff --git a/API/Controllers/NotificationConnectorController.cs b/API/Controllers/NotificationConnectorController.cs index cac14e4..157e0f5 100644 --- a/API/Controllers/NotificationConnectorController.cs +++ b/API/Controllers/NotificationConnectorController.cs @@ -13,7 +13,7 @@ namespace API.Controllers; [ApiController] [Produces("application/json")] [Route("v{v:apiVersion}/[controller]")] -public class NotificationConnectorController(IServiceScope scope) : Controller +public class NotificationConnectorController(NotificationsContext context) : Controller { /// /// Gets all configured @@ -23,7 +23,6 @@ public class NotificationConnectorController(IServiceScope scope) : Controller [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetAllConnectors() { - NotificationsContext context = scope.ServiceProvider.GetRequiredService(); return Ok(context.NotificationConnectors.ToArray()); } @@ -39,7 +38,6 @@ public class NotificationConnectorController(IServiceScope scope) : Controller [ProducesResponseType(Status404NotFound)] public IActionResult GetConnector(string Name) { - NotificationsContext context = scope.ServiceProvider.GetRequiredService(); if(context.NotificationConnectors.Find(Name) is not { } connector) return NotFound(); @@ -58,11 +56,10 @@ public class NotificationConnectorController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public IActionResult CreateConnector([FromBody]NotificationConnector notificationConnector) { - NotificationsContext context = scope.ServiceProvider.GetRequiredService(); context.NotificationConnectors.Add(notificationConnector); - if(context.Sync().Result is { success: false } result) + if(context.Sync() is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); return Created(); } @@ -150,13 +147,12 @@ public class NotificationConnectorController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public IActionResult DeleteConnector(string Name) { - NotificationsContext context = scope.ServiceProvider.GetRequiredService(); if(context.NotificationConnectors.Find(Name) is not { } connector) return NotFound(); context.NotificationConnectors.Remove(connector); - if(context.Sync().Result is { success: false } result) + if(context.Sync() is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); return Created(); } diff --git a/API/Controllers/QueryController.cs b/API/Controllers/QueryController.cs index 3341162..72ff801 100644 --- a/API/Controllers/QueryController.cs +++ b/API/Controllers/QueryController.cs @@ -9,7 +9,7 @@ namespace API.Controllers; [ApiVersion(2)] [ApiController] [Route("v{v:apiVersion}/[controller]")] -public class QueryController(IServiceScope scope) : Controller +public class QueryController(MangaContext context) : Controller { /// /// Returns the with @@ -22,7 +22,6 @@ public class QueryController(IServiceScope scope) : Controller [ProducesResponseType(Status404NotFound)] public IActionResult GetAuthor(string AuthorId) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Authors.Find(AuthorId) is not { } author) return NotFound(); @@ -39,7 +38,6 @@ public class QueryController(IServiceScope scope) : Controller [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetMangaWithAuthorIds(string AuthorId) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Authors.Find(AuthorId) is not { } author) return NotFound(); @@ -56,7 +54,6 @@ public class QueryController(IServiceScope scope) : Controller [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetMangasWithTag(string Tag) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Tags.Find(Tag) is not { } tag) return NotFound(); @@ -73,7 +70,6 @@ public class QueryController(IServiceScope scope) : Controller [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetChapter(string ChapterId) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.Chapters.Find(ChapterId) is not { } chapter) return NotFound(); diff --git a/API/Controllers/SearchController.cs b/API/Controllers/SearchController.cs index b5d997e..60780cb 100644 --- a/API/Controllers/SearchController.cs +++ b/API/Controllers/SearchController.cs @@ -10,7 +10,7 @@ namespace API.Controllers; [ApiVersion(2)] [ApiController] [Route("v{v:apiVersion}/[controller]")] -public class SearchController(IServiceScope scope) : Controller +public class SearchController(MangaContext context) : Controller { /// /// Initiate a search for a on with searchTerm @@ -26,7 +26,6 @@ public class SearchController(IServiceScope scope) : Controller [ProducesResponseType(Status406NotAcceptable)] public IActionResult SearchManga(string MangaConnectorName, string Query) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if(context.MangaConnectors.Find(MangaConnectorName) is not { } connector) return NotFound(); if (connector.Enabled is false) @@ -57,7 +56,6 @@ public class SearchController(IServiceScope scope) : Controller [ProducesResponseType(Status500InternalServerError)] public IActionResult GetMangaFromUrl([FromBody]string url) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); if (context.MangaConnectors.Find("Global") is not { } connector) return StatusCode(Status500InternalServerError, "Could not find Global Connector."); diff --git a/API/Controllers/SettingsController.cs b/API/Controllers/SettingsController.cs index b4deaeb..72a8bd4 100644 --- a/API/Controllers/SettingsController.cs +++ b/API/Controllers/SettingsController.cs @@ -1,6 +1,4 @@ using API.MangaDownloadClients; -using API.Schema.MangaContext; -using API.Workers; using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using static Microsoft.AspNetCore.Http.StatusCodes; @@ -11,7 +9,7 @@ namespace API.Controllers; [ApiVersion(2)] [ApiController] [Route("v{v:apiVersion}/[controller]")] -public class SettingsController(IServiceScope scope) : Controller +public class SettingsController() : Controller { /// /// Get all @@ -221,13 +219,8 @@ public class SettingsController(IServiceScope scope) : Controller [ProducesResponseType(Status200OK)] public IActionResult SetCustomNamingScheme([FromBody]string namingScheme) { - MangaContext context = scope.ServiceProvider.GetRequiredService(); - - Dictionary oldPaths = context.Chapters.ToDictionary(c => c, c => c.FullArchiveFilePath); + //TODO Move old Chapters Tranga.Settings.SetChapterNamingScheme(namingScheme); - MoveFileOrFolderWorker[] newJobs = oldPaths - .Select(kv => new MoveFileOrFolderWorker(kv.Value, kv.Key.FullArchiveFilePath)).ToArray(); - Tranga.AddWorkers(newJobs); return Ok(); } diff --git a/API/Controllers/WorkerController.cs b/API/Controllers/WorkerController.cs index 39ea00d..e031a27 100644 --- a/API/Controllers/WorkerController.cs +++ b/API/Controllers/WorkerController.cs @@ -11,7 +11,7 @@ namespace API.Controllers; [ApiVersion(2)] [ApiController] [Route("v{version:apiVersion}/[controller]")] -public class WorkerController(ILog Log) : Controller +public class WorkerController() : Controller { /// /// Returns all diff --git a/API/Schema/MangaContext/MetadataFetchers/MyAnimeList.cs b/API/Schema/MangaContext/MetadataFetchers/MyAnimeList.cs index 3be2d10..be3caa9 100644 --- a/API/Schema/MangaContext/MetadataFetchers/MyAnimeList.cs +++ b/API/Schema/MangaContext/MetadataFetchers/MyAnimeList.cs @@ -67,7 +67,7 @@ public class MyAnimeList : MetadataFetcher dbManga.Authors.Clear(); dbManga.Authors = resultData.Authors.Select(a => new Author(a.Name)).ToList(); - dbContext.SaveChanges(); + dbContext.Sync(); } catch (DbUpdateException e) { diff --git a/API/Schema/TrangaBaseContext.cs b/API/Schema/TrangaBaseContext.cs index 1f0641e..58f6239 100644 --- a/API/Schema/TrangaBaseContext.cs +++ b/API/Schema/TrangaBaseContext.cs @@ -22,11 +22,11 @@ public abstract class TrangaBaseContext : DbContext where T : DbContext }, Array.Empty(), LogLevel.Warning, DbContextLoggerOptions.Level | DbContextLoggerOptions.Category | DbContextLoggerOptions.UtcTime); } - internal async Task<(bool success, string? exceptionMessage)> Sync() + internal (bool success, string? exceptionMessage) Sync() { try { - await this.SaveChangesAsync(); + this.SaveChanges(); return (true, null); } catch (Exception e) diff --git a/API/Tranga.cs b/API/Tranga.cs index ab3fe72..6deb350 100644 --- a/API/Tranga.cs +++ b/API/Tranga.cs @@ -174,7 +174,7 @@ public static class Tranga if(context.MangaConnectorToManga.Find(addMcId.Key) is null) context.MangaConnectorToManga.Add(mcId); - if (context.Sync().Result is { success: false }) + if (context.Sync() is { success: false }) return false; return true; } @@ -191,7 +191,7 @@ public static class Tranga if(context.MangaConnectorToChapter.Find(chId.Key) is null) context.MangaConnectorToChapter.Add(chId); - if (context.Sync().Result is { success: false }) + if (context.Sync() is { success: false }) return false; return true; } diff --git a/API/Workers/MoveMangaLibraryWorker.cs b/API/Workers/MoveMangaLibraryWorker.cs index 63e537f..170b611 100644 --- a/API/Workers/MoveMangaLibraryWorker.cs +++ b/API/Workers/MoveMangaLibraryWorker.cs @@ -2,7 +2,7 @@ using API.Schema.MangaContext; namespace API.Workers; -public class MoveMangaLibraryWorker(Manga manga, FileLibrary toLibrary, IServiceScope scope, IEnumerable? dependsOn = null) +public class MoveMangaLibraryWorker(Manga manga, FileLibrary toLibrary, IEnumerable? dependsOn = null) : BaseWorkerWithContext(dependsOn) { protected override BaseWorker[] DoWorkInternal() @@ -10,7 +10,7 @@ public class MoveMangaLibraryWorker(Manga manga, FileLibrary toLibrary, IService Dictionary oldPath = manga.Chapters.ToDictionary(c => c, c => c.FullArchiveFilePath); manga.Library = toLibrary; - if (DbContext.Sync().Result is { success: false }) + if (DbContext.Sync() is { success: false }) return []; return manga.Chapters.Select(c => new MoveFileOrFolderWorker(c.FullArchiveFilePath, oldPath[c])).ToArray();