Updated the web UI to use the API. Reworked the looks of web UI
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBotCore.Interfaces.API;
|
||||
using DiscordBotCore.Others;
|
||||
|
||||
namespace DiscordBotCore.API.Endpoints.SettingsManagement;
|
||||
|
||||
public class SettingsChangeEndpoint : IEndpoint
|
||||
{
|
||||
public string Path => "/api/settings/update";
|
||||
public EndpointType HttpMethod => EndpointType.Post;
|
||||
public async Task<ApiResponse> HandleRequest(string? jsonRequest)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonRequest))
|
||||
{
|
||||
return ApiResponse.Fail("Invalid json string");
|
||||
}
|
||||
|
||||
Dictionary<string, string> jsonDictionary = await JsonManager.ConvertFromJson<Dictionary<string, string>>(jsonRequest);
|
||||
foreach (var (key, value) in jsonDictionary)
|
||||
{
|
||||
Application.CurrentApplication.ApplicationEnvironmentVariables.Set(key, value);
|
||||
}
|
||||
|
||||
return ApiResponse.Ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBotCore.Interfaces.API;
|
||||
using DiscordBotCore.Others;
|
||||
|
||||
namespace DiscordBotCore.API.Endpoints.SettingsManagement;
|
||||
|
||||
public class SettingsGetEndpoint : IEndpoint
|
||||
{
|
||||
public string Path => "/api/settings/get";
|
||||
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>())}
|
||||
};
|
||||
|
||||
string jsonResponse = await JsonManager.ConvertToJsonString(jsonSettingsDictionary);
|
||||
return ApiResponse.From(jsonResponse, true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user