8 Commits

Author SHA1 Message Date
6aa0ea277b #22 2023-05-25 14:28:56 +02:00
780df1cd6e Created Image-Cache 2023-05-25 14:25:23 +02:00
0b7da2e9cb Merge remote-tracking branch 'origin/master'
# Conflicts:
#	Website/interaction.js
2023-05-25 13:59:06 +02:00
01a059d26b Base 64 images #22 2023-05-25 13:58:54 +02:00
a8dbece237 Base 64 images #22 2023-05-25 13:58:10 +02:00
5efa00e059 Added field posterBase64 to Publication #22 2023-05-25 13:50:48 +02:00
02075ed1b1 Renamed RequestType Cover to CoverUrl 2023-05-25 13:50:08 +02:00
fabd16ccea Remove unnecessary output from dockerfile 2023-05-25 13:49:29 +02:00
10 changed files with 55 additions and 25 deletions

View File

@ -3,13 +3,11 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-env FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-env
WORKDIR /src WORKDIR /src
COPY . /src/ COPY . /src/
RUN ls /src
RUN dotnet restore Tranga-API/Tranga-API.csproj RUN dotnet restore Tranga-API/Tranga-API.csproj
RUN dotnet publish -c Release -o /publish RUN dotnet publish -c Release -o /publish
FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime
WORKDIR /publish WORKDIR /publish
COPY --from=build-env /publish . COPY --from=build-env /publish .
RUN ls /publish
EXPOSE 80 EXPOSE 80
ENTRYPOINT ["dotnet", "/publish/Tranga-API.dll"] ENTRYPOINT ["dotnet", "/publish/Tranga-API.dll"]

View File

@ -8,24 +8,28 @@ string logsFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/va
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(downloadFolderPath);
Directory.CreateDirectory(logsFolderPath); Directory.CreateDirectory(logsFolderPath);
Console.WriteLine($"Application-Folder: {applicationFolderPath}");
Console.WriteLine($"Download-Folder-Path: {downloadFolderPath}");
Console.WriteLine($"Logfile-Path: {logFilePath}");
Console.WriteLine($"Settings-File-Path: {settingsFilePath}");
Logger logger = new(new[] { Logger.LoggerType.FileLogger, Logger.LoggerType.ConsoleLogger }, Console.Out, Console.Out.Encoding, logFilePath); Logger logger = new(new[] { Logger.LoggerType.FileLogger, Logger.LoggerType.ConsoleLogger }, Console.Out, Console.Out.Encoding, logFilePath);
logger.WriteLine("Tranga_CLI", "Loading Taskmanager."); logger.WriteLine("Tranga", "Loading settings.");
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);

View File

@ -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>

View File

@ -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)

View File

@ -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;
}
} }

View File

@ -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;

View File

@ -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>();

View File

@ -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)

View File

@ -111,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');

View File

@ -3,7 +3,7 @@
image: glax/tranga-api:latest image: glax/tranga-api:latest
container_name: tranga-api container_name: tranga-api
volumes: volumes:
- ./tranga:/usr/share/Tranga-API - ./tranga:/usr/share/Tranga-API #1 when replacing ./tranga replace #2 with same value
- ./Manga:/Manga - ./Manga:/Manga
ports: ports:
- 6531:80 - 6531:80
@ -13,3 +13,5 @@
container_name: tranga-website container_name: tranga-website
ports: ports:
- 9555:80 - 9555:80
volumes:
- ./tranga/imageCache:/usr/share/nginx/html/imageCache #2 when replacing Point to same value as #1/imageCache