mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-03 17:34:17 +02:00
BaseWorker, BaseWorkerWithContext DoWork, call: Scope setting
TrangaBaseContext Sync return with success state and exception message
This commit is contained in:
@ -63,8 +63,8 @@ public class FileLibraryController(IServiceScope scope) : Controller
|
||||
//TODO Path check
|
||||
library.BasePath = newBasePath;
|
||||
|
||||
if(context.Sync().Result is { } errorMessage)
|
||||
return StatusCode(Status500InternalServerError, errorMessage);
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
@ -90,8 +90,8 @@ public class FileLibraryController(IServiceScope scope) : Controller
|
||||
//TODO Name check
|
||||
library.LibraryName = newName;
|
||||
|
||||
if(context.Sync().Result is { } errorMessage)
|
||||
return StatusCode(Status500InternalServerError, errorMessage);
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
@ -111,8 +111,8 @@ public class FileLibraryController(IServiceScope scope) : Controller
|
||||
//TODO Parameter check
|
||||
context.FileLibraries.Add(library);
|
||||
|
||||
if(context.Sync().Result is { } errorMessage)
|
||||
return StatusCode(Status500InternalServerError, errorMessage);
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Created();
|
||||
}
|
||||
|
||||
@ -134,8 +134,8 @@ public class FileLibraryController(IServiceScope scope) : Controller
|
||||
|
||||
context.FileLibraries.Remove(library);
|
||||
|
||||
if(context.Sync().Result is { } errorMessage)
|
||||
return StatusCode(Status500InternalServerError, errorMessage);
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Ok();
|
||||
}
|
||||
}
|
@ -60,8 +60,8 @@ public class LibraryConnectorController(IServiceScope scope) : Controller
|
||||
|
||||
context.LibraryConnectors.Add(libraryConnector);
|
||||
|
||||
if(context.Sync().Result is { } errorMessage)
|
||||
return StatusCode(Status500InternalServerError, errorMessage);
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Created();
|
||||
}
|
||||
|
||||
@ -84,8 +84,8 @@ public class LibraryConnectorController(IServiceScope scope) : Controller
|
||||
|
||||
context.LibraryConnectors.Remove(connector);
|
||||
|
||||
if(context.Sync().Result is { } errorMessage)
|
||||
return StatusCode(Status500InternalServerError, errorMessage);
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Ok();
|
||||
}
|
||||
}
|
@ -88,8 +88,8 @@ public class MangaConnectorController(IServiceScope scope) : Controller
|
||||
|
||||
connector.Enabled = Enabled;
|
||||
|
||||
if(context.Sync().Result is { } errorMessage)
|
||||
return StatusCode(Status500InternalServerError, errorMessage);
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Accepted();
|
||||
}
|
||||
}
|
@ -81,8 +81,8 @@ public class MangaController(IServiceScope scope) : Controller
|
||||
|
||||
context.Mangas.Remove(manga);
|
||||
|
||||
if(context.Sync().Result is { } errorMessage)
|
||||
return StatusCode(Status500InternalServerError, errorMessage);
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
@ -329,8 +329,8 @@ public class MangaController(IServiceScope scope) : Controller
|
||||
return NotFound();
|
||||
|
||||
manga.IgnoreChaptersBefore = chapterThreshold;
|
||||
if(context.Sync().Result is { } errorMessage)
|
||||
return StatusCode(Status500InternalServerError, errorMessage);
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
|
||||
return Accepted();
|
||||
}
|
||||
@ -354,7 +354,7 @@ public class MangaController(IServiceScope scope) : Controller
|
||||
return NotFound(nameof(LibraryId));
|
||||
|
||||
MoveMangaLibraryWorker moveLibrary = new(manga, library, scope);
|
||||
UpdateChaptersDownloadedWorker updateDownloadedFiles = new(manga, scope, [moveLibrary]);
|
||||
UpdateChaptersDownloadedWorker updateDownloadedFiles = new(manga, [moveLibrary]);
|
||||
|
||||
Tranga.AddWorkers([moveLibrary, updateDownloadedFiles]);
|
||||
|
||||
|
@ -119,8 +119,8 @@ public class MetadataFetcherController(IServiceScope scope) : Controller
|
||||
|
||||
context.Remove(entry);
|
||||
|
||||
if(context.Sync().Result is { } errorMessage)
|
||||
return StatusCode(Status500InternalServerError, errorMessage);
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Ok();
|
||||
}
|
||||
}
|
@ -62,8 +62,8 @@ public class NotificationConnectorController(IServiceScope scope) : Controller
|
||||
|
||||
context.NotificationConnectors.Add(notificationConnector);
|
||||
|
||||
if(context.Sync().Result is { } errorMessage)
|
||||
return StatusCode(Status500InternalServerError, errorMessage);
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Created();
|
||||
}
|
||||
|
||||
@ -156,8 +156,8 @@ public class NotificationConnectorController(IServiceScope scope) : Controller
|
||||
|
||||
context.NotificationConnectors.Remove(connector);
|
||||
|
||||
if(context.Sync().Result is { } errorMessage)
|
||||
return StatusCode(Status500InternalServerError, errorMessage);
|
||||
if(context.Sync().Result is { success: false } result)
|
||||
return StatusCode(Status500InternalServerError, result.exceptionMessage);
|
||||
return Created();
|
||||
}
|
||||
}
|
@ -96,7 +96,7 @@ public class SearchController(IServiceScope scope) : Controller
|
||||
if(context.MangaConnectorToManga.Find(addMcId.Key) is null)
|
||||
context.MangaConnectorToManga.Add(mcId);
|
||||
|
||||
if (context.Sync().Result is not null)
|
||||
if (context.Sync().Result is { success: false } )
|
||||
return null;
|
||||
return manga;
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
using API.APIEndpointRecords;
|
||||
using API.Schema.MangaContext;
|
||||
using API.Workers;
|
||||
using Asp.Versioning;
|
||||
using log4net;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
@ -129,7 +127,7 @@ public class WorkerController(ILog Log) : Controller
|
||||
if (worker.State >= WorkerExecutionState.Waiting)
|
||||
return StatusCode(Status412PreconditionFailed, "Already running");
|
||||
|
||||
Tranga.StartWorker(worker);
|
||||
Tranga.MarkWorkerForStart(worker);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user