Skip to content

Commit

Permalink
Merge pull request #163 from C9Glax/cuttingedge
Browse files Browse the repository at this point in the history
Connector Bugs, AprilFools Mode
  • Loading branch information
C9Glax authored Apr 18, 2024
2 parents 2872eee + 8f8d019 commit 0260868
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 158 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/docker-image-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Docker Image CI

on:
push:
branches: [ "dev" ]
workflow_dispatch:

jobs:

build:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

# https://github.com/docker/setup-qemu-action#usage
- name: Set up QEMU
uses: docker/[email protected]

# https://github.com/marketplace/actions/docker-setup-buildx
- name: Set up Docker Buildx
id: buildx
uses: docker/[email protected]

# https://github.com/docker/login-action#docker-hub
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# https://github.com/docker/build-push-action#multi-platform-image
- name: Build and push API
uses: docker/[email protected]
with:
context: ./
file: ./Dockerfile
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
platforms: linux/amd64
pull: true
push: true
tags: |
glax/tranga-api:dev
4 changes: 2 additions & 2 deletions CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public override int Execute([NotNull] CommandContext context, [NotNull] Settings
if(settings.fileLogger is true)
enabledLoggers.Add(Logger.LoggerType.FileLogger);

string? logFilePath = settings.fileLoggerPath ?? "";
Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, logFilePath);
string? logFolderPath = settings.fileLoggerPath ?? "";
Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, logFolderPath);

TrangaSettings? trangaSettings = null;

Expand Down
15 changes: 8 additions & 7 deletions Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public enum LoggerType
private readonly FormattedConsoleLogger? _formattedConsoleLogger;
private readonly MemoryLogger _memoryLogger;

public Logger(LoggerType[] enabledLoggers, TextWriter? stdOut, Encoding? encoding, string? logFilePath)
public Logger(LoggerType[] enabledLoggers, TextWriter? stdOut, Encoding? encoding, string? logFolderPath)
{
this.Encoding = encoding ?? Encoding.UTF8;
if(enabledLoggers.Contains(LoggerType.FileLogger) && (logFilePath is null || logFilePath == ""))
DateTime now = DateTime.Now;
if(enabledLoggers.Contains(LoggerType.FileLogger) && (logFolderPath is null || logFolderPath == ""))
{
DateTime now = DateTime.Now;
logFilePath = Path.Join(LogDirectoryPath,
string filePath = Path.Join(LogDirectoryPath,
$"{now.ToShortDateString()}_{now.Hour}-{now.Minute}-{now.Second}.log");
_fileLogger = new FileLogger(logFilePath, encoding);
}else if (enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is not null)
_fileLogger = new FileLogger(logFilePath, encoding);
_fileLogger = new FileLogger(filePath, encoding);
}else if (enabledLoggers.Contains(LoggerType.FileLogger) && logFolderPath is not null)
_fileLogger = new FileLogger(Path.Join(logFolderPath, $"{now.ToShortDateString()}_{now.Hour}-{now.Minute}-{now.Second}.log") , encoding);


if (enabledLoggers.Contains(LoggerType.ConsoleLogger) && stdOut is not null)
Expand All @@ -43,6 +43,7 @@ public Logger(LoggerType[] enabledLoggers, TextWriter? stdOut, Encoding? encodin
throw new ArgumentException($"stdOut can not be null for LoggerType {LoggerType.ConsoleLogger}");
}
_memoryLogger = new MemoryLogger(encoding);
WriteLine(GetType().ToString(), $"Logfile: {logFilePath}");
}

public void WriteLine(string caller, string? value)
Expand Down
2 changes: 1 addition & 1 deletion Tranga/Jobs/JobBoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void LoadJobsList(HashSet<MangaConnector> connectors)
}

HashSet<string> coverFileNames = cachedPublications.Select(manga => manga.coverFileNameInCache!).ToHashSet();
foreach (string fileName in Directory.GetFiles(settings.coverImageCache))
foreach (string fileName in Directory.GetFiles(settings.coverImageCache)) //Cleanup Unused Covers
{
if(!coverFileNames.Any(existingManga => fileName.Contains(existingManga)))
File.Delete(fileName);
Expand Down
3 changes: 2 additions & 1 deletion Tranga/MangaConnectors/ChromiumDownloadClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text;
using HtmlAgilityPack;
using PuppeteerSharp;
using PuppeteerSharp.Input;

namespace Tranga.MangaConnectors;

Expand Down Expand Up @@ -81,7 +82,7 @@ protected override RequestResult MakeRequestInternal(string url, string? referre
{
if (content.Contains("text/html"))
{
if(clickButton is not null)
if (clickButton is not null && page.QuerySelectorAsync(clickButton).Result is not null)
page.ClickAsync(clickButton).Wait();
string htmlString = page.GetContentAsync().Result;
stream = new MemoryStream(Encoding.Default.GetBytes(htmlString));
Expand Down
6 changes: 4 additions & 2 deletions Tranga/MangaConnectors/MangaConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ protected HttpStatusCode DownloadChapterImages(string[] imageUrls, string saveAr
return HttpStatusCode.Created;

//Create a temporary folder to store images
string tempFolder = Directory.CreateTempSubdirectory().FullName;
string tempFolder = Directory.CreateTempSubdirectory("trangatemp").FullName;

int chapter = 0;
//Download all Images to temporary Folder
Expand All @@ -260,8 +260,10 @@ protected HttpStatusCode DownloadChapterImages(string[] imageUrls, string saveAr
progressToken?.Increment();
}

if(comicInfoPath is not null)
if(comicInfoPath is not null){
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
File.Delete(comicInfoPath); //Delete tmp-file
}

Log($"Creating archive {saveArchiveFilePath}");
//ZIP-it and ship-it
Expand Down
Loading

0 comments on commit 0260868

Please sign in to comment.