Remove APi for testing
This commit is contained in:
parent
13c96fd09a
commit
df991e3da6
@ -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"]
|
|
@ -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<TrangaTask>());
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<RootNamespace>Tranga_API</RootNamespace>
|
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="..\.dockerignore">
|
|
||||||
<Link>.dockerignore</Link>
|
|
||||||
</Content>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AllowedHosts": "*"
|
|
||||||
}
|
|
@ -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"}]
|
|
@ -4,8 +4,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga", ".\Tranga\Tranga.c
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-CLI", "Tranga-CLI\Tranga-CLI.csproj", "{4899E3B2-B259-479A-B43E-042D043E9501}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-CLI", "Tranga-CLI\Tranga-CLI.csproj", "{4899E3B2-B259-479A-B43E-042D043E9501}"
|
||||||
EndProject
|
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}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Logging\Logging.csproj", "{415BE889-BB7D-426F-976F-8D977876A462}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
@ -22,10 +20,6 @@ Global
|
|||||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{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.ActiveCfg = Release|Any CPU
|
||||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.Build.0 = 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.ActiveCfg = Debug|Any CPU
|
||||||
{415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.Build.0 = 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
|
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
Loading…
Reference in New Issue
Block a user