From 07c6081c03300baa85f7ff50a2ed16905bbb18ce Mon Sep 17 00:00:00 2001 From: Glax Date: Sun, 27 Oct 2024 03:49:55 +0100 Subject: [PATCH] #236 --- Tranga/MangaConnectors/MangaConnector.cs | 6 +++--- Tranga/Server/v2Settings.cs | 9 +++++---- Tranga/TrangaSettings.cs | 16 ++++++++-------- docs/API_Calls_v2.md | 10 +++++----- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Tranga/MangaConnectors/MangaConnector.cs b/Tranga/MangaConnectors/MangaConnector.cs index 20b8472..f87e4bf 100644 --- a/Tranga/MangaConnectors/MangaConnector.cs +++ b/Tranga/MangaConnectors/MangaConnector.cs @@ -222,7 +222,7 @@ public abstract class MangaConnector : GlobalBase private void ProcessImage(string imagePath) { - if (!TrangaSettings.bwImages && !TrangaSettings.compressImages) + if (!TrangaSettings.bwImages && TrangaSettings.compression == 100) return; DateTime start = DateTime.Now; using Image image = Image.Load(imagePath); @@ -231,9 +231,9 @@ public abstract class MangaConnector : GlobalBase image.Mutate(i => i.ApplyProcessor(new AdaptiveThresholdProcessor())); image.SaveAsJpeg(imagePath, new JpegEncoder() { - Quality = TrangaSettings.compressImages ? 30 : 75 + Quality = TrangaSettings.compression }); - Log($"Image processing took {DateTime.Now.Subtract(start):s\\.fff} B/W:{TrangaSettings.bwImages} Compress:{TrangaSettings.compressImages}"); + Log($"Image processing took {DateTime.Now.Subtract(start):s\\.fff} B/W:{TrangaSettings.bwImages} Compression: {TrangaSettings.compression}"); } protected HttpStatusCode DownloadChapterImages(string[] imageUrls, Chapter chapter, RequestType requestType, string? referrer = null, ProgressToken? progressToken = null) diff --git a/Tranga/Server/v2Settings.cs b/Tranga/Server/v2Settings.cs index 045312f..4e0212e 100644 --- a/Tranga/Server/v2Settings.cs +++ b/Tranga/Server/v2Settings.cs @@ -88,15 +88,16 @@ public partial class Server private ValueTuple GetV2SettingsCompressImages(GroupCollection groups, Dictionary requestParameters) { - return new ValueTuple(HttpStatusCode.OK, TrangaSettings.compressImages); + return new ValueTuple(HttpStatusCode.OK, TrangaSettings.compression); } private ValueTuple PostV2SettingsCompressImages(GroupCollection groups, Dictionary requestParameters) { - if (!requestParameters.TryGetValue("value", out string? trueFalseStr) || - !bool.TryParse(trueFalseStr, out bool trueFalse)) + if (!requestParameters.TryGetValue("value", out string? valueStr) || + !int.TryParse(valueStr, out int value) + || value != int.Clamp(value, 1, 100)) return new ValueTuple(HttpStatusCode.InternalServerError, "Errors parsing 'value'"); - TrangaSettings.UpdateCompressImages(trueFalse); + TrangaSettings.UpdateCompressImages(value); return new ValueTuple(HttpStatusCode.OK, null); } diff --git a/Tranga/TrangaSettings.cs b/Tranga/TrangaSettings.cs index 16919c8..dfa1590 100644 --- a/Tranga/TrangaSettings.cs +++ b/Tranga/TrangaSettings.cs @@ -17,7 +17,7 @@ public static class TrangaSettings public static string userAgent { get; private set; } = DefaultUserAgent; public static bool bufferLibraryUpdates { get; private set; } = false; public static bool bufferNotifications { get; private set; } = false; - public static bool compressImages { get; private set; } = true; + public static int compression{ get; private set; } = 40; public static bool bwImages { get; private set; } = false; [JsonIgnore] public static string settingsFilePath => Path.Join(workingDirectory, "settings.json"); [JsonIgnore] public static string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json"); @@ -53,7 +53,7 @@ public static class TrangaSettings public static void CreateOrUpdate(string? downloadDirectory = null, string? pWorkingDirectory = null, int? pApiPortNumber = null, string? pUserAgent = null, bool? pAprilFoolsMode = null, - bool? pBufferLibraryUpdates = null, bool? pBufferNotifications = null, bool? pCompressImages = null, bool? pbwImages = null) + bool? pBufferLibraryUpdates = null, bool? pBufferNotifications = null, int? pCompression = null, bool? pbwImages = null) { if(pWorkingDirectory is null && File.Exists(settingsFilePath)) LoadFromWorkingDirectory(workingDirectory); @@ -64,7 +64,7 @@ public static class TrangaSettings aprilFoolsMode = pAprilFoolsMode ?? aprilFoolsMode; bufferLibraryUpdates = pBufferLibraryUpdates ?? bufferLibraryUpdates; bufferNotifications = pBufferNotifications ?? bufferNotifications; - compressImages = pCompressImages ?? compressImages; + compression = pCompression ?? compression; bwImages = pbwImages ?? bwImages; Directory.CreateDirectory(downloadLocation); Directory.CreateDirectory(workingDirectory); @@ -105,9 +105,9 @@ public static class TrangaSettings ExportSettings(); } - public static void UpdateCompressImages(bool enabled) + public static void UpdateCompressImages(int value) { - compressImages = enabled; + compression = int.Clamp(value, 1, 100); ExportSettings(); } @@ -208,7 +208,7 @@ public static class TrangaSettings jobj.Add("requestLimits", JToken.FromObject(requestLimits)); jobj.Add("bufferLibraryUpdates", JToken.FromObject(bufferLibraryUpdates)); jobj.Add("bufferNotifications", JToken.FromObject(bufferNotifications)); - jobj.Add("compressImages", JToken.FromObject(compressImages)); + jobj.Add("compression", JToken.FromObject(compression)); jobj.Add("bwImages", JToken.FromObject(bwImages)); return jobj; } @@ -234,8 +234,8 @@ public static class TrangaSettings bufferLibraryUpdates = blu.Value()!; if (jobj.TryGetValue("bufferNotifications", out JToken? bn)) bufferNotifications = bn.Value()!; - if (jobj.TryGetValue("compressImages", out JToken? ci)) - compressImages = ci.Value()!; + if (jobj.TryGetValue("compression", out JToken? ci)) + compression = ci.Value()!; if (jobj.TryGetValue("bwImages", out JToken? bwi)) bwImages = bwi.Value()!; } diff --git a/docs/API_Calls_v2.md b/docs/API_Calls_v2.md index 34bbce0..e47bcd4 100644 --- a/docs/API_Calls_v2.md +++ b/docs/API_Calls_v2.md @@ -735,19 +735,19 @@ Returns the current state of the Image-compression setting.
Returns - Boolean + number
### ![POST](https://img.shields.io/badge/POST-00f) `/v2/Settings/CompressImages` -Enables/Disables Imagecompression. +Set the quality of the compression.
Request - | Parameter | Value | - |-----------|------------| - | value | true/false | + | Parameter | Value | + |-----------|-------| + | value | 1-100 |