mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-04 18:04:16 +02:00
Compare commits
23 Commits
0.7
...
6aa0ea277b
Author | SHA1 | Date | |
---|---|---|---|
6aa0ea277b | |||
780df1cd6e | |||
0b7da2e9cb | |||
01a059d26b | |||
a8dbece237 | |||
5efa00e059 | |||
02075ed1b1 | |||
fabd16ccea | |||
79928075b0 | |||
9b8eb6a197 | |||
1d263ef45a | |||
e0877add30 | |||
046cad8072 | |||
b2ce55be96 | |||
a6e9013495 | |||
14c69631a6 | |||
ccc4e42a49 | |||
d6e75fda31 | |||
fc89537f63 | |||
fd3423d03c | |||
878f77766f | |||
08001fd684 | |||
e2917d2f2e |
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-env
|
||||||
|
WORKDIR /src
|
||||||
|
COPY . /src/
|
||||||
|
RUN dotnet restore Tranga-API/Tranga-API.csproj
|
||||||
|
RUN dotnet publish -c Release -o /publish
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime
|
||||||
|
WORKDIR /publish
|
||||||
|
COPY --from=build-env /publish .
|
||||||
|
EXPOSE 80
|
||||||
|
ENTRYPOINT ["dotnet", "/publish/Tranga-API.dll"]
|
@ -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,28 +1,35 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
using Logging;
|
using Logging;
|
||||||
using Tranga;
|
using Tranga;
|
||||||
|
|
||||||
string applicationFolderPath =
|
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga-API");
|
||||||
Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga-API");
|
string downloadFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(applicationFolderPath, "Manga");
|
||||||
string downloadFolderPath = Path.Join(applicationFolderPath, "Manga");
|
string logsFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/var/logs/Tranga" : Path.Join(applicationFolderPath, "logs");
|
||||||
string logsFolderPath = Path.Join(applicationFolderPath, "logs");
|
|
||||||
string logFilePath = Path.Join(logsFolderPath, $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt");
|
string logFilePath = Path.Join(logsFolderPath, $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt");
|
||||||
string settingsFilePath = Path.Join(applicationFolderPath, "settings.json");
|
string settingsFilePath = Path.Join(applicationFolderPath, "settings.json");
|
||||||
|
|
||||||
Directory.CreateDirectory(applicationFolderPath);
|
|
||||||
Directory.CreateDirectory(logsFolderPath);
|
Directory.CreateDirectory(logsFolderPath);
|
||||||
|
Logger logger = new(new[] { Logger.LoggerType.FileLogger, Logger.LoggerType.ConsoleLogger }, Console.Out, Console.Out.Encoding, logFilePath);
|
||||||
Console.WriteLine($"Logfile-Path: {logFilePath}");
|
|
||||||
Console.WriteLine($"Settings-File-Path: {settingsFilePath}");
|
logger.WriteLine("Tranga", "Loading settings.");
|
||||||
|
|
||||||
Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, null, logFilePath);
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Loading Taskmanager.");
|
|
||||||
TrangaSettings settings;
|
TrangaSettings settings;
|
||||||
if (File.Exists(settingsFilePath))
|
if (File.Exists(settingsFilePath))
|
||||||
settings = TrangaSettings.LoadSettings(settingsFilePath);
|
settings = TrangaSettings.LoadSettings(settingsFilePath);
|
||||||
else
|
else
|
||||||
settings = new TrangaSettings(downloadFolderPath, applicationFolderPath, null);
|
settings = new TrangaSettings(downloadFolderPath, applicationFolderPath, null);
|
||||||
|
|
||||||
|
Directory.CreateDirectory(settings.workingDirectory);
|
||||||
|
Directory.CreateDirectory(settings.downloadLocation);
|
||||||
|
Directory.CreateDirectory(settings.coverImageCache);
|
||||||
|
|
||||||
|
logger.WriteLine("Tranga",$"Application-Folder: {settings.workingDirectory}");
|
||||||
|
logger.WriteLine("Tranga",$"Settings-File-Path: {settings.settingsFilePath}");
|
||||||
|
logger.WriteLine("Tranga",$"Download-Folder-Path: {settings.downloadLocation}");
|
||||||
|
logger.WriteLine("Tranga",$"Logfile-Path: {logFilePath}");
|
||||||
|
logger.WriteLine("Tranga",$"Image-Cache-Path: {settings.coverImageCache}");
|
||||||
|
|
||||||
|
logger.WriteLine("Tranga", "Loading Taskmanager.");
|
||||||
TaskManager taskManager = new (settings, logger);
|
TaskManager taskManager = new (settings, logger);
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@ -36,7 +43,7 @@ builder.Services.AddCors(options =>
|
|||||||
options.AddPolicy(name: corsHeader,
|
options.AddPolicy(name: corsHeader,
|
||||||
policy =>
|
policy =>
|
||||||
{
|
{
|
||||||
policy.WithOrigins("http://localhost", "http://127.0.0.1", "http://localhost:63342");
|
policy.AllowAnyOrigin();
|
||||||
policy.WithMethods("GET", "POST", "DELETE");
|
policy.WithMethods("GET", "POST", "DELETE");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -82,23 +89,45 @@ app.MapDelete("/Tasks/Delete", (string taskType, string? connectorName, string?
|
|||||||
|
|
||||||
app.MapGet("/Tasks/Get", (string taskType, string? connectorName, string? searchString) =>
|
app.MapGet("/Tasks/Get", (string taskType, string? connectorName, string? searchString) =>
|
||||||
{
|
{
|
||||||
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
|
try
|
||||||
if (searchString is null)
|
{
|
||||||
return taskManager.GetAllTasks().Where(tTask => tTask.task == task && tTask.connectorName == connectorName);
|
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
|
||||||
else
|
if (searchString is null || connectorName is null)
|
||||||
return taskManager.GetAllTasks().Where(tTask =>
|
return taskManager.GetAllTasks().Where(tTask => tTask.task == task);
|
||||||
tTask.task == task && tTask.connectorName == connectorName && tTask.ToString()
|
else
|
||||||
.Contains(searchString, StringComparison.InvariantCultureIgnoreCase));
|
return taskManager.GetAllTasks().Where(tTask =>
|
||||||
|
tTask.task == task && tTask.connectorName == connectorName && tTask.ToString()
|
||||||
|
.Contains(searchString, StringComparison.InvariantCultureIgnoreCase));
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return Array.Empty<TrangaTask>();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.MapPost("/Tasks/Start", (string taskType, string? connectorName, string? publicationId) =>
|
app.MapPost("/Tasks/Start", (string taskType, string? connectorName, string? publicationId) =>
|
||||||
{
|
{
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
try
|
||||||
TrangaTask? task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
{
|
||||||
tTask.task == pTask && tTask.publication?.internalId == publicationId && tTask.connectorName == connectorName);
|
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
||||||
if (task is null)
|
TrangaTask? task = null;
|
||||||
|
if (connectorName is null || publicationId is null)
|
||||||
|
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
||||||
|
tTask.task == pTask);
|
||||||
|
else
|
||||||
|
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
||||||
|
tTask.task == pTask && tTask.publication?.internalId == publicationId &&
|
||||||
|
tTask.connectorName == connectorName);
|
||||||
|
|
||||||
|
if (task is null)
|
||||||
|
return;
|
||||||
|
taskManager.ExecuteTaskNow(task);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
taskManager.ExecuteTaskNow(task);
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.MapGet("/Tasks/GetRunningTasks",
|
app.MapGet("/Tasks/GetRunningTasks",
|
||||||
@ -109,22 +138,50 @@ app.MapGet("/Queue/GetList",
|
|||||||
|
|
||||||
app.MapPost("/Queue/Enqueue", (string taskType, string? connectorName, string? publicationId) =>
|
app.MapPost("/Queue/Enqueue", (string taskType, string? connectorName, string? publicationId) =>
|
||||||
{
|
{
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
try
|
||||||
TrangaTask? task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
{
|
||||||
tTask.task == pTask && tTask.publication?.internalId == publicationId && tTask.connectorName == connectorName);
|
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
||||||
if (task is null)
|
TrangaTask? task = null;
|
||||||
|
if (connectorName is null || publicationId is null)
|
||||||
|
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
||||||
|
tTask.task == pTask);
|
||||||
|
else
|
||||||
|
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
||||||
|
tTask.task == pTask && tTask.publication?.internalId == publicationId &&
|
||||||
|
tTask.connectorName == connectorName);
|
||||||
|
|
||||||
|
if (task is null)
|
||||||
|
return;
|
||||||
|
taskManager.AddTaskToQueue(task);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
taskManager.AddTaskToQueue(task);
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.MapDelete("/Queue/Dequeue", (string taskType, string? connectorName, string? publicationId) =>
|
app.MapDelete("/Queue/Dequeue", (string taskType, string? connectorName, string? publicationId) =>
|
||||||
{
|
{
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
try
|
||||||
TrangaTask? task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
{
|
||||||
tTask.task == pTask && tTask.publication?.internalId == publicationId && tTask.connectorName == connectorName);
|
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
||||||
if (task is null)
|
TrangaTask? task = null;
|
||||||
|
if (connectorName is null || publicationId is null)
|
||||||
|
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
||||||
|
tTask.task == pTask);
|
||||||
|
else
|
||||||
|
task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
||||||
|
tTask.task == pTask && tTask.publication?.internalId == publicationId &&
|
||||||
|
tTask.connectorName == connectorName);
|
||||||
|
|
||||||
|
if (task is null)
|
||||||
|
return;
|
||||||
|
taskManager.RemoveTaskFromQueue(task);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
taskManager.RemoveTaskFromQueue(task);
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.MapGet("/Settings/Get", () => taskManager.settings);
|
app.MapGet("/Settings/Get", () => taskManager.settings);
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
|
|
||||||
WORKDIR /src
|
|
||||||
COPY ["Tranga-CLI/Tranga-CLI.csproj", "Tranga-CLI/"]
|
|
||||||
RUN dotnet restore "Tranga-CLI/Tranga-CLI.csproj"
|
|
||||||
COPY . .
|
|
||||||
WORKDIR "/src/Tranga-CLI"
|
|
||||||
RUN dotnet build "Tranga-CLI.csproj" -c Release -o /app/build
|
|
||||||
|
|
||||||
FROM build AS publish
|
|
||||||
RUN dotnet publish "Tranga-CLI.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
|
||||||
|
|
||||||
FROM base AS final
|
|
||||||
WORKDIR /app
|
|
||||||
COPY --from=publish /app/publish .
|
|
||||||
ENTRYPOINT ["dotnet", "Tranga-CLI.dll"]
|
|
@ -1,3 +1,4 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Komga/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Komga/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Taskmanager/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tranga/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tranga/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -16,7 +16,9 @@ public abstract class Connector
|
|||||||
|
|
||||||
protected Logger? logger;
|
protected Logger? logger;
|
||||||
|
|
||||||
protected Connector(string downloadLocation, Logger? logger)
|
protected string imageCachePath;
|
||||||
|
|
||||||
|
protected Connector(string downloadLocation, string imageCachePath, Logger? logger)
|
||||||
{
|
{
|
||||||
this.downloadLocation = downloadLocation;
|
this.downloadLocation = downloadLocation;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
@ -24,6 +26,7 @@ public abstract class Connector
|
|||||||
{
|
{
|
||||||
//RequestTypes for RateLimits
|
//RequestTypes for RateLimits
|
||||||
}, logger);
|
}, logger);
|
||||||
|
this.imageCachePath = imageCachePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract string name { get; } //Name of the Connector (e.g. Website)
|
public abstract string name { get; } //Name of the Connector (e.g. Website)
|
||||||
|
@ -14,11 +14,11 @@ public class MangaDex : Connector
|
|||||||
Manga,
|
Manga,
|
||||||
Feed,
|
Feed,
|
||||||
AtHomeServer,
|
AtHomeServer,
|
||||||
Cover,
|
CoverUrl,
|
||||||
Author
|
Author,
|
||||||
}
|
}
|
||||||
|
|
||||||
public MangaDex(string downloadLocation, Logger? logger) : base(downloadLocation, logger)
|
public MangaDex(string downloadLocation, string imageCachePath, Logger? logger) : base(downloadLocation, imageCachePath, logger)
|
||||||
{
|
{
|
||||||
name = "MangaDex";
|
name = "MangaDex";
|
||||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||||
@ -26,7 +26,7 @@ public class MangaDex : Connector
|
|||||||
{(byte)RequestType.Manga, 250},
|
{(byte)RequestType.Manga, 250},
|
||||||
{(byte)RequestType.Feed, 250},
|
{(byte)RequestType.Feed, 250},
|
||||||
{(byte)RequestType.AtHomeServer, 40},
|
{(byte)RequestType.AtHomeServer, 40},
|
||||||
{(byte)RequestType.Cover, 250},
|
{(byte)RequestType.CoverUrl, 250},
|
||||||
{(byte)RequestType.Author, 250}
|
{(byte)RequestType.Author, 250}
|
||||||
}, logger);
|
}, logger);
|
||||||
}
|
}
|
||||||
@ -98,6 +98,12 @@ public class MangaDex : Connector
|
|||||||
authorId = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue<string>() == "author")!["id"]!.GetValue<string>();
|
authorId = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue<string>() == "author")!["id"]!.GetValue<string>();
|
||||||
}
|
}
|
||||||
string? coverUrl = GetCoverUrl(publicationId, posterId);
|
string? coverUrl = GetCoverUrl(publicationId, posterId);
|
||||||
|
string? coverCacheName = null;
|
||||||
|
if (coverUrl is not null)
|
||||||
|
{
|
||||||
|
DownloadClient.RequestResult coverResult = downloadClient.MakeRequest(coverUrl, (byte)RequestType.AtHomeServer);
|
||||||
|
coverCacheName = SaveImage(coverUrl, coverResult.result);
|
||||||
|
}
|
||||||
string? author = GetAuthor(authorId);
|
string? author = GetAuthor(authorId);
|
||||||
|
|
||||||
Dictionary<string, string> linksDict = new();
|
Dictionary<string, string> linksDict = new();
|
||||||
@ -127,6 +133,7 @@ public class MangaDex : Connector
|
|||||||
altTitlesDict,
|
altTitlesDict,
|
||||||
tags.ToArray(),
|
tags.ToArray(),
|
||||||
coverUrl,
|
coverUrl,
|
||||||
|
coverCacheName,
|
||||||
linksDict,
|
linksDict,
|
||||||
year,
|
year,
|
||||||
originalLanguage,
|
originalLanguage,
|
||||||
@ -232,7 +239,7 @@ public class MangaDex : Connector
|
|||||||
|
|
||||||
//Request information where to download Cover
|
//Request information where to download Cover
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest($"https://api.mangadex.org/cover/{posterId}", (byte)RequestType.Cover);
|
downloadClient.MakeRequest($"https://api.mangadex.org/cover/{posterId}", (byte)RequestType.CoverUrl);
|
||||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||||
return null;
|
return null;
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
@ -292,4 +299,15 @@ public class MangaDex : Connector
|
|||||||
//Download cover-Image
|
//Download cover-Image
|
||||||
DownloadImage(publication.posterUrl, Path.Join(downloadLocation, publication.folderName, $"cover.{extension}"), this.downloadClient, (byte)RequestType.AtHomeServer);
|
DownloadImage(publication.posterUrl, Path.Join(downloadLocation, publication.folderName, $"cover.{extension}"), this.downloadClient, (byte)RequestType.AtHomeServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string SaveImage(string url, Stream imageData)
|
||||||
|
{
|
||||||
|
string[] split = url.Split('/');
|
||||||
|
string filename = split[^1];
|
||||||
|
string saveImagePath = Path.Join(imageCachePath, filename);
|
||||||
|
using MemoryStream ms = new();
|
||||||
|
imageData.CopyTo(ms);
|
||||||
|
File.WriteAllBytes(saveImagePath, ms.ToArray());
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System.Net.Http.Headers;
|
using System.Net;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
using Logging;
|
using Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -45,9 +46,17 @@ public class Komga
|
|||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Libraries");
|
logger?.WriteLine(this.GetType().ToString(), $"Getting Libraries");
|
||||||
Stream data = NetClient.MakeRequest($"{baseUrl}/api/v1/libraries", auth);
|
Stream data = NetClient.MakeRequest($"{baseUrl}/api/v1/libraries", auth);
|
||||||
|
if (data == Stream.Null)
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"No libraries returned");
|
||||||
|
return Array.Empty<KomgaLibrary>();
|
||||||
|
}
|
||||||
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
||||||
if (result is null)
|
if (result is null)
|
||||||
|
{
|
||||||
|
logger?.WriteLine(this.GetType().ToString(), $"No libraries returned");
|
||||||
return Array.Empty<KomgaLibrary>();
|
return Array.Empty<KomgaLibrary>();
|
||||||
|
}
|
||||||
|
|
||||||
HashSet<KomgaLibrary> ret = new();
|
HashSet<KomgaLibrary> ret = new();
|
||||||
|
|
||||||
@ -89,37 +98,51 @@ public class Komga
|
|||||||
{
|
{
|
||||||
public static Stream MakeRequest(string url, string auth)
|
public static Stream MakeRequest(string url, string auth)
|
||||||
{
|
{
|
||||||
HttpClient client = new();
|
HttpClientHandler clientHandler = new ();
|
||||||
HttpRequestMessage requestMessage = new HttpRequestMessage
|
clientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => true;
|
||||||
|
HttpClient client = new(clientHandler);
|
||||||
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", auth);
|
||||||
|
|
||||||
|
HttpRequestMessage requestMessage = new ()
|
||||||
{
|
{
|
||||||
Method = HttpMethod.Get,
|
Method = HttpMethod.Get,
|
||||||
RequestUri = new Uri(url),
|
RequestUri = new Uri(url)
|
||||||
Headers =
|
|
||||||
{
|
|
||||||
{ "Accept", "application/json" },
|
|
||||||
{ "Authorization", new AuthenticationHeaderValue("Basic", auth).ToString() }
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
HttpResponseMessage response = client.Send(requestMessage);
|
HttpResponseMessage response = client.Send(requestMessage);
|
||||||
Stream resultString = response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null;
|
Stream ret;
|
||||||
return resultString;
|
if (response.StatusCode is HttpStatusCode.Unauthorized)
|
||||||
|
{
|
||||||
|
ret = MakeRequest(response.RequestMessage!.RequestUri!.AbsoluteUri, auth);
|
||||||
|
}else
|
||||||
|
return response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool MakePost(string url, string auth)
|
public static bool MakePost(string url, string auth)
|
||||||
{
|
{
|
||||||
HttpClient client = new();
|
HttpClientHandler clientHandler = new HttpClientHandler();
|
||||||
HttpRequestMessage requestMessage = new HttpRequestMessage
|
clientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => true;
|
||||||
|
HttpClient client = new(clientHandler)
|
||||||
{
|
{
|
||||||
Method = HttpMethod.Post,
|
DefaultRequestHeaders =
|
||||||
RequestUri = new Uri(url),
|
|
||||||
Headers =
|
|
||||||
{
|
{
|
||||||
{ "Accept", "application/json" },
|
{ "Accept", "application/json" },
|
||||||
{ "Authorization", new AuthenticationHeaderValue("Basic", auth).ToString() }
|
{ "Authorization", new AuthenticationHeaderValue("Basic", auth).ToString() }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
HttpRequestMessage requestMessage = new HttpRequestMessage
|
||||||
|
{
|
||||||
|
Method = HttpMethod.Post,
|
||||||
|
RequestUri = new Uri(url)
|
||||||
|
};
|
||||||
HttpResponseMessage response = client.Send(requestMessage);
|
HttpResponseMessage response = client.Send(requestMessage);
|
||||||
return response.IsSuccessStatusCode;
|
bool ret;
|
||||||
|
if (response.StatusCode is HttpStatusCode.Unauthorized)
|
||||||
|
{
|
||||||
|
ret = MakePost(response.RequestMessage!.RequestUri!.AbsoluteUri, auth);
|
||||||
|
}else
|
||||||
|
return response.IsSuccessStatusCode;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,6 +15,7 @@ public readonly struct Publication
|
|||||||
public string? description { get; }
|
public string? description { get; }
|
||||||
public string[] tags { get; }
|
public string[] tags { get; }
|
||||||
public string? posterUrl { get; }
|
public string? posterUrl { get; }
|
||||||
|
public string? coverFileNameInCache { get; }
|
||||||
public Dictionary<string,string> links { get; }
|
public Dictionary<string,string> links { get; }
|
||||||
public int? year { get; }
|
public int? year { get; }
|
||||||
public string? originalLanguage { get; }
|
public string? originalLanguage { get; }
|
||||||
@ -23,13 +24,14 @@ public readonly struct Publication
|
|||||||
public string publicationId { get; }
|
public string publicationId { get; }
|
||||||
public string internalId { get; }
|
public string internalId { get; }
|
||||||
|
|
||||||
public Publication(string sortName, string? author, string? description, Dictionary<string,string> altTitles, string[] tags, string? posterUrl, Dictionary<string,string>? links, int? year, string? originalLanguage, string status, string publicationId)
|
public Publication(string sortName, string? author, string? description, Dictionary<string,string> altTitles, string[] tags, string? posterUrl, string? coverFileNameInCache, Dictionary<string,string>? links, int? year, string? originalLanguage, string status, string publicationId)
|
||||||
{
|
{
|
||||||
this.sortName = sortName;
|
this.sortName = sortName;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.altTitles = altTitles;
|
this.altTitles = altTitles;
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
|
this.coverFileNameInCache = coverFileNameInCache;
|
||||||
this.posterUrl = posterUrl;
|
this.posterUrl = posterUrl;
|
||||||
this.links = links ?? new Dictionary<string, string>();
|
this.links = links ?? new Dictionary<string, string>();
|
||||||
this.year = year;
|
this.year = year;
|
||||||
|
@ -21,11 +21,12 @@ public class TaskManager
|
|||||||
|
|
||||||
/// <param name="downloadFolderPath">Local path to save data (Manga) to</param>
|
/// <param name="downloadFolderPath">Local path to save data (Manga) to</param>
|
||||||
/// <param name="workingDirectory">Path to the working directory</param>
|
/// <param name="workingDirectory">Path to the working directory</param>
|
||||||
|
/// <param name="imageCachePath">Path to the cover-image cache</param>
|
||||||
/// <param name="komgaBaseUrl">The Url of the Komga-instance that you want to update</param>
|
/// <param name="komgaBaseUrl">The Url of the Komga-instance that you want to update</param>
|
||||||
/// <param name="komgaUsername">The Komga username</param>
|
/// <param name="komgaUsername">The Komga username</param>
|
||||||
/// <param name="komgaPassword">The Komga password</param>
|
/// <param name="komgaPassword">The Komga password</param>
|
||||||
/// <param name="logger"></param>
|
/// <param name="logger"></param>
|
||||||
public TaskManager(string downloadFolderPath, string workingDirectory, string? komgaBaseUrl = null, string? komgaUsername = null, string? komgaPassword = null, Logger? logger = null)
|
public TaskManager(string downloadFolderPath, string workingDirectory, string imageCachePath, string? komgaBaseUrl = null, string? komgaUsername = null, string? komgaPassword = null, Logger? logger = null)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
_allTasks = new HashSet<TrangaTask>();
|
_allTasks = new HashSet<TrangaTask>();
|
||||||
@ -37,7 +38,7 @@ public class TaskManager
|
|||||||
this.settings = new TrangaSettings(downloadFolderPath, workingDirectory, newKomga);
|
this.settings = new TrangaSettings(downloadFolderPath, workingDirectory, newKomga);
|
||||||
ExportData();
|
ExportData();
|
||||||
|
|
||||||
this._connectors = new Connector[]{ new MangaDex(downloadFolderPath, logger) };
|
this._connectors = new Connector[]{ new MangaDex(downloadFolderPath, imageCachePath, logger) };
|
||||||
foreach(Connector cConnector in this._connectors)
|
foreach(Connector cConnector in this._connectors)
|
||||||
_taskQueue.Add(cConnector, new List<TrangaTask>());
|
_taskQueue.Add(cConnector, new List<TrangaTask>());
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ public class TaskManager
|
|||||||
public TaskManager(TrangaSettings settings, Logger? logger = null)
|
public TaskManager(TrangaSettings settings, Logger? logger = null)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this._connectors = new Connector[]{ new MangaDex(settings.downloadLocation, logger) };
|
this._connectors = new Connector[]{ new MangaDex(settings.downloadLocation, settings.coverImageCache, logger) };
|
||||||
foreach(Connector cConnector in this._connectors)
|
foreach(Connector cConnector in this._connectors)
|
||||||
_taskQueue.Add(cConnector, new List<TrangaTask>());
|
_taskQueue.Add(cConnector, new List<TrangaTask>());
|
||||||
_allTasks = new HashSet<TrangaTask>();
|
_allTasks = new HashSet<TrangaTask>();
|
||||||
|
@ -9,6 +9,7 @@ public class TrangaSettings
|
|||||||
[JsonIgnore]public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
[JsonIgnore]public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
||||||
[JsonIgnore]public string tasksFilePath => Path.Join(workingDirectory, "tasks.json");
|
[JsonIgnore]public string tasksFilePath => Path.Join(workingDirectory, "tasks.json");
|
||||||
[JsonIgnore]public string knownPublicationsPath => Path.Join(workingDirectory, "knownPublications.json");
|
[JsonIgnore]public string knownPublicationsPath => Path.Join(workingDirectory, "knownPublications.json");
|
||||||
|
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
||||||
public Komga? komga { get; set; }
|
public Komga? komga { get; set; }
|
||||||
|
|
||||||
public TrangaSettings(string downloadLocation, string workingDirectory, Komga? komga)
|
public TrangaSettings(string downloadLocation, string workingDirectory, Komga? komga)
|
||||||
|
4
Website/Dockerfile
Normal file
4
Website/Dockerfile
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
FROM nginx:alpine3.17-slim
|
||||||
|
COPY . /usr/share/nginx/html
|
||||||
|
EXPOSE 80
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
@ -1,4 +1,23 @@
|
|||||||
const apiUri = "http://localhost:5177";
|
let apiUri = `http://${window.location.host.split(':')[0]}:6531`
|
||||||
|
|
||||||
|
if(getCookie("apiUri") != ""){
|
||||||
|
apiUri = getCookie("apiUri");
|
||||||
|
}
|
||||||
|
function getCookie(cname) {
|
||||||
|
let name = cname + "=";
|
||||||
|
let decodedCookie = decodeURIComponent(document.cookie);
|
||||||
|
let ca = decodedCookie.split(';');
|
||||||
|
for(let i = 0; i < ca.length; i++) {
|
||||||
|
let c = ca[i];
|
||||||
|
while (c.charAt(0) == ' ') {
|
||||||
|
c = c.substring(1);
|
||||||
|
}
|
||||||
|
if (c.indexOf(name) == 0) {
|
||||||
|
return c.substring(name.length, c.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
async function GetData(uri){
|
async function GetData(uri){
|
||||||
let request = await fetch(uri, {
|
let request = await fetch(uri, {
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
</window-titlebar>
|
</window-titlebar>
|
||||||
<window-content>
|
<window-content>
|
||||||
<addtask-settings>
|
<addtask-settings>
|
||||||
<addtask-setting><label for="selectReccurrence">Recurrence</label><input id="selectReccurrence" type="time" value="01:00" step="3600"></addtask-setting>
|
<addtask-setting><label for="selectReccurrence">Recurrence</label><input id="selectReccurrence" type="time" value="01:00:00" step="3600"></addtask-setting>
|
||||||
<addtask-setting><label for="connectors">Connector</label>
|
<addtask-setting><label for="connectors">Connector</label>
|
||||||
<select id="connectors">
|
<select id="connectors">
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
@ -82,14 +82,16 @@
|
|||||||
<settingstab id="settingstab">
|
<settingstab id="settingstab">
|
||||||
<span class="title">Download Location:</span>
|
<span class="title">Download Location:</span>
|
||||||
<span id="downloadLocation"></span>
|
<span id="downloadLocation"></span>
|
||||||
|
<span class="title">API-URI</span>
|
||||||
|
<label for="settingApiUri"></label><input placeholder="https://" type="text" id="settingApiUri">
|
||||||
<komga-settings>
|
<komga-settings>
|
||||||
<span class="title">Komga</span>
|
<span class="title">Komga</span>
|
||||||
<div>Configured: <span id="komgaConfigured">✅❌</span></div>
|
<div>Configured: <span id="komgaConfigured">✅❌</span></div>
|
||||||
<label for="komgaUrl"></label><input placeholder="URL" id="komgaUrl" type="text">
|
<label for="komgaUrl"></label><input placeholder="URL" id="komgaUrl" type="text">
|
||||||
<label for="komgaUsername"></label><input placeholder="Username" id="komgaUsername" type="text">
|
<label for="komgaUsername"></label><input placeholder="Username" id="komgaUsername" type="text">
|
||||||
<label for="komgaPassword"></label><input placeholder="Password" id="komgaPassword" type="password">
|
<label for="komgaPassword"></label><input placeholder="Password" id="komgaPassword" type="password">
|
||||||
<div><label for="komgaUpdateTime" style="margin-right: 5px;">Update Time</label><input id="komgaUpdateTime" type="time" value="00:01"></div>
|
<div><label for="komgaUpdateTime" style="margin-right: 5px;">Update Time</label><input id="komgaUpdateTime" type="time" value="00:01:00" step="10"></div>
|
||||||
<input type="submit" value="Update" onclick="UpdateSettingsClick()">
|
<input type="submit" value="Update" onclick="UpdateKomgaSettings()">
|
||||||
</komga-settings>
|
</komga-settings>
|
||||||
</settingstab>
|
</settingstab>
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ const settingKomgaUser = document.querySelector("#komgaUsername");
|
|||||||
const settingKomgaPass = document.querySelector("#komgaPassword");
|
const settingKomgaPass = document.querySelector("#komgaPassword");
|
||||||
const settingKomgaTime = document.querySelector("#komgaUpdateTime");
|
const settingKomgaTime = document.querySelector("#komgaUpdateTime");
|
||||||
const settingKomgaConfigured = document.querySelector("#komgaConfigured");
|
const settingKomgaConfigured = document.querySelector("#komgaConfigured");
|
||||||
|
const settingApiUri = document.querySelector("#settingApiUri");
|
||||||
|
|
||||||
|
|
||||||
settingsCog.addEventListener("click", () => OpenSettings());
|
settingsCog.addEventListener("click", () => OpenSettings());
|
||||||
@ -53,6 +54,18 @@ document.querySelector("#blurBackgroundTaskPopup").addEventListener("click", ()
|
|||||||
document.querySelector("#blurBackgroundPublicationPopup").addEventListener("click", () => HidePublicationPopup());
|
document.querySelector("#blurBackgroundPublicationPopup").addEventListener("click", () => HidePublicationPopup());
|
||||||
publicationDelete.addEventListener("click", () => DeleteTaskClick());
|
publicationDelete.addEventListener("click", () => DeleteTaskClick());
|
||||||
publicationAdd.addEventListener("click", () => AddTaskClick());
|
publicationAdd.addEventListener("click", () => AddTaskClick());
|
||||||
|
settingApiUri.addEventListener("keypress", (event) => {
|
||||||
|
if(event.key === "Enter"){
|
||||||
|
apiUri = settingApiUri.value;
|
||||||
|
setTimeout(() => GetSettingsClick(), 100);
|
||||||
|
document.cookie = `apiUri=${apiUri};`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
searchPublicationQuery.addEventListener("keypress", (event) => {
|
||||||
|
if(event.key === "Enter"){
|
||||||
|
NewSearch();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let availableConnectors;
|
let availableConnectors;
|
||||||
GetAvailableControllers()
|
GetAvailableControllers()
|
||||||
@ -66,11 +79,6 @@ GetAvailableControllers()
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
searchPublicationQuery.addEventListener("keypress", (event) => {
|
|
||||||
if(event.key === "Enter"){
|
|
||||||
NewSearch();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function NewSearch(){
|
function NewSearch(){
|
||||||
//Disable inputs
|
//Disable inputs
|
||||||
@ -103,7 +111,7 @@ function CreatePublication(publication, connector){
|
|||||||
var publicationElement = document.createElement('publication');
|
var publicationElement = document.createElement('publication');
|
||||||
publicationElement.setAttribute("id", publication.internalId);
|
publicationElement.setAttribute("id", publication.internalId);
|
||||||
var img = document.createElement('img');
|
var img = document.createElement('img');
|
||||||
img.src = publication.posterUrl;
|
img.src = `imageCache/${publication.coverFileNameInCache}`;
|
||||||
publicationElement.appendChild(img);
|
publicationElement.appendChild(img);
|
||||||
var info = document.createElement('publication-information');
|
var info = document.createElement('publication-information');
|
||||||
var connectorName = document.createElement('connector-name');
|
var connectorName = document.createElement('connector-name');
|
||||||
@ -210,10 +218,13 @@ function OpenSettings(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function GetSettingsClick(){
|
function GetSettingsClick(){
|
||||||
|
settingApiUri.value = "";
|
||||||
settingKomgaUrl.value = "";
|
settingKomgaUrl.value = "";
|
||||||
settingKomgaUser.value = "";
|
settingKomgaUser.value = "";
|
||||||
settingKomgaPass.value = "";
|
settingKomgaPass.value = "";
|
||||||
|
|
||||||
|
settingApiUri.placeholder = apiUri;
|
||||||
|
|
||||||
GetSettings().then(json => {
|
GetSettings().then(json => {
|
||||||
settingDownloadLocation.innerText = json.downloadLocation;
|
settingDownloadLocation.innerText = json.downloadLocation;
|
||||||
if(json.komga != null)
|
if(json.komga != null)
|
||||||
@ -228,7 +239,7 @@ function GetSettingsClick(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function UpdateSettingsClick(){
|
function UpdateKomgaSettings(){
|
||||||
var auth = utf8_to_b64(`${settingKomgaUser.value}:${settingKomgaPass.value}`);
|
var auth = utf8_to_b64(`${settingKomgaUser.value}:${settingKomgaPass.value}`);
|
||||||
console.log(auth);
|
console.log(auth);
|
||||||
UpdateSettings("", settingKomgaUrl.value, auth);
|
UpdateSettings("", settingKomgaUrl.value, auth);
|
||||||
|
@ -132,6 +132,13 @@ settingstab > * {
|
|||||||
margin: 0 20px;
|
margin: 0 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settingstab input {
|
||||||
|
padding: 3px;
|
||||||
|
border-radius: 3px;
|
||||||
|
border: 0;
|
||||||
|
margin: 2px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
settingstab .title {
|
settingstab .title {
|
||||||
font-size: 14pt;
|
font-size: 14pt;
|
||||||
font-weight: bolder;
|
font-weight: bolder;
|
||||||
@ -145,14 +152,8 @@ komga-settings {
|
|||||||
flex-wrap: nowrap;
|
flex-wrap: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
komga-settings > * {
|
|
||||||
margin: 2px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
komga-settings input {
|
komga-settings input {
|
||||||
padding: 3px;
|
margin: 2px 0;
|
||||||
border-radius: 3px;
|
|
||||||
border: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#addPublication {
|
#addPublication {
|
||||||
|
17
docker-compose.yaml
Normal file
17
docker-compose.yaml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
services:
|
||||||
|
tranga-api:
|
||||||
|
image: glax/tranga-api:latest
|
||||||
|
container_name: tranga-api
|
||||||
|
volumes:
|
||||||
|
- ./tranga:/usr/share/Tranga-API #1 when replacing ./tranga replace #2 with same value
|
||||||
|
- ./Manga:/Manga
|
||||||
|
ports:
|
||||||
|
- 6531:80
|
||||||
|
restart: unless-stopped
|
||||||
|
tranga-website:
|
||||||
|
image: glax/tranga-website:latest
|
||||||
|
container_name: tranga-website
|
||||||
|
ports:
|
||||||
|
- 9555:80
|
||||||
|
volumes:
|
||||||
|
- ./tranga/imageCache:/usr/share/nginx/html/imageCache #2 when replacing Point to same value as #1/imageCache
|
Reference in New Issue
Block a user