Merge recent changes to TrangaSettings backend

This commit is contained in:
Glax 2024-08-26 19:08:59 +02:00
parent 032ee95716
commit 3c3f7bb95a
9 changed files with 22 additions and 22 deletions

View File

@ -70,7 +70,7 @@ public abstract class GlobalBase
internal void ImportManga()
{
string folder = settings.mangaCacheFolderPath;
string folder = TrangaSettings.mangaCacheFolderPath;
Directory.CreateDirectory(folder);
foreach (FileInfo fileInfo in new DirectoryInfo(folder).GetFiles())
@ -91,7 +91,7 @@ public abstract class GlobalBase
private void ExportManga()
{
string folder = settings.mangaCacheFolderPath;
string folder = TrangaSettings.mangaCacheFolderPath;
Directory.CreateDirectory(folder);
foreach (Manga manga in cachedPublications.Values)
{

View File

@ -38,7 +38,7 @@ public class DownloadNewChapters : Job
Log($"Manga {mangaInternalId} is missing! Can not execute job.");
return Array.Empty<Job>();
}
manga.Value.SaveSeriesInfoJson(settings.downloadLocation);
manga.Value.SaveSeriesInfoJson();
Chapter[] chapters = manga.Value.mangaConnector.GetNewChapters(manga.Value, this.translatedLanguage);
this.progressToken.increments = chapters.Length;
List<Job> jobs = new();

View File

@ -195,7 +195,7 @@ public class JobBoss : GlobalBase
string[] coverFiles = Directory.GetFiles(TrangaSettings.coverImageCache);
foreach(string fileName in coverFiles.Where(fileName => !GetAllCachedManga().Any(manga => manga.coverFileNameInCache == fileName)))
File.Delete(fileName);
string[] mangaFiles = Directory.GetFiles(settings.mangaCacheFolderPath);
string[] mangaFiles = Directory.GetFiles(TrangaSettings.mangaCacheFolderPath);
foreach(string fileName in mangaFiles.Where(fileName => !GetAllCachedManga().Any(manga => fileName.Split('.')[0] == manga.internalId)))
File.Delete(fileName);
}

View File

@ -42,7 +42,7 @@ public class UpdateMetadata : Job
}
AddMangaToCache(manga.Value.WithMetadata(updatedManga));
this.manga.Value.SaveSeriesInfoJson(settings.downloadLocation, true);
this.manga.Value.SaveSeriesInfoJson(true);
this.mangaConnector.CopyCoverFromCacheToDownloadLocation((Manga)manga);
this.progressToken.Complete();
}

View File

@ -75,9 +75,9 @@ public partial class Server : GlobalBase, IDisposable
this._parent = parent;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
this._listener.Prefixes.Add($"http://*:{settings.apiPortNumber}/");
this._listener.Prefixes.Add($"http://*:{TrangaSettings.apiPortNumber}/");
else
this._listener.Prefixes.Add($"http://localhost:{settings.apiPortNumber}/");
this._listener.Prefixes.Add($"http://localhost:{TrangaSettings.apiPortNumber}/");
Thread listenThread = new(Listen);
listenThread.Start();
while(_parent.keepRunning && _running)

View File

@ -61,7 +61,7 @@ public partial class Server
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "'interval' Parameter missing, or is not in correct format.");
requestParameters.TryGetValue("language", out string? language);
if (requestParameters.TryGetValue("customFolder", out string? folder))
manga.Value.MovePublicationFolder(settings.downloadLocation, folder);
manga.Value.MovePublicationFolder(TrangaSettings.downloadLocation, folder);
if (requestParameters.TryGetValue("startChapter", out string? startChapterStr) &&
float.TryParse(startChapterStr, out float startChapter))
{

View File

@ -140,7 +140,7 @@ public partial class Server
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Manga with ID '{groups[1].Value} could not be found.'");
if(!requestParameters.TryGetValue("location", out string? newFolder))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.BadRequest, "Parameter 'location' missing.");
manga.Value.MovePublicationFolder(settings.downloadLocation, newFolder);
manga.Value.MovePublicationFolder(TrangaSettings.downloadLocation, newFolder);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
}
}

View File

