Use GetConnector Method.

This commit is contained in:
glax 2023-05-20 14:21:47 +02:00
parent fa44de0c8d
commit 58de0115d6
3 changed files with 4 additions and 11 deletions

View File

@ -10,9 +10,7 @@ app.MapGet("/GetConnectors", () => JsonSerializer.Serialize(taskManager.GetAvail
app.MapGet("/GetPublications", (string connectorName, string? title) => app.MapGet("/GetPublications", (string connectorName, string? title) =>
{ {
Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(c => c.Key == connectorName).Value; Connector connector = taskManager.GetConnector(connectorName);
if (connector is null)
return JsonSerializer.Serialize($"Connector {connectorName} is not a known connector.");
Publication[] publications; Publication[] publications;
if (title is not null) if (title is not null)

View File

@ -279,7 +279,7 @@ public static class Tranga_Cli
private static void DownloadNow(TaskManager.SettingsData settings) private static void DownloadNow(TaskManager.SettingsData settings)
{ {
Connector connector = SelectConnector(settings.downloadLocation); Connector connector = SelectConnector(settings.downloadLocation, new Connector[]{new MangaDex(settings.downloadLocation)});
Publication publication = SelectPublication(connector); Publication publication = SelectPublication(connector);
@ -298,10 +298,9 @@ public static class Tranga_Cli
} }
} }
private static Connector SelectConnector(string folderPath, Connector[]? availableConnectors = null) private static Connector SelectConnector(string folderPath, Connector[] connectors)
{ {
Console.Clear(); Console.Clear();
Connector[] connectors = availableConnectors ?? new Connector[] { new MangaDex(folderPath) };
int cIndex = 0; int cIndex = 0;
Console.WriteLine("Connectors:"); Console.WriteLine("Connectors:");

View File

@ -18,11 +18,7 @@ public static class TaskExecutor
{ {
Connector? connector = null; Connector? connector = null;
if (trangaTask.task != TrangaTask.Task.UpdateKomgaLibrary) if (trangaTask.task != TrangaTask.Task.UpdateKomgaLibrary)
{ connector = taskManager.GetConnector(trangaTask.connectorName!);
//Get Connector from list of available Connectors and the required Connector of the TrangaTask
if (!taskManager.GetAvailableConnectors().TryGetValue(trangaTask.connectorName, out connector))
throw new ArgumentException($"Connector {trangaTask.connectorName} is not a known connector.");
}
if (trangaTask.isBeingExecuted) if (trangaTask.isBeingExecuted)
return; return;