diff --git a/Tranga-API/Dockerfile b/Tranga-API/Dockerfile deleted file mode 100644 index 6a0e453..0000000 --- a/Tranga-API/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -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 deleted file mode 100644 index 6356e38..0000000 --- a/Tranga-API/Program.cs +++ /dev/null @@ -1,186 +0,0 @@ -using System.Text.Json; -using Tranga; -using Logging; - -string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Tranga-API"); -string logsFolderPath = Path.Join(applicationFolderPath, "logs"); -string logFilePath = Path.Join(logsFolderPath, $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt"); -string settingsFilePath = Path.Join(applicationFolderPath, "data.json"); -Directory.CreateDirectory(applicationFolderPath); -Directory.CreateDirectory(logsFolderPath); - -Console.WriteLine($"Logfile-Path: {logFilePath}"); -Console.WriteLine($"Settings-File-Path: {settingsFilePath}"); - -Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, null, logFilePath); - -logger.WriteLine("Tranga_API", "Loading Taskmanager."); - -TaskManager.SettingsData settings; -if (File.Exists(settingsFilePath)) - settings = TaskManager.LoadData(settingsFilePath); -else - settings = new TaskManager.SettingsData(Directory.GetCurrentDirectory(), settingsFilePath, null, new HashSet()); - -TaskManager taskManager = new (settings, logger); - -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) => -{ - Connector connector = taskManager.GetConnector(connectorName); - - Publication[] publications; - if (publicationName is not null) - publications = connector.GetPublications(publicationName); - else - publications = connector.GetPublications(); - - return JsonSerializer.Serialize(publications); -}); - -app.MapGet("/ListTasks", () => JsonSerializer.Serialize(taskManager.GetAllTasks())); - -app.MapGet("/TaskTypes", () => -{ - string[] availableTasks = Enum.GetNames(typeof(TrangaTask.Task)); - return JsonSerializer.Serialize(availableTasks); -}); - -app.MapGet("/CreateTask", - (TrangaTask.Task task, string? connectorName, string? publicationInternalId, TimeSpan reoccurrence, string? language) => - { - switch (task) - { - case TrangaTask.Task.UpdateKomgaLibrary: - taskManager.AddTask(TrangaTask.Task.UpdateKomgaLibrary, null, null, reoccurrence); - break; - case TrangaTask.Task.DownloadNewChapters: - try - { - Publication? publication = taskManager.GetAllPublications() - .FirstOrDefault(pub => pub.internalId == publicationInternalId); - - if (publication is null) - { - return JsonSerializer.Serialize($"Publication {publicationInternalId} is unknown."); - } - else - { - 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? publicationInternalId) => -{ - switch (task) - { - case TrangaTask.Task.UpdateKomgaLibrary: - taskManager.DeleteTask(TrangaTask.Task.UpdateKomgaLibrary, null, null); - return JsonSerializer.Serialize("Success"); - case TrangaTask.Task.DownloadNewChapters: - Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == publicationInternalId); - if (publication is null) - JsonSerializer.Serialize($"Publication with id {publicationInternalId} is unknown."); - - taskManager.DeleteTask(TrangaTask.Task.DownloadNewChapters, connectorName, publication); - - return JsonSerializer.Serialize("Success"); - - default: return JsonSerializer.Serialize("Not Implemented"); - } -}); - -app.MapGet("/StartTask", (TrangaTask.Task task, string? connectorName, string? publicationInternalId) => -{ - TrangaTask[] allTasks = taskManager.GetAllTasks(); - TrangaTask? taskToStart = allTasks.FirstOrDefault(tTask => - tTask.task == task && tTask.connectorName == connectorName && - tTask.publication?.internalId == publicationInternalId); - if(taskToStart is null) - JsonSerializer.Serialize($"Task with parameters {task} {connectorName} {publicationInternalId} is unknown."); - taskManager.ExecuteTaskNow(taskToStart!); - return JsonSerializer.Serialize("Success"); -}); - -app.MapGet("/TaskQueue", () => -{ - return JsonSerializer.Serialize(taskManager.GetAllTasks() - .Where(task => task.state is TrangaTask.ExecutionState.Enqueued or TrangaTask.ExecutionState.Running) - .ToArray()); -}); - -app.MapGet("/TaskEnqueue", (TrangaTask.Task task, string? connectorName, string? publicationInternalId) => -{ - TrangaTask[] allTasks = taskManager.GetAllTasks(); - TrangaTask? taskToEnqueue = allTasks.FirstOrDefault(tTask => - tTask.task == task && tTask.connectorName == connectorName && - tTask.publication?.internalId == publicationInternalId); - if(taskToEnqueue is null) - JsonSerializer.Serialize($"Task with parameters {task} {connectorName} {publicationInternalId} is unknown."); - taskManager.AddTaskToQueue(taskToEnqueue!); - return JsonSerializer.Serialize("Success"); -}); - -app.MapGet("/TaskDequeue", (TrangaTask.Task task, string? connectorName, string? publicationInternalId) => -{ - TrangaTask[] allTasks = taskManager.GetAllTasks(); - TrangaTask? taskToDequeue = allTasks.FirstOrDefault(tTask => - tTask.task == task && tTask.connectorName == connectorName && - tTask.publication?.internalId == publicationInternalId); - if(taskToDequeue is null) - JsonSerializer.Serialize($"Task with parameters {task} {connectorName} {publicationInternalId} is unknown."); - taskManager.RemoveTaskFromQueue(taskToDequeue); - return JsonSerializer.Serialize("Success"); -}); - -app.MapGet("/Settings", () => JsonSerializer.Serialize(new Settings(taskManager.settings))); - -app.MapGet("/EditSettings", (string downloadLocation, string komgaBaseUrl, string komgaAuthString) => -{ - taskManager.settings.downloadLocation = downloadLocation; - taskManager.settings.komga = new Komga(komgaBaseUrl, komgaAuthString, logger); -}); - -app.Run(); - -struct Settings -{ - public Komga? komga { get; set; } - public string downloadLocation { get; set; } - public string settingsFilePath { get; set; } - public Settings(TaskManager.SettingsData data) - { - this.settingsFilePath = data.settingsFilePath; - this.downloadLocation = data.downloadLocation; - this.komga = data.komga; - } - - public Settings(string downloadLocation, string settingsFilePath, Komga komga) - { - this.downloadLocation = downloadLocation; - this.settingsFilePath = settingsFilePath; - this.komga = komga; - } - - public void Update(string? newDownloadLocation = null, string? newSettingsFilePath = null, Komga? newKomga= null) - { - this.downloadLocation = newDownloadLocation ?? this.downloadLocation; - this.settingsFilePath = newSettingsFilePath ?? this.settingsFilePath; - this.komga = newKomga ?? this.komga; - } -} \ No newline at end of file diff --git a/Tranga-API/Properties/launchSettings.json b/Tranga-API/Properties/launchSettings.json deleted file mode 100644 index 773e2c3..0000000 --- a/Tranga-API/Properties/launchSettings.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "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 deleted file mode 100644 index ade20c4..0000000 --- a/Tranga-API/Tranga-API.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - net7.0 - enable - enable - Tranga_API - Linux - - - - - .dockerignore - - - - - - - - diff --git a/Tranga-API/appsettings.Development.json b/Tranga-API/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/Tranga-API/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/Tranga-API/appsettings.json b/Tranga-API/appsettings.json deleted file mode 100644 index 10f68b8..0000000 --- a/Tranga-API/appsettings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*" -} diff --git a/Tranga-API/tasks.json b/Tranga-API/tasks.json deleted file mode 100644 index 8cbf4a7..0000000 --- a/Tranga-API/tasks.json +++ /dev/null @@ -1 +0,0 @@ -[{"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 f11d582..d67d5c6 100644 --- a/Tranga.sln +++ b/Tranga.sln @@ -4,8 +4,6 @@ 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 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Logging\Logging.csproj", "{415BE889-BB7D-426F-976F-8D977876A462}" EndProject Global @@ -22,10 +20,6 @@ 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 {415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.Build.0 = Debug|Any CPU {415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.ActiveCfg = Release|Any CPU