Updated the web UI to use the API. Reworked the looks of web UI

This commit is contained in:
2024-12-14 17:31:36 +02:00
parent 9102cfaa47
commit 54be74b1cb
27 changed files with 227 additions and 738 deletions

View File

@@ -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();
}
}

View File

@@ -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);
}
}