diff --git a/DiscordBotCore.PluginManagement/Helpers/PluginRepository.cs b/DiscordBotCore.PluginManagement/Helpers/PluginRepository.cs index b78da57..63c97fe 100644 --- a/DiscordBotCore.PluginManagement/Helpers/PluginRepository.cs +++ b/DiscordBotCore.PluginManagement/Helpers/PluginRepository.cs @@ -28,18 +28,27 @@ public class PluginRepository : IPluginRepository { "operatingSystem", operatingSystem.ToString() }, { "includeNotApproved", includeNotApproved.ToString() } }); - - HttpResponseMessage response = await _httpClient.GetAsync(url); - if (!response.IsSuccessStatusCode) + try { + HttpResponseMessage response = await _httpClient.GetAsync(url); + + if (!response.IsSuccessStatusCode) + { + return []; + } + + string content = await response.Content.ReadAsStringAsync(); + List plugins = await JsonManager.ConvertFromJson>(content); + + return plugins; + } + catch (HttpRequestException exception) + { + _logger.LogException(exception,this); return []; } - - string content = await response.Content.ReadAsStringAsync(); - List plugins = await JsonManager.ConvertFromJson>(content); - - return plugins; + } public async Task GetPluginById(int pluginId) @@ -50,17 +59,27 @@ public class PluginRepository : IPluginRepository { "pluginId", pluginId.ToString() }, { "includeNotApproved", "false" } }); - HttpResponseMessage response = await _httpClient.GetAsync(url); - if (!response.IsSuccessStatusCode) + try { + HttpResponseMessage response = await _httpClient.GetAsync(url); + + if (!response.IsSuccessStatusCode) + { + return null; + } + + string content = await response.Content.ReadAsStringAsync(); + OnlinePlugin plugin = await JsonManager.ConvertFromJson(content); + + return plugin; + } + catch (HttpRequestException exception) + { + _logger.LogException(exception, this); return null; } - - string content = await response.Content.ReadAsStringAsync(); - OnlinePlugin plugin = await JsonManager.ConvertFromJson(content); - - return plugin; + } public async Task GetPluginByName(string pluginName, int operatingSystem, bool includeNotApproved) @@ -72,18 +91,28 @@ public class PluginRepository : IPluginRepository { "operatingSystem", operatingSystem.ToString() }, { "includeNotApproved", includeNotApproved.ToString() } }); - HttpResponseMessage response = await _httpClient.GetAsync(url); - if (!response.IsSuccessStatusCode) + try { - _logger.Log($"Plugin {pluginName} not found"); + HttpResponseMessage response = await _httpClient.GetAsync(url); + + if (!response.IsSuccessStatusCode) + { + _logger.Log($"Plugin {pluginName} not found"); + return null; + } + + string content = await response.Content.ReadAsStringAsync(); + OnlinePlugin plugin = await JsonManager.ConvertFromJson(content); + + return plugin; + } + catch (HttpRequestException exception) + { + _logger.LogException(exception, this); return null; } - - string content = await response.Content.ReadAsStringAsync(); - OnlinePlugin plugin = await JsonManager.ConvertFromJson(content); - - return plugin; + } public async Task> GetDependenciesForPlugin(int pluginId) @@ -93,18 +122,26 @@ public class PluginRepository : IPluginRepository { { "pluginId", pluginId.ToString() } }); - - HttpResponseMessage response = await _httpClient.GetAsync(url); - if(!response.IsSuccessStatusCode) + + try { - _logger.Log($"Failed to get dependencies for plugin with ID {pluginId}"); + HttpResponseMessage response = await _httpClient.GetAsync(url); + if(!response.IsSuccessStatusCode) + { + _logger.Log($"Failed to get dependencies for plugin with ID {pluginId}"); + return []; + } + + string content = await response.Content.ReadAsStringAsync(); + List dependencies = await JsonManager.ConvertFromJson>(content); + + return dependencies; + }catch(HttpRequestException exception) + { + _logger.LogException(exception, this); return []; } - - string content = await response.Content.ReadAsStringAsync(); - List dependencies = await JsonManager.ConvertFromJson>(content); - - return dependencies; + } private string CreateUrlWithQueryParams(string baseUrl, string endpoint, Dictionary queryParams) diff --git a/DiscordBotCore.WebApplication/DiscordBotCore.WebApplication.csproj b/DiscordBotCore.WebApplication/DiscordBotCore.WebApplication.csproj index 9162818..811d440 100644 --- a/DiscordBotCore.WebApplication/DiscordBotCore.WebApplication.csproj +++ b/DiscordBotCore.WebApplication/DiscordBotCore.WebApplication.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/DiscordBotCore/DiscordBotCore.csproj b/DiscordBotCore/DiscordBotCore.csproj index 08e3340..e5dad5f 100644 --- a/DiscordBotCore/DiscordBotCore.csproj +++ b/DiscordBotCore/DiscordBotCore.csproj @@ -1,19 +1,13 @@ - + net8.0 enable Library - - AnyCPU - - - - diff --git a/WebUI/Components/Pages/Home.razor b/WebUI/Components/Pages/Home.razor index dfcdf75..b46f758 100644 --- a/WebUI/Components/Pages/Home.razor +++ b/WebUI/Components/Pages/Home.razor @@ -4,4 +4,16 @@

Hello, world!

-Welcome to your new app. \ No newline at end of file + + +Welcome to your new app. + + +@code { + + private void ClickTest(int i) + { + Console.WriteLine($"Clicked {i}"); + } + +} \ No newline at end of file diff --git a/WebUI/Components/Pages/Plugins/Local.razor b/WebUI/Components/Pages/Plugins/Local.razor index f697c9e..7ec63e7 100644 --- a/WebUI/Components/Pages/Plugins/Local.razor +++ b/WebUI/Components/Pages/Plugins/Local.razor @@ -1,4 +1,6 @@ @page "/plugins/local" +@rendermode InteractiveServer + @using DiscordBotCore.Logging @using DiscordBotCore.PluginManagement @using DiscordBotCore.PluginManagement.Models diff --git a/WebUI/Components/Pages/Plugins/Online.razor b/WebUI/Components/Pages/Plugins/Online.razor index a4a285c..f5190be 100644 --- a/WebUI/Components/Pages/Plugins/Online.razor +++ b/WebUI/Components/Pages/Plugins/Online.razor @@ -1,9 +1,11 @@ @page "/plugins/online" +@rendermode InteractiveServer + @using DiscordBotCore.Logging @using DiscordBotCore.PluginManagement -

Available Plugins

+

Available Plugins

@if (_onlinePlugins.Any()) { @@ -25,7 +27,7 @@ } @@ -104,6 +106,9 @@ else }; _onlinePlugins.Add(onlinePlugin); } + + Logger.Log($"Found {_onlinePlugins.Count} online plugins.", this); + StateHasChanged(); } private async Task InstallPlugin(int pluginId) @@ -128,6 +133,7 @@ else Logger.Log($"Plugin {pluginData.Name} installed successfully.", this); CloseInstallPercentageModal(); + StateHasChanged(); } private void CloseInstallPercentageModal() @@ -145,4 +151,4 @@ else public string Author { get; set; } public string Version { get; set; } } -} +} \ No newline at end of file diff --git a/WebUI/Program.cs b/WebUI/Program.cs index 8fe10b4..2c6f1f8 100644 --- a/WebUI/Program.cs +++ b/WebUI/Program.cs @@ -7,6 +7,7 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); builder.AddDiscordBotComponents(); + var app = builder.Build(); // Configure the HTTP request pipeline.
@plugin.Author @plugin.Version - +