2
0
This commit is contained in:
Glax 2024-10-27 03:49:55 +01:00
parent 585d7e3380
commit 07c6081c03
4 changed files with 21 additions and 20 deletions

View File

@ -222,7 +222,7 @@ public abstract class MangaConnector : GlobalBase
private void ProcessImage(string imagePath) private void ProcessImage(string imagePath)
{ {
if (!TrangaSettings.bwImages && !TrangaSettings.compressImages) if (!TrangaSettings.bwImages && TrangaSettings.compression == 100)
return; return;
DateTime start = DateTime.Now; DateTime start = DateTime.Now;
using Image image = Image.Load(imagePath); using Image image = Image.Load(imagePath);
@ -231,9 +231,9 @@ public abstract class MangaConnector : GlobalBase
image.Mutate(i => i.ApplyProcessor(new AdaptiveThresholdProcessor())); image.Mutate(i => i.ApplyProcessor(new AdaptiveThresholdProcessor()));
image.SaveAsJpeg(imagePath, new JpegEncoder() 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) protected HttpStatusCode DownloadChapterImages(string[] imageUrls, Chapter chapter, RequestType requestType, string? referrer = null, ProgressToken? progressToken = null)

View File

@ -88,15 +88,16 @@ public partial class Server
private ValueTuple<HttpStatusCode, object?> GetV2SettingsCompressImages(GroupCollection groups, Dictionary<string, string> requestParameters) private ValueTuple<HttpStatusCode, object?> GetV2SettingsCompressImages(GroupCollection groups, Dictionary<string, string> requestParameters)
{ {
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.compressImages); return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.compression);
} }
private ValueTuple<HttpStatusCode, object?> PostV2SettingsCompressImages(GroupCollection groups, Dictionary<string, string> requestParameters) private ValueTuple<HttpStatusCode, object?> PostV2SettingsCompressImages(GroupCollection groups, Dictionary<string, string> requestParameters)
{ {
if (!requestParameters.TryGetValue("value", out string? trueFalseStr) || if (!requestParameters.TryGetValue("value", out string? valueStr) ||
!bool.TryParse(trueFalseStr, out bool trueFalse)) !int.TryParse(valueStr, out int value)
|| value != int.Clamp(value, 1, 100))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "Errors parsing 'value'"); return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "Errors parsing 'value'");
TrangaSettings.UpdateCompressImages(trueFalse); TrangaSettings.UpdateCompressImages(value);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null); return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
} }

View File

@ -17,7 +17,7 @@ public static class TrangaSettings
public static string userAgent { get; private set; } = DefaultUserAgent; public static string userAgent { get; private set; } = DefaultUserAgent;
public static bool bufferLibraryUpdates { get; private set; } = false; public static bool bufferLibraryUpdates { get; private set; } = false;
public static bool bufferNotifications { 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; public static bool bwImages { get; private set; } = false;
[JsonIgnore] public static string settingsFilePath => Path.Join(workingDirectory, "settings.json"); [JsonIgnore] public static string settingsFilePath => Path.Join(workingDirectory, "settings.json");
[JsonIgnore] public static string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.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, public static void CreateOrUpdate(string? downloadDirectory = null, string? pWorkingDirectory = null,
int? pApiPortNumber = null, string? pUserAgent = null, bool? pAprilFoolsMode = 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)) if(pWorkingDirectory is null && File.Exists(settingsFilePath))
LoadFromWorkingDirectory(workingDirectory); LoadFromWorkingDirectory(workingDirectory);
@ -64,7 +64,7 @@ public static class TrangaSettings
aprilFoolsMode = pAprilFoolsMode ?? aprilFoolsMode; aprilFoolsMode = pAprilFoolsMode ?? aprilFoolsMode;
bufferLibraryUpdates = pBufferLibraryUpdates ?? bufferLibraryUpdates; bufferLibraryUpdates = pBufferLibraryUpdates ?? bufferLibraryUpdates;
bufferNotifications = pBufferNotifications ?? bufferNotifications; bufferNotifications = pBufferNotifications ?? bufferNotifications;
compressImages = pCompressImages ?? compressImages; compression = pCompression ?? compression;
bwImages = pbwImages ?? bwImages; bwImages = pbwImages ?? bwImages;
Directory.CreateDirectory(downloadLocation); Directory.CreateDirectory(downloadLocation);
Directory.CreateDirectory(workingDirectory); Directory.CreateDirectory(workingDirectory);
@ -105,9 +105,9 @@ public static class TrangaSettings
ExportSettings(); ExportSettings();
} }
public static void UpdateCompressImages(bool enabled) public static void UpdateCompressImages(int value)
{ {
compressImages = enabled; compression = int.Clamp(value, 1, 100);
ExportSettings(); ExportSettings();
} }
@ -208,7 +208,7 @@ public static class TrangaSettings
jobj.Add("requestLimits", JToken.FromObject(requestLimits)); jobj.Add("requestLimits", JToken.FromObject(requestLimits));
jobj.Add("bufferLibraryUpdates", JToken.FromObject(bufferLibraryUpdates)); jobj.Add("bufferLibraryUpdates", JToken.FromObject(bufferLibraryUpdates));
jobj.Add("bufferNotifications", JToken.FromObject(bufferNotifications)); jobj.Add("bufferNotifications", JToken.FromObject(bufferNotifications));
jobj.Add("compressImages", JToken.FromObject(compressImages)); jobj.Add("compression", JToken.FromObject(compression));
jobj.Add("bwImages", JToken.FromObject(bwImages)); jobj.Add("bwImages", JToken.FromObject(bwImages));
return jobj; return jobj;
} }
@ -234,8 +234,8 @@ public static class TrangaSettings
bufferLibraryUpdates = blu.Value<bool>()!; bufferLibraryUpdates = blu.Value<bool>()!;
if (jobj.TryGetValue("bufferNotifications", out JToken? bn)) if (jobj.TryGetValue("bufferNotifications", out JToken? bn))
bufferNotifications = bn.Value<bool>()!; bufferNotifications = bn.Value<bool>()!;
if (jobj.TryGetValue("compressImages", out JToken? ci)) if (jobj.TryGetValue("compression", out JToken? ci))
compressImages = ci.Value<bool>()!; compression = ci.Value<int>()!;
if (jobj.TryGetValue("bwImages", out JToken? bwi)) if (jobj.TryGetValue("bwImages", out JToken? bwi))
bwImages = bwi.Value<bool>()!; bwImages = bwi.Value<bool>()!;
} }

View File

@ -735,19 +735,19 @@ Returns the current state of the Image-compression setting.
<details> <details>
<summary>Returns</summary> <summary>Returns</summary>
Boolean number
</details> </details>
### <sub>![POST](https://img.shields.io/badge/POST-00f)</sub> `/v2/Settings/CompressImages` ### <sub>![POST](https://img.shields.io/badge/POST-00f)</sub> `/v2/Settings/CompressImages`
Enables/Disables Imagecompression. Set the quality of the compression.
<details> <details>
<summary>Request</summary> <summary>Request</summary>
| Parameter | Value | | Parameter | Value |
|-----------|------------| |-----------|-------|
| value | true/false | | value | 1-100 |
</details> </details>
<details> <details>