@ -8,24 +8,24 @@ public partial class Server
{
private ValueTuple<HttpStatusCode, object?> GetV2Settings(GroupCollection groups, Dictionary<string, string> requestParameters)
{
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, settings);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.AsJObject());
}
private ValueTuple<HttpStatusCode, object?> GetV2SettingsUserAgent(GroupCollection groups, Dictionary<string, string> requestParameters)
{
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, settings.userAgent);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.userAgent);
}
private ValueTuple<HttpStatusCode, object?> PostV2SettingsUserAgent(GroupCollection groups, Dictionary<string, string> requestParameters)
{
if (!requestParameters.TryGetValue("value", out string? userAgent))
{
settings.UpdateUserAgent(null);
TrangaSettings.UpdateUserAgent(null);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.Accepted, null);
}
else
{
settings.UpdateUserAgent(userAgent);
TrangaSettings.UpdateUserAgent(userAgent);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
}
}
@ -37,7 +37,7 @@ public partial class Server
private ValueTuple<HttpStatusCode, object?> GetV2SettingsRateLimit(GroupCollection groups, Dictionary<string, string> requestParameters)
{
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, settings.requestLimits);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.requestLimits);
}
private ValueTuple<HttpStatusCode, object?> PostV2SettingsRateLimit(GroupCollection groups, Dictionary<string, string> requestParameters)
@ -47,10 +47,9 @@ public partial class Server
if(!Enum.TryParse(kv.Key, out RequestType requestType) ||
!int.TryParse(kv.Value, out int requestsPerMinute))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, null);
settings.requestLimits[requestType] = requestsPerMinute;
settings.ExportSettings();
TrangaSettings.UpdateRateLimit(requestType, requestsPerMinute);
}
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, settings.requestLimits);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.requestLimits);
}
private ValueTuple<HttpStatusCode, object?> GetV2SettingsRateLimitType(GroupCollection groups, Dictionary<string, string> requestParameters)
@ -58,7 +57,7 @@ public partial class Server
if(groups.Count < 1 ||
!Enum.TryParse(groups[1].Value, out RequestType requestType))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"RequestType {groups[1].Value}");
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, settings.requestLimits[requestType]);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.requestLimits[requestType]);
}
private ValueTuple<HttpStatusCode, object?> PostV2SettingsRateLimitType(GroupCollection groups, Dictionary<string, string> requestParameters)
@ -69,13 +68,13 @@ public partial class Server
if (!requestParameters.TryGetValue("value", out string? requestsPerMinuteStr) ||
!int.TryParse(requestsPerMinuteStr, out int requestsPerMinute))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "Errors parsing requestsPerMinute");
settings.requestLimits[requestType] = requestsPerMinute;
TrangaSettings.UpdateRateLimit(requestType, requestsPerMinute);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
}
private ValueTuple<HttpStatusCode, object?> GetV2SettingsAprilFoolsMode(GroupCollection groups, Dictionary<string, string> requestParameters)
{
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, settings.aprilFoolsMode);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, TrangaSettings.aprilFoolsMode);
}
private ValueTuple<HttpStatusCode, object?> PostV2SettingsAprilFoolsMode(GroupCollection groups, Dictionary<string, string> requestParameters)
@ -83,7 +82,7 @@ public partial class Server
if (!requestParameters.TryGetValue("value", out string? trueFalseStr) ||
!bool.TryParse(trueFalseStr, out bool trueFalse))
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.InternalServerError, "Errors parsing 'value'");
settings.UpdateAprilFoolsMode(trueFalse);
TrangaSettings.UpdateAprilFoolsMode(trueFalse);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
}
@ -98,7 +97,7 @@ public partial class Server
false => true,
true => bool.Parse(moveFilesStr!)
};
settings.UpdateDownloadLocation(folderPath, moveFiles);
TrangaSettings.UpdateDownloadLocation(folderPath, moveFiles);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
}
catch (FormatException)

View File

@ -20,6 +20,7 @@ public static class TrangaSettings
[JsonIgnore] public static string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json");
[JsonIgnore] public static string jobsFolderPath => Path.Join(workingDirectory, "jobs");
[JsonIgnore] public static string coverImageCache => Path.Join(workingDirectory, "imageCache");
[JsonIgnore] public static string mangaCacheFolderPath => Path.Join(workingDirectory, "mangaCache");
public static ushort? version { get; } = 2;
public static bool aprilFoolsMode { get; private set; } = true;
[JsonIgnore]internal static readonly Dictionary<RequestType, int> DefaultRequestLimits = new ()