2
0

Compare commits

..

No commits in common. "18b5d179942af967627216d91b24300e36eeb8a1" and "1449292e53865624f3b7ce79957da175e8b8dff7" have entirely different histories.

2 changed files with 20 additions and 55 deletions

View File

@ -1,19 +1,20 @@
using System.Text.Json; using System.Text.Json;
using Tranga; using Tranga;
using Tranga.Connectors;
TaskManager taskManager = new (Directory.GetCurrentDirectory()); TaskManager taskManager = new TaskManager(Directory.GetCurrentDirectory());
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
var app = builder.Build(); var app = builder.Build();
app.MapGet("/GetConnectors", () => JsonSerializer.Serialize(taskManager.GetAvailableConnectors().Values.ToArray())); app.MapGet("/GetConnectors", () => JsonSerializer.Serialize(taskManager.GetAvailableConnectors().Values.ToArray()));
app.MapGet("/GetPublications", (string connectorName, string? publicationName) => app.MapGet("/GetPublications", (string connectorName, string? title) =>
{ {
Connector connector = taskManager.GetConnector(connectorName); Connector connector = taskManager.GetConnector(connectorName);
Publication[] publications; Publication[] publications;
if (publicationName is not null) if (title is not null)
publications = connector.GetPublications(publicationName); publications = connector.GetPublications(title);
else else
publications = connector.GetPublications(); publications = connector.GetPublications();
@ -23,60 +24,26 @@ app.MapGet("/GetPublications", (string connectorName, string? publicationName) =
app.MapGet("/ListTasks", () => JsonSerializer.Serialize(taskManager.GetAllTasks())); app.MapGet("/ListTasks", () => JsonSerializer.Serialize(taskManager.GetAllTasks()));
app.MapGet("/CreateTask", app.MapGet("/CreateTask",
(TrangaTask.Task task, string? connectorName, string? publicationName, TimeSpan reoccurrence, string? language) => (TrangaTask.Task task, string connectorName, string? publicationName, TimeSpan reoccurrence, string language) =>
{ {
switch (task) Publication? publication =
{ taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName);
case TrangaTask.Task.UpdateKomgaLibrary: if (publication is null)
taskManager.AddTask(TrangaTask.Task.UpdateKomgaLibrary, null, null, reoccurrence); JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
break;
case TrangaTask.Task.DownloadNewChapters: taskManager.AddTask(task, connectorName, publication, reoccurrence, language);
try JsonSerializer.Serialize("Success");
{
Connector connector = taskManager.GetConnector(connectorName);
Publication[] publications;
if (publicationName is not null)
publications = connector.GetPublications(publicationName);
else
publications = connector.GetPublications();
Publication? publication = publications.FirstOrDefault(pub => pub.downloadUrl == publicationName);
if (publication is null)
JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
taskManager.AddTask(TrangaTask.Task.DownloadNewChapters, connectorName, publication, reoccurrence, language ?? "");
return JsonSerializer.Serialize("Success");
}
catch (Exception e)
{
return JsonSerializer.Serialize(e.Message);
}
default: return JsonSerializer.Serialize("Not Implemented");
}
return JsonSerializer.Serialize("Not Implemented");
}); });
app.MapGet("/RemoveTask", (TrangaTask.Task task, string? connectorName, string? publicationName) => app.MapGet("/RemoveTask", (TrangaTask.Task task, string connector, string? publicationName) =>
{ {
switch (task) Publication? publication =
{ taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName);
case TrangaTask.Task.UpdateKomgaLibrary: if (publication is null)
taskManager.RemoveTask(TrangaTask.Task.UpdateKomgaLibrary, null, null); JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
return JsonSerializer.Serialize("Success");
break;
case TrangaTask.Task.DownloadNewChapters:
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName);
if (publication is null)
JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
taskManager.RemoveTask(TrangaTask.Task.DownloadNewChapters, connectorName, publication);
return JsonSerializer.Serialize("Success");
default: return JsonSerializer.Serialize("Not Implemented"); taskManager.RemoveTask(task, connector, publication);
} JsonSerializer.Serialize("Success");
}); });
app.Run(); app.Run();

View File

@ -193,8 +193,6 @@ public class TaskManager
/// <exception cref="Exception">If Connector is not available</exception> /// <exception cref="Exception">If Connector is not available</exception>
public Connector GetConnector(string connectorName) public Connector GetConnector(string connectorName)
{ {
if(connectorName is null)
throw new Exception($"connectorName can not be null");
Connector? ret = this._connectors.FirstOrDefault(connector => connector.name == connectorName); Connector? ret = this._connectors.FirstOrDefault(connector => connector.name == connectorName);
if (ret is null) if (ret is null)
throw new Exception($"Connector {connectorName} is not an available Connector."); throw new Exception($"Connector {connectorName} is not an available Connector.");