Compare commits
3 Commits
1449292e53
...
18b5d17994
Author | SHA1 | Date | |
---|---|---|---|
18b5d17994 | |||
1916018fba | |||
a6a2d20981 |
@ -1,20 +1,19 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Tranga;
|
using Tranga;
|
||||||
using Tranga.Connectors;
|
|
||||||
|
|
||||||
TaskManager taskManager = new TaskManager(Directory.GetCurrentDirectory());
|
TaskManager taskManager = new (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? title) =>
|
app.MapGet("/GetPublications", (string connectorName, string? publicationName) =>
|
||||||
{
|
{
|
||||||
Connector connector = taskManager.GetConnector(connectorName);
|
Connector connector = taskManager.GetConnector(connectorName);
|
||||||
|
|
||||||
Publication[] publications;
|
Publication[] publications;
|
||||||
if (title is not null)
|
if (publicationName is not null)
|
||||||
publications = connector.GetPublications(title);
|
publications = connector.GetPublications(publicationName);
|
||||||
else
|
else
|
||||||
publications = connector.GetPublications();
|
publications = connector.GetPublications();
|
||||||
|
|
||||||
@ -24,26 +23,60 @@ app.MapGet("/GetPublications", (string connectorName, string? title) =>
|
|||||||
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) =>
|
||||||
{
|
{
|
||||||
Publication? publication =
|
switch (task)
|
||||||
taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName);
|
{
|
||||||
|
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)
|
if (publication is null)
|
||||||
JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
taskManager.AddTask(task, connectorName, publication, reoccurrence, language);
|
default: return JsonSerializer.Serialize("Not Implemented");
|
||||||
JsonSerializer.Serialize("Success");
|
}
|
||||||
|
|
||||||
|
return JsonSerializer.Serialize("Not Implemented");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.MapGet("/RemoveTask", (TrangaTask.Task task, string connector, string? publicationName) =>
|
app.MapGet("/RemoveTask", (TrangaTask.Task task, string? connectorName, string? publicationName) =>
|
||||||
{
|
{
|
||||||
Publication? publication =
|
switch (task)
|
||||||
taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName);
|
{
|
||||||
|
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)
|
if (publication is null)
|
||||||
JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
|
JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
|
||||||
|
|
||||||
taskManager.RemoveTask(task, connector, publication);
|
taskManager.RemoveTask(TrangaTask.Task.DownloadNewChapters, connectorName, publication);
|
||||||
JsonSerializer.Serialize("Success");
|
|
||||||
|
return JsonSerializer.Serialize("Success");
|
||||||
|
|
||||||
|
default: return JsonSerializer.Serialize("Not Implemented");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
@ -193,6 +193,8 @@ 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.");
|
||||||
|
Loading…
Reference in New Issue
Block a user