diff --git a/Tranga-API/Dockerfile b/Tranga-API/Dockerfile new file mode 100644 index 0000000..6a0e453 --- /dev/null +++ b/Tranga-API/Dockerfile @@ -0,0 +1,20 @@ +FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +WORKDIR /src +COPY ["Tranga-API/Tranga-API.csproj", "Tranga-API/"] +RUN dotnet restore "Tranga-API/Tranga-API.csproj" +COPY . . +WORKDIR "/src/Tranga-API" +RUN dotnet build "Tranga-API.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "Tranga-API.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Tranga-API.dll"] diff --git a/Tranga-API/Program.cs b/Tranga-API/Program.cs new file mode 100644 index 0000000..8b17fcd --- /dev/null +++ b/Tranga-API/Program.cs @@ -0,0 +1,51 @@ +using System.Text.Json; +using Tranga; +using Tranga.Connectors; + +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? title) => +{ + Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(c => c.Key == connectorName).Value; + if (connector is null) + JsonSerializer.Serialize($"Connector {connectorName} is not a known connector."); + + Publication[] publications; + if (title is not null) + publications = connector.GetPublications(title); + else + publications = connector.GetPublications(); + + return JsonSerializer.Serialize(publications); +}); + +app.MapGet("/ListTasks", () => JsonSerializer.Serialize(taskManager.GetAllTasks())); + +app.MapGet("/CreateTask", + (TrangaTask.Task task, string connectorName, string? publicationName, TimeSpan reoccurrence, string language) => + { + 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 connector, string? publicationName) => +{ + Publication? publication = + taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName); + if (publication is null) + JsonSerializer.Serialize($"Publication {publicationName} is unknown."); + + taskManager.RemoveTask(task, connector, publication); + JsonSerializer.Serialize("Success"); +}); + +app.Run(); \ No newline at end of file diff --git a/Tranga-API/Properties/launchSettings.json b/Tranga-API/Properties/launchSettings.json new file mode 100644 index 0000000..773e2c3 --- /dev/null +++ b/Tranga-API/Properties/launchSettings.json @@ -0,0 +1,37 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:14826", + "sslPort": 44333 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5119", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7070;http://localhost:5119", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Tranga-API/Tranga-API.csproj b/Tranga-API/Tranga-API.csproj new file mode 100644 index 0000000..ade20c4 --- /dev/null +++ b/Tranga-API/Tranga-API.csproj @@ -0,0 +1,21 @@ + + + + net7.0 + enable + enable + Tranga_API + Linux + + + + + .dockerignore + + + + + + + + diff --git a/Tranga-API/appsettings.Development.json b/Tranga-API/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Tranga-API/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Tranga-API/appsettings.json b/Tranga-API/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Tranga-API/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Tranga-API/tasks.json b/Tranga-API/tasks.json new file mode 100644 index 0000000..8cbf4a7 --- /dev/null +++ b/Tranga-API/tasks.json @@ -0,0 +1 @@ +[{"reoccurrence":"00:00:00","lastExecuted":"2023-05-19T17:34:40.5349215+02:00","connectorName":"MangaDex","task":0,"publication":{"sortName":null,"description":null,"tags":null,"posterUrl":null,"year":null,"originalLanguage":null,"status":null,"folderName":null,"downloadUrl":null},"language":"en"}] \ No newline at end of file diff --git a/Tranga.sln b/Tranga.sln index c74a82a..055c08f 100644 --- a/Tranga.sln +++ b/Tranga.sln @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga", ".\Tranga\Tranga.c EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-CLI", "Tranga-CLI\Tranga-CLI.csproj", "{4899E3B2-B259-479A-B43E-042D043E9501}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-API", "Tranga-API\Tranga-API.csproj", "{6284C936-4E90-486B-BC46-0AFAD85AD8EE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -18,5 +20,9 @@ Global {4899E3B2-B259-479A-B43E-042D043E9501}.Debug|Any CPU.Build.0 = Debug|Any CPU {4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.ActiveCfg = Release|Any CPU {4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.Build.0 = Release|Any CPU + {6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal