Updated settings change route
This commit is contained in:
@@ -8,10 +8,10 @@ namespace DiscordBotCore.API.Endpoints;
|
||||
|
||||
internal sealed class EndpointManager
|
||||
{
|
||||
private WebApplication _appBuilder;
|
||||
private readonly WebApplication _AppBuilder;
|
||||
internal EndpointManager(WebApplication appBuilder)
|
||||
{
|
||||
_appBuilder = appBuilder;
|
||||
_AppBuilder = appBuilder;
|
||||
}
|
||||
|
||||
internal void MapEndpoint(IEndpoint endpoint)
|
||||
@@ -19,7 +19,7 @@ internal sealed class EndpointManager
|
||||
switch (endpoint.HttpMethod)
|
||||
{
|
||||
case EndpointType.Get:
|
||||
_appBuilder.MapGet(endpoint.Path, async context =>
|
||||
_AppBuilder.MapGet(endpoint.Path, async context =>
|
||||
{
|
||||
//convert the context to a string
|
||||
string jsonRequest = string.Empty;
|
||||
@@ -34,7 +34,7 @@ internal sealed class EndpointManager
|
||||
});
|
||||
break;
|
||||
case EndpointType.Put:
|
||||
_appBuilder.MapPut(endpoint.Path, async context =>
|
||||
_AppBuilder.MapPut(endpoint.Path, async context =>
|
||||
{
|
||||
string jsonRequest = string.Empty;
|
||||
if (context.Request.Body.CanRead)
|
||||
@@ -48,7 +48,7 @@ internal sealed class EndpointManager
|
||||
});
|
||||
break;
|
||||
case EndpointType.Post:
|
||||
_appBuilder.MapPost(endpoint.Path, async context =>
|
||||
_AppBuilder.MapPost(endpoint.Path, async context =>
|
||||
{
|
||||
string jsonRequest = string.Empty;
|
||||
if (context.Request.Body.CanRead)
|
||||
@@ -62,7 +62,7 @@ internal sealed class EndpointManager
|
||||
});
|
||||
break;
|
||||
case EndpointType.Delete:
|
||||
_appBuilder.MapDelete(endpoint.Path, async context =>
|
||||
_AppBuilder.MapDelete(endpoint.Path, async context =>
|
||||
{
|
||||
string jsonRequest = string.Empty;
|
||||
if (context.Request.Body.CanRead)
|
||||
|
||||
@@ -16,7 +16,7 @@ public class SettingsChangeEndpoint : IEndpoint
|
||||
return ApiResponse.Fail("Invalid json string");
|
||||
}
|
||||
|
||||
Dictionary<string, string> jsonDictionary = await JsonManager.ConvertFromJson<Dictionary<string, string>>(jsonRequest);
|
||||
Dictionary<string, object> jsonDictionary = await JsonManager.ConvertFromJson<Dictionary<string, object>>(jsonRequest);
|
||||
foreach (var (key, value) in jsonDictionary)
|
||||
{
|
||||
Application.CurrentApplication.ApplicationEnvironmentVariables.Set(key, value);
|
||||
|
||||
@@ -11,16 +11,11 @@ public class SettingsGetEndpoint : IEndpoint
|
||||
public EndpointType HttpMethod => EndpointType.Get;
|
||||
public async Task<ApiResponse> HandleRequest(string? jsonRequest)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonRequest))
|
||||
{
|
||||
return ApiResponse.Fail("The json from the request was empty");
|
||||
}
|
||||
|
||||
Dictionary<string, object> jsonSettingsDictionary = new Dictionary<string, object>()
|
||||
{
|
||||
{"token", Application.CurrentApplication.ApplicationEnvironmentVariables.Get("token", string.Empty)},
|
||||
{"prefix", Application.CurrentApplication.ApplicationEnvironmentVariables.Get("prefix", string.Empty)},
|
||||
{"ServerIDs", Application.CurrentApplication.ApplicationEnvironmentVariables.GetList("ServerIDs", new List<ulong>())}
|
||||
{"serverIds", Application.CurrentApplication.ApplicationEnvironmentVariables.GetList("ServerID", new List<ulong>())}
|
||||
};
|
||||
|
||||
string jsonResponse = await JsonManager.ConvertToJsonString(jsonSettingsDictionary);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBotCore.API;
|
||||
using DiscordBotCore.API.Endpoints;
|
||||
@@ -82,7 +81,7 @@ namespace DiscordBotCore
|
||||
|
||||
CurrentApplication.Logger = new Logger(_LogsFolder, _LogFormat);
|
||||
|
||||
if (!File.Exists(_PluginsDatabaseFile))
|
||||
if (!File.Exists(_PluginsDatabaseFile))
|
||||
{
|
||||
List<PluginInfo> plugins = new();
|
||||
await JsonManager.SaveToJsonFile(_PluginsDatabaseFile, plugins);
|
||||
|
||||
@@ -96,6 +96,8 @@ public abstract class CustomSettingsDictionaryBase<TKey,TValue> : ICustomSetting
|
||||
return list;
|
||||
}
|
||||
|
||||
Application.CurrentApplication.Logger.Log($"Key '{key}' not found in settings dictionary. Adding default value.", LogType.Warning);
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ public sealed class PluginRepository : RepositoryBase
|
||||
return Default;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var pluginRepoDict = Application.CurrentApplication.ApplicationEnvironmentVariables.GetDictionary<string, string>("PluginRepository");
|
||||
|
||||
Reference in New Issue
Block a user