mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Handling type validation on config edits
This commit is contained in:
parent
f3e415a050
commit
fcd419993a
@ -41,14 +41,15 @@ namespace Kyoo.Controllers
|
||||
path = path.Replace("__", ":");
|
||||
if (!_references.TryGetValue(path, out Type type))
|
||||
throw new ItemNotFoundException($"No configuration exists for the name: {path}");
|
||||
value = JObject.FromObject(value).ToObject(type);
|
||||
if (value == null)
|
||||
throw new ArgumentException("Invalid value format.");
|
||||
|
||||
ExpandoObject config = ToObject(_configuration);
|
||||
IDictionary<string, object> configDic = config;
|
||||
// TODO validate the type
|
||||
configDic[path] = value;
|
||||
JObject obj = JObject.FromObject(config);
|
||||
// TODO allow path to change
|
||||
await using StreamWriter writer = new("settings.json");
|
||||
await using StreamWriter writer = new(Program.JsonConfigPath);
|
||||
await writer.WriteAsync(obj.ToString());
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,11 @@ namespace Kyoo
|
||||
/// </summary>
|
||||
public static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The path of the json configuration of the application.
|
||||
/// </summary>
|
||||
public const string JsonConfigPath = "./settings.json";
|
||||
|
||||
/// <summary>
|
||||
/// Main function of the program
|
||||
/// </summary>
|
||||
@ -66,7 +71,7 @@ namespace Kyoo
|
||||
/// <returns>The modified configuration builder</returns>
|
||||
private static IConfigurationBuilder SetupConfig(IConfigurationBuilder builder, string[] args)
|
||||
{
|
||||
return builder.AddJsonFile("./settings.json", false, true)
|
||||
return builder.AddJsonFile(JsonConfigPath, false, true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddCommandLine(args);
|
||||
}
|
||||
|
@ -87,6 +87,10 @@ namespace Kyoo.Api
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user