Added download and progress endpoints
This commit is contained in:
@@ -12,12 +12,21 @@ public class ApiManager
|
||||
{
|
||||
private bool IsRunning { get; set; }
|
||||
private List<IEndpoint> ApiEndpoints { get; }
|
||||
|
||||
|
||||
public ApiManager()
|
||||
{
|
||||
ApiEndpoints = new List<IEndpoint>();
|
||||
}
|
||||
|
||||
internal void AddBaseEndpoints()
|
||||
{
|
||||
AddEndpoint(new HomeEndpoint());
|
||||
AddEndpoint(new PluginListEndpoint());
|
||||
AddEndpoint(new PluginListInstalledEndpoint());
|
||||
AddEndpoint(new PluginInstallEndpoint());
|
||||
AddEndpoint(new PluginInstallGetProgressEndpoint());
|
||||
}
|
||||
|
||||
public Result AddEndpoint(IEndpoint endpoint)
|
||||
{
|
||||
if (ApiEndpoints.Contains(endpoint) || ApiEndpoints.Exists(x => x.Path == endpoint.Path))
|
||||
@@ -38,12 +47,6 @@ public class ApiManager
|
||||
{
|
||||
return this.ApiEndpoints.Exists(endpoint => endpoint.Path == endpointPath);
|
||||
}
|
||||
|
||||
internal void AddBaseEndpoints()
|
||||
{
|
||||
AddEndpoint(new HomeEndpoint());
|
||||
AddEndpoint(new PluginListEndpoint());
|
||||
}
|
||||
|
||||
public async Task InitializeApi()
|
||||
{
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBotCore.Interfaces.API;
|
||||
using DiscordBotCore.Others;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace DiscordBotCore.API.Endpoints;
|
||||
|
||||
|
||||
@@ -4,12 +4,10 @@ using System.Threading.Tasks;
|
||||
using DiscordBotCore.Interfaces.API;
|
||||
using DiscordBotCore.Others;
|
||||
using DiscordBotCore.Plugin;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
|
||||
namespace DiscordBotCore.API.Endpoints.PluginManagement;
|
||||
|
||||
public class InstallPluginEndpoint : IEndpoint
|
||||
public class PluginInstallEndpoint : IEndpoint
|
||||
{
|
||||
public string Path => "/api/plugin/install";
|
||||
public EndpointType HttpMethod => EndpointType.Put;
|
||||
@@ -25,7 +23,7 @@ public class InstallPluginEndpoint : IEndpoint
|
||||
return ApiResponse.Fail("Plugin not found.");
|
||||
}
|
||||
|
||||
await Application.CurrentApplication.PluginManager.InstallPlugin(pluginInfo, null);
|
||||
await Application.CurrentApplication.PluginManager.InstallPluginWithNoProgress(pluginInfo);
|
||||
return ApiResponse.Ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBotCore.Interfaces.API;
|
||||
using DiscordBotCore.Others;
|
||||
|
||||
namespace DiscordBotCore.API.Endpoints.PluginManagement;
|
||||
|
||||
public class PluginInstallGetProgressEndpoint : IEndpoint
|
||||
{
|
||||
public string Path => "/api/plugin/install/progress";
|
||||
public EndpointType HttpMethod => EndpointType.Get;
|
||||
public async Task<ApiResponse> HandleRequest(string? jsonRequest)
|
||||
{
|
||||
if (!Application.CurrentApplication.PluginManager.InstallingPluginInformation.IsInstalling)
|
||||
{
|
||||
return ApiResponse.Fail("No plugin is currently being installed.");
|
||||
}
|
||||
|
||||
var progress = Application.CurrentApplication.PluginManager.InstallingPluginInformation.InstallationProgress;
|
||||
string stringProgress = progress.ToString(CultureInfo.InvariantCulture);
|
||||
var response = new Dictionary<string, string>
|
||||
{
|
||||
{"progress", stringProgress},
|
||||
{"pluginName", Application.CurrentApplication.PluginManager.InstallingPluginInformation.PluginName}
|
||||
};
|
||||
return ApiResponse.From(await JsonManager.ConvertToJsonString(response), true);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBotCore.Interfaces.API;
|
||||
using DiscordBotCore.Others;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace DiscordBotCore.API.Endpoints.PluginManagement;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user