From ae1184320f6e6a55ae9d185e7bb2793c6b3d64d1 Mon Sep 17 00:00:00 2001 From: glax Date: Tue, 5 Sep 2023 19:50:56 +0200 Subject: [PATCH] Added API: customFolderName to Jobs/MonitorManga and Jobs/DownloadNewChapters resolves #30 --- Tranga/Manga.cs | 11 ++++++++++- Tranga/Server.cs | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index 247be53..b37b675 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -28,7 +28,7 @@ public struct Manga public string? originalLanguage { get; } // ReSharper disable once MemberCanBePrivate.Global public string status { get; } - public string folderName { get; } + public string folderName { get; private set; } public string publicationId { get; } public string internalId { get; } public float ignoreChaptersBelow { get; set; } @@ -73,6 +73,15 @@ public struct Manga return publicationFolder; } + public void MovePublicationFolder(string downloadDirectory, string newFolderName) + { + string oldPath = Path.Join(downloadDirectory, this.folderName); + this.folderName = newFolderName; + string newPath = CreatePublicationFolder(downloadDirectory); + if(Directory.Exists(oldPath)) + Directory.Move(oldPath, newPath); + } + public void SaveSeriesInfoJson(string downloadDirectory) { string publicationFolder = CreatePublicationFolder(downloadDirectory); diff --git a/Tranga/Server.cs b/Tranga/Server.cs index 603b20c..1b429d9 100644 --- a/Tranga/Server.cs +++ b/Tranga/Server.cs @@ -222,7 +222,7 @@ public class Server : GlobalBase private void HandlePost(HttpListenerRequest request, HttpListenerResponse response) { Dictionary requestVariables = GetRequestVariables(request.Url!.Query); - string? connectorName, internalId, jobId, chapterNumStr; + string? connectorName, internalId, jobId, chapterNumStr, customFolderName; MangaConnector connector; Manga manga; Job? job; @@ -251,6 +251,10 @@ public class Server : GlobalBase } manga.ignoreChaptersBelow = chapterNum; } + + if (requestVariables.TryGetValue("customFolderName", out customFolderName)) + manga.MovePublicationFolder(settings.downloadLocation, customFolderName); + _parent.jobBoss.AddJob(new DownloadNewChapters(this, connector, manga, true, interval)); SendResponse(HttpStatusCode.Accepted, response); break; @@ -274,6 +278,10 @@ public class Server : GlobalBase } manga.ignoreChaptersBelow = chapterNum; } + + if (requestVariables.TryGetValue("customFolderName", out customFolderName)) + manga.MovePublicationFolder(settings.downloadLocation, customFolderName); + _parent.jobBoss.AddJob(new DownloadNewChapters(this, connector, manga, false)); SendResponse(HttpStatusCode.Accepted, response); break;