glax 2023-10-28 12:47:13 +02:00
parent d78897eb74
commit 7c7f711bb4
2 changed files with 27 additions and 0 deletions

View File

@ -335,6 +335,18 @@ public class Server : GlobalBase
settings.UpdateDownloadLocation(downloadLocation, moveFiles);
SendResponse(HttpStatusCode.Accepted, response);
break;
case "Settings/ChangeStyleSheet":
if (!requestVariables.TryGetValue("styleSheet", out string? styleSheet))
{
SendResponse(HttpStatusCode.BadRequest, response);
break;
}
if (settings.UpdateStyleSheet(styleSheet))
SendResponse(HttpStatusCode.Accepted, response);
else
SendResponse(HttpStatusCode.BadRequest, response, "Invalid parameter for styleSheet");
break;
/*case "Settings/UpdateWorkingDirectory":
if (!requestVariables.TryGetValue("workingDirectory", out string? workingDirectory))
{

View File

@ -11,6 +11,7 @@ public class TrangaSettings
public string downloadLocation { get; private set; }
public string workingDirectory { get; private set; }
public int apiPortNumber { get; init; }
public string styleSheet { get; private set; }
[JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
[JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
[JsonIgnore] public string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json");
@ -29,6 +30,7 @@ public class TrangaSettings
this.downloadLocation = downloadLocation ?? settings.downloadLocation;
this.workingDirectory = workingDirectory ?? settings.workingDirectory;
this.apiPortNumber = apiPortNumber ?? settings.apiPortNumber;
this.styleSheet = "default" ?? settings.styleSheet;
lockFile.Close(); //unlock settingsfile
}
else if(!File.Exists(settingsFilePath))
@ -38,6 +40,7 @@ public class TrangaSettings
this.apiPortNumber = apiPortNumber ?? 6531;
this.downloadLocation = downloadLocation ?? (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(Directory.GetCurrentDirectory(), "Downloads"));
this.workingDirectory = workingDirectory ?? Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/usr/share" : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tranga-api");
this.styleSheet = "default";
ExportSettings();
}
else
@ -45,6 +48,7 @@ public class TrangaSettings
this.apiPortNumber = apiPortNumber!.Value;
this.downloadLocation = downloadLocation!;
this.workingDirectory = workingDirectory!;
this.styleSheet = "default";
}
UpdateDownloadLocation(this.downloadLocation, false);
}
@ -77,6 +81,17 @@ public class TrangaSettings
})!;
}
public bool UpdateStyleSheet(string newStyleSheet)
{
string[] validStyleSheets = { "default", "hover" };
if (validStyleSheets.Contains(newStyleSheet))
{
this.styleSheet = newStyleSheet;
return true;
}
return false;
}
public void UpdateDownloadLocation(string newPath, bool moveFiles = true)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))