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 Tranga;
using Tranga.Connectors;
TaskManager taskManager = new (Directory.GetCurrentDirectory());
TaskManager taskManager = new TaskManager(Directory.GetCurrentDirectory());
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
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);
Publication[] publications;
if (publicationName is not null)
publications = connector.GetPublications(publicationName);
if (title is not null)
publications = connector.GetPublications(title);
else
publications = connector.GetPublications();
@ -23,60 +24,26 @@ app.MapGet("/GetPublications", (string connectorName, string? publicationName) =
app.MapGet("/ListTasks", () => JsonSerializer.Serialize(taskManager.GetAllTasks()));
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)
{
case TrangaTask.Task.UpdateKomgaLibrary:
taskManager.AddTask(TrangaTask.Task.UpdateKomgaLibrary, null, null, reoccurrence);
break;
case TrangaTask.Task.DownloadNewChapters:
try
{
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");
Publication? publication =
taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName);
if (publication is null)
JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
taskManager.AddTask(task, connectorName, publication, reoccurrence, language);
JsonSerializer.Serialize("Success");
});
app.MapGet("/RemoveTask", (TrangaTask.Task task, string? connectorName, string? publicationName) =>
app.MapGet("/RemoveTask", (TrangaTask.Task task, string connector, string? publicationName) =>
{
switch (task)
{
case TrangaTask.Task.UpdateKomgaLibrary:
taskManager.RemoveTask(TrangaTask.Task.UpdateKomgaLibrary, null, null);
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");
Publication? publication =
taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName);
if (publication is null)
JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
default: return JsonSerializer.Serialize("Not Implemented");
}
taskManager.RemoveTask(task, connector, publication);
JsonSerializer.Serialize("Success");
});
app.Run();

View File

@ -193,8 +193,6 @@ public class TaskManager
/// <exception cref="Exception">If Connector is not available</exception>
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);
if (ret is null)
throw new Exception($"Connector {connectorName} is not an available Connector.");