diff --git a/docs/technical/api/plugins/Api.Plugins.md b/docs/technical/api/plugins/Api.Plugins.md
index 22b30816..4f4b87ce 100644
--- a/docs/technical/api/plugins/Api.Plugins.md
+++ b/docs/technical/api/plugins/Api.Plugins.md
@@ -2,6 +2,9 @@
- [Lumina API](#lumina-api)
- [Plugins](#plugins)
+ - [Install Plugin](#install-plugin)
+ - [Install Plugin Request](#install-plugin-request)
+ - [Install Plugin Response](#install-plugin-response)
- [Get Plugins](#get-plugins)
- [Get Plugins Request](#get-plugins-request)
- [Get Plugins Response](#get-plugins-response)
@@ -23,6 +26,22 @@
## Plugins
+### Install Plugin
+
+#### Install Plugin Request
+
+```js
+POST api/v1/plugins
+```
+
+Uploads the plugin as a `multipart/form-data` request. The first file part of the form is used as the plugin archive, which can be either a single `.dll` assembly or a `.zip` archive containing the plugin assembly and its dependencies. The assemblies are placed into the plugin storage directory of the API and are loaded at the next API startup.
+
+#### Install Plugin Response
+
+```js
+200 Ok
+```
+
### Get Plugins
#### Get Plugins Request
diff --git a/docs/technical/requests/plugins/InstallPlugin.http b/docs/technical/requests/plugins/InstallPlugin.http
new file mode 100644
index 00000000..f7e7bb90
--- /dev/null
+++ b/docs/technical/requests/plugins/InstallPlugin.http
@@ -0,0 +1,10 @@
+POST {{host}}/api/v1/plugins
+Authorization: Bearer {{ACCESS_TOKEN}}
+Content-Type: multipart/form-data; boundary=----LuminaBoundary
+
+------LuminaBoundary
+Content-Disposition: form-data; name="archive"; filename="my-plugin.zip"
+Content-Type: application/octet-stream
+
+< ./my-plugin.zip
+------LuminaBoundary--
diff --git a/src/Lumina.Application/Common/Infrastructure/Plugins/IPluginInstaller.cs b/src/Lumina.Application/Common/Infrastructure/Plugins/IPluginInstaller.cs
new file mode 100644
index 00000000..77ddab1e
--- /dev/null
+++ b/src/Lumina.Application/Common/Infrastructure/Plugins/IPluginInstaller.cs
@@ -0,0 +1,24 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.Common.Primitives;
+using System.IO;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Application.Common.Infrastructure.Plugins;
+
+///
+/// Service for installing plugins from an uploaded archive into the plugin storage directory.
+///
+public interface IPluginInstaller
+{
+ ///
+ /// Installs the plugin from the provided archive, placing its assemblies into the plugin storage directory.
+ /// The installed plugin is loaded by the host application at the next startup.
+ ///
+ /// The archive stream of the uploaded plugin.
+ /// The file name of the uploaded plugin.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successful operation, or an error.
+ Task> InstallAsync(Stream archive, string fileName, CancellationToken cancellationToken);
+}
diff --git a/src/Lumina.Application/Core/Plugins/Commands/InstallPlugin/InstallPluginCommand.cs b/src/Lumina.Application/Core/Plugins/Commands/InstallPlugin/InstallPluginCommand.cs
new file mode 100644
index 00000000..365fc89d
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Commands/InstallPlugin/InstallPluginCommand.cs
@@ -0,0 +1,18 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System.Diagnostics;
+using System.IO;
+#endregion
+
+namespace Lumina.Application.Core.Plugins.Commands.InstallPlugin;
+
+///
+/// Command for installing a plugin from an uploaded archive, placing its assemblies into the plugin storage directory.
+///
+/// The archive stream of the uploaded plugin.
+/// The file name of the uploaded plugin.
+[DebuggerDisplay("FileName: {FileName}")]
+public record InstallPluginCommand(
+ Stream? Archive,
+ string? FileName
+) : ICommand;
diff --git a/src/Lumina.Application/Core/Plugins/Commands/InstallPlugin/InstallPluginCommandHandler.cs b/src/Lumina.Application/Core/Plugins/Commands/InstallPlugin/InstallPluginCommandHandler.cs
new file mode 100644
index 00000000..9cbf250f
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Commands/InstallPlugin/InstallPluginCommandHandler.cs
@@ -0,0 +1,75 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.Infrastructure.Authentication;
+using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Plugins;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Domain.Common.Primitives;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Plugins.Commands.InstallPlugin;
+
+///
+/// Handler for the command to install a plugin from an uploaded archive.
+///
+public class InstallPluginCommandHandler : ICommandHandler>
+{
+ private readonly IPluginInstaller _pluginInstaller;
+ private readonly ICurrentUserService _currentUserService;
+ private readonly IAuthorizationService _authorizationService;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected service for installing plugins into the plugin storage directory.
+ /// Injected service to retrieve the current user information.
+ /// Injected service for authorization related functionality.
+ /// Injected validator for application validation rules.
+ public InstallPluginCommandHandler(
+ IPluginInstaller pluginInstaller,
+ ICurrentUserService currentUserService,
+ IAuthorizationService authorizationService,
+ IValidator validator)
+ {
+ _pluginInstaller = pluginInstaller;
+ _currentUserService = currentUserService;
+ _authorizationService = authorizationService;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the command to install a plugin from an uploaded archive.
+ ///
+ /// The command to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An representing either a successful operation, or an error.
+ ///
+ public async Task> HandleAsync(InstallPluginCommand command, CancellationToken cancellationToken)
+ {
+ List validationResult = _validator.Validate(command);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ Guid? currentUserId = _currentUserService.UserId;
+ if (currentUserId is null)
+ return ApplicationErrors.Authorization.NotAuthorized;
+ Guid userId = currentUserId.Value;
+
+ // only admins can install plugins
+ if (!await _authorizationService.IsInRoleAsync(userId, "Admin", cancellationToken).ConfigureAwait(false))
+ return ApplicationErrors.Authorization.NotAuthorized;
+
+ Result installResult = await _pluginInstaller.InstallAsync(command.Archive!, command.FileName!, cancellationToken).ConfigureAwait(false);
+ if (installResult.IsFailure)
+ return installResult.Errors;
+
+ return Result.Success;
+ }
+}
diff --git a/src/Lumina.Application/Core/Plugins/Commands/InstallPlugin/InstallPluginCommandValidator.cs b/src/Lumina.Application/Core/Plugins/Commands/InstallPlugin/InstallPluginCommandValidator.cs
new file mode 100644
index 00000000..be4ad9e5
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Commands/InstallPlugin/InstallPluginCommandValidator.cs
@@ -0,0 +1,27 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
+using Lumina.Domain.Common.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Plugins.Commands.InstallPlugin;
+
+///
+/// Validates the needed validation rules for .
+///
+public class InstallPluginCommandValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public InstallPluginCommandValidator()
+ {
+ RuleFor(command => command.Archive)
+ .NotNull()
+ .WithError(Errors.Plugins.PluginArchiveCannotBeNull);
+
+ RuleFor(command => command.FileName)
+ .NotEmpty()
+ .WithError(Errors.Plugins.PluginFileNameCannotBeEmpty);
+ }
+}
diff --git a/src/Lumina.Domain/Common/Errors/Errors.Plugins.cs b/src/Lumina.Domain/Common/Errors/Errors.Plugins.cs
index c0ed3faf..f79e7cb1 100644
--- a/src/Lumina.Domain/Common/Errors/Errors.Plugins.cs
+++ b/src/Lumina.Domain/Common/Errors/Errors.Plugins.cs
@@ -18,5 +18,10 @@ public static partial class Errors
public static Error PluginIdsListCannotBeNull => Error.Validation(description: nameof(PluginIdsListCannotBeNull));
public static Error PluginIdsListCannotBeEmpty => Error.Validation(description: nameof(PluginIdsListCannotBeEmpty));
public static Error LibraryMetadataProviderConfigurationNotFound => Error.NotFound(description: nameof(LibraryMetadataProviderConfigurationNotFound));
+ public static Error PluginArchiveCannotBeNull => Error.Validation(description: nameof(PluginArchiveCannotBeNull));
+ public static Error PluginFileNameCannotBeEmpty => Error.Validation(description: nameof(PluginFileNameCannotBeEmpty));
+ public static Error UnsupportedPluginFileType => Error.Validation(description: nameof(UnsupportedPluginFileType));
+ public static Error PluginArchiveNotReadable => Error.Failure(description: nameof(PluginArchiveNotReadable));
+ public static Error PluginArchiveContainsNoAssemblies => Error.Failure(description: nameof(PluginArchiveContainsNoAssemblies));
}
}
diff --git a/src/Lumina.Infrastructure/Common/DependencyInjection/InfrastructureLayerServices.cs b/src/Lumina.Infrastructure/Common/DependencyInjection/InfrastructureLayerServices.cs
index 2f7ed608..16ca5a37 100644
--- a/src/Lumina.Infrastructure/Common/DependencyInjection/InfrastructureLayerServices.cs
+++ b/src/Lumina.Infrastructure/Common/DependencyInjection/InfrastructureLayerServices.cs
@@ -108,6 +108,7 @@ public static class InfrastructureLayerServices
PluginLoadResultDto pluginLoadResult = PluginLoader.LoadPlugins(pluginsDirectory, services);
services.AddSingleton(new PluginManager(pluginLoadResult.Plugins));
services.AddScoped();
+ services.AddScoped();
services.AddSingleton(serviceProvider => new PluginDetectionSyncJob(
serviceProvider.GetRequiredService(),
serviceProvider.GetRequiredService(),
diff --git a/src/Lumina.Infrastructure/Core/Plugins/PluginInstaller.cs b/src/Lumina.Infrastructure/Core/Plugins/PluginInstaller.cs
new file mode 100644
index 00000000..c9f7b37d
--- /dev/null
+++ b/src/Lumina.Infrastructure/Core/Plugins/PluginInstaller.cs
@@ -0,0 +1,125 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Models.DTO.Configuration;
+using Lumina.Application.Common.Infrastructure.Plugins;
+using Lumina.Domain.Common.Errors;
+using Lumina.Domain.Common.Primitives;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using System;
+using System.Collections.Concurrent;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Infrastructure.Core.Plugins;
+
+///
+/// Service for installing plugins from an uploaded archive into the plugin storage directory. The installed plugin assemblies are loaded by the host application at the next startup.
+///
+internal sealed class PluginInstaller : IPluginInstaller
+{
+ // the install mutates the shared plugins directory, so the operations are serialized per resolved directory.
+ // A per-instance gate is NOT enough: several hosts can run against the same plugins directory at once (for
+ // example the parallel in-memory hosts started by the test factories), so the gate is keyed on the directory.
+ private static readonly ConcurrentDictionary s_pluginDirectoryGates = new(StringComparer.Ordinal);
+ private readonly string _pluginsDirectory;
+ private readonly SemaphoreSlim _mutationGate;
+ private readonly ILogger _logger;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The injected plugins configuration options.
+ /// The logger for this service.
+ public PluginInstaller(IOptions pluginsSettings, ILogger logger)
+ {
+ _pluginsDirectory = Path.Combine(AppContext.BaseDirectory, pluginsSettings.Value.Directory);
+ _mutationGate = s_pluginDirectoryGates.GetOrAdd(_pluginsDirectory, static _ => new SemaphoreSlim(1, 1));
+ _logger = logger;
+ }
+
+ ///
+ /// Installs the plugin from the provided archive, placing its assemblies into the plugin storage directory.
+ ///
+ /// The archive stream of the uploaded plugin.
+ /// The file name of the uploaded plugin.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successful operation, or an error.
+ public async Task> InstallAsync(Stream archive, string fileName, CancellationToken cancellationToken)
+ {
+ await _mutationGate.WaitAsync(cancellationToken);
+ try
+ {
+ string extension = Path.GetExtension(fileName);
+ if (string.Equals(extension, ".dll", StringComparison.OrdinalIgnoreCase))
+ {
+ await CopySingleAssemblyAsync(archive, Path.GetFileName(fileName), cancellationToken).ConfigureAwait(false);
+ return Result.Success;
+ }
+
+ if (string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase))
+ {
+ try
+ {
+ return await ExtractZipArchiveAsync(archive, cancellationToken).ConfigureAwait(false);
+ }
+ catch (InvalidDataException exception)
+ {
+ _logger.LogWarning(exception, "An uploaded plugin archive could not be read.");
+ return Errors.Plugins.PluginArchiveNotReadable;
+ }
+ }
+
+ return Errors.Plugins.UnsupportedPluginFileType;
+ }
+ finally
+ {
+ _mutationGate.Release();
+ }
+ }
+
+ ///
+ /// Copies a single plugin assembly into the plugin storage directory.
+ ///
+ /// The stream of the plugin assembly.
+ /// The file name of the plugin assembly.
+ /// Cancellation token that can be used to stop the execution.
+ private async Task CopySingleAssemblyAsync(Stream assemblyStream, string assemblyFileName, CancellationToken cancellationToken)
+ {
+ Directory.CreateDirectory(_pluginsDirectory);
+ string destinationPath = Path.Combine(_pluginsDirectory, assemblyFileName);
+ await using FileStream outputStream = new(destinationPath, FileMode.Create, FileAccess.Write, FileShare.None);
+ await assemblyStream.CopyToAsync(outputStream, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Extracts the plugin assemblies from a ZIP archive into the plugin storage directory, flattening the archive
+ /// structure, since the plugin loader scans the storage directory root for assemblies.
+ ///
+ /// The stream of the uploaded ZIP archive.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successful operation, or an error.
+ private async Task> ExtractZipArchiveAsync(Stream archive, CancellationToken cancellationToken)
+ {
+ using ZipArchive zipArchive = new(archive);
+ ZipArchiveEntry[] assemblyEntries = [.. zipArchive.Entries.Where(entry => string.Equals(Path.GetExtension(entry.FullName), ".dll", StringComparison.OrdinalIgnoreCase))];
+ if (assemblyEntries.Length == 0)
+ return Errors.Plugins.PluginArchiveContainsNoAssemblies;
+
+ Directory.CreateDirectory(_pluginsDirectory);
+ foreach (ZipArchiveEntry entry in assemblyEntries)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+ // flatten the archive structure and use only the file name, so no entry can escape the plugin storage directory
+ string destinationPath = Path.Combine(_pluginsDirectory, Path.GetFileName(entry.FullName));
+ await using Stream entryStream = entry.Open();
+ await using FileStream outputStream = new(destinationPath, FileMode.Create, FileAccess.Write, FileShare.None);
+ await entryStream.CopyToAsync(outputStream, cancellationToken).ConfigureAwait(false);
+ }
+
+ return Result.Success;
+ }
+}
diff --git a/src/Lumina.Presentation.Api/Common/Routes/Plugins/ApiRoutes.Plugins.cs b/src/Lumina.Presentation.Api/Common/Routes/Plugins/ApiRoutes.Plugins.cs
index 4081864a..721e8557 100644
--- a/src/Lumina.Presentation.Api/Common/Routes/Plugins/ApiRoutes.Plugins.cs
+++ b/src/Lumina.Presentation.Api/Common/Routes/Plugins/ApiRoutes.Plugins.cs
@@ -13,5 +13,6 @@ public static partial class ApiRoutes
public const string GET_PLUGINS = "/plugins";
public const string GET_PLUGIN_SETTINGS = "/plugins/{pluginId}/settings";
public const string UPDATE_PLUGIN_SETTINGS = "/plugins/{pluginId}/settings";
+ public const string INSTALL_PLUGIN = "/plugins";
}
}
diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Plugins/InstallPlugin/InstallPluginEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Plugins/InstallPlugin/InstallPluginEndpoint.cs
new file mode 100644
index 00000000..d013a9dd
--- /dev/null
+++ b/src/Lumina.Presentation.Api/Core/Endpoints/Plugins/InstallPlugin/InstallPluginEndpoint.cs
@@ -0,0 +1,68 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Core.Plugins.Commands.InstallPlugin;
+using Lumina.Domain.Common.Primitives;
+using Lumina.Presentation.Api.Common.Routes.Plugins;
+using Lumina.Presentation.Api.Core.Endpoints.Common;
+using Microsoft.AspNetCore.Http;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.InstallPlugin;
+
+///
+/// API endpoint for the /plugins route.
+///
+public class InstallPluginEndpoint : BaseEndpoint
+{
+ private readonly ICommandHandler> _installPluginCommandHandler;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected service for handling install plugin commands.
+ public InstallPluginEndpoint(ICommandHandler> installPluginCommandHandler)
+ {
+ _installPluginCommandHandler = installPluginCommandHandler;
+ }
+
+ ///
+ /// Configures the API endpoint.
+ ///
+ public override void Configure()
+ {
+ Verbs(FastEndpoints.Http.POST);
+ Routes(ApiRoutes.Plugins.INSTALL_PLUGIN);
+ Version(1);
+ DontCatchExceptions();
+ }
+
+ ///
+ /// Installs the plugin uploaded in the multipart form of the request, placing its assemblies into the plugin storage directory.
+ ///
+ /// The request object.
+ /// Cancellation token that can be used to stop the execution.
+ public override async Task ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
+ {
+ // a multipart body without any part cannot be parsed as a form, so a malformed upload is treated as a missing archive
+ IFormFile? archive = null;
+ if (HttpContext.Request.HasFormContentType)
+ {
+ try
+ {
+ archive = HttpContext.Request.Form.Files.FirstOrDefault();
+ }
+ catch (InvalidDataException)
+ {
+ archive = null;
+ }
+ }
+
+ InstallPluginCommand command = new(archive?.OpenReadStream(), archive?.FileName);
+ Result result = await _installPluginCommandHandler.HandleAsync(command, cancellationToken).ConfigureAwait(false);
+ return result.Match(success => TypedResults.Ok(), Problem);
+ }
+}
diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Plugins/InstallPlugin/InstallPluginEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Plugins/InstallPlugin/InstallPluginEndpointSummary.cs
new file mode 100644
index 00000000..f7bfe65d
--- /dev/null
+++ b/src/Lumina.Presentation.Api/Core/Endpoints/Plugins/InstallPlugin/InstallPluginEndpointSummary.cs
@@ -0,0 +1,110 @@
+#region ========================================================================= USING =====================================================================================
+using FastEndpoints;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+#endregion
+
+namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.InstallPlugin;
+
+///
+/// Class used for providing a textual description for the API endpoint, for OpenAPI.
+///
+[ExcludeFromCodeCoverage]
+public class InstallPluginEndpointSummary : Summary
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public InstallPluginEndpointSummary()
+ {
+ Summary = "Installs a plugin.";
+ Description = "Installs the plugin uploaded in the multipart form of the request, placing its assemblies into the plugin storage directory. The plugin is loaded by the host application at the next startup.";
+
+ Response(200, "The plugin was successfully installed.");
+
+ Response(401, "Authentication required.", "application/problem+json",
+ example: new[]
+ {
+ new
+ {
+ type = "https://tools.ietf.org/html/rfc7235#section-3.1",
+ status = 401,
+ title = "Unauthorized",
+ detail = "You are not authorized",
+ instance = "/api/v1/plugins"
+ },
+ new
+ {
+ type = "https://tools.ietf.org/html/rfc7235#section-3.1",
+ status = 401,
+ title = "Unauthorized",
+ detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
+ instance = "/api/v1/plugins"
+ },
+ new
+ {
+ type = "https://tools.ietf.org/html/rfc7235#section-3.1",
+ status = 401,
+ title = "Unauthorized",
+ detail = "The token is invalid",
+ instance = "/api/v1/plugins"
+ }
+ }
+ );
+
+ Response(403, "The request failed because the user is not an Admin, or the uploaded plugin archive is not readable.", "application/problem+json",
+ example: new[]
+ {
+ new
+ {
+ type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
+ title = "General.Failure",
+ status = 403,
+ detail = "NotAuthorized",
+ instance = "/api/v1/plugins",
+ traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
+ },
+ new
+ {
+ type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
+ title = "General.Failure",
+ status = 403,
+ detail = "PluginArchiveNotReadable",
+ instance = "/api/v1/plugins",
+ traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
+ },
+ new
+ {
+ type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
+ title = "General.Failure",
+ status = 403,
+ detail = "PluginArchiveContainsNoAssemblies",
+ instance = "/api/v1/plugins",
+ traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
+ }
+ }
+ );
+
+ Response(422, "The request did not pass validation checks.", "application/problem+json",
+ example: new
+ {
+ type = "https://tools.ietf.org/html/rfc4918#section-11.2",
+ title = "General.Validation",
+ status = 422,
+ detail = "OneOrMoreValidationErrorsOccurred",
+ instance = "/api/v1/plugins",
+ errors = new Dictionary
+ {
+ {
+ "General.Validation", new[]
+ {
+ "PluginArchiveCannotBeNull"
+ }
+ }
+ },
+ traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
+ }
+ );
+ }
+}
diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Plugins.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Plugins.cs
index 1371d505..17d5074b 100644
--- a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Plugins.cs
+++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Plugins.cs
@@ -13,5 +13,6 @@ public static partial class ApiRoutes
public const string GET_PLUGINS = "plugins";
public const string GET_PLUGIN_SETTINGS = "plugins/{pluginId}/settings";
public const string UPDATE_PLUGIN_SETTINGS = "plugins/{pluginId}/settings";
+ public const string INSTALL_PLUGIN = "plugins";
}
}
diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Plugins.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Plugins.cs
index 7d054eaa..e9f8d817 100644
--- a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Plugins.cs
+++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.Plugins.cs
@@ -14,5 +14,6 @@ public static partial class WebRoutes
public const string GET_PLUGINS = "{culture}/admin/manage-plugins/api-get-plugins";
public const string GET_PLUGIN_SETTINGS = "{culture}/admin/manage-plugins/api-get-plugin-settings/{pluginId}";
public const string UPDATE_PLUGIN_SETTINGS = "{culture}/admin/manage-plugins/api-update-plugin-settings";
+ public const string INSTALL_PLUGIN = "{culture}/admin/manage-plugins/api-install-plugin";
}
}
diff --git a/src/Lumina.Presentation.Web/Core/Endpoints/Plugins/InstallPlugin/InstallPluginEndpoint.cs b/src/Lumina.Presentation.Web/Core/Endpoints/Plugins/InstallPlugin/InstallPluginEndpoint.cs
new file mode 100644
index 00000000..b30e9eb0
--- /dev/null
+++ b/src/Lumina.Presentation.Web/Core/Endpoints/Plugins/InstallPlugin/InstallPluginEndpoint.cs
@@ -0,0 +1,63 @@
+#region ========================================================================= USING =====================================================================================
+using FastEndpoints;
+using Lumina.Presentation.Web.Common.Api;
+using Lumina.Presentation.Web.Common.Authorization;
+using Lumina.Presentation.Web.Common.DTO.Plugins;
+using Lumina.Presentation.Web.Common.Routes;
+using Lumina.Presentation.Web.Core.Endpoints.Common;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Http;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Presentation.Web.Core.Endpoints.Plugins.InstallPlugin;
+
+///
+/// API endpoint for the /{culture}/admin/manage-plugins/api-install-plugin route.
+///
+public class InstallPluginEndpoint : BaseEndpoint
+{
+ private readonly IApiHttpClient _apiHttpClient;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected service for interactions with the API.
+ public InstallPluginEndpoint(IApiHttpClient apiHttpClient)
+ {
+ _apiHttpClient = apiHttpClient;
+ }
+
+ ///
+ /// Configures the endpoint.
+ ///
+ public override void Configure()
+ {
+ base.Configure();
+ Verbs(Http.POST);
+ Routes(WebRoutes.Plugins.INSTALL_PLUGIN);
+ DontAutoTag();
+ Options(options => options.WithTags("Plugins"));
+ Policies(AuthorizationPolicies.REQUIRE_ADMIN_ROLE);
+ EnableAntiforgery();
+ }
+
+ ///
+ /// Installs the plugin uploaded in the multipart form of the request.
+ ///
+ /// The request object.
+ /// Cancellation token that can be used to stop the execution.
+ public override async Task ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
+ {
+ IFormFile? archive = HttpContext.Request.Form.Files.FirstOrDefault();
+ if (archive is null)
+ return Results.Problem(statusCode: StatusCodes.Status400BadRequest, detail: "The uploaded plugin archive is missing.");
+
+ await using Stream archiveStream = archive.OpenReadStream();
+ await _apiHttpClient.PostMultipartAsync(ApiRoutes.Plugins.INSTALL_PLUGIN, archiveStream, archive.FileName, "archive", cancellationToken).ConfigureAwait(false);
+ return JsonSuccess();
+ }
+}
diff --git a/src/Lumina.Presentation.Web/Core/Endpoints/Plugins/InstallPlugin/InstallPluginEndpointSummary.cs b/src/Lumina.Presentation.Web/Core/Endpoints/Plugins/InstallPlugin/InstallPluginEndpointSummary.cs
new file mode 100644
index 00000000..9f8e258a
--- /dev/null
+++ b/src/Lumina.Presentation.Web/Core/Endpoints/Plugins/InstallPlugin/InstallPluginEndpointSummary.cs
@@ -0,0 +1,25 @@
+#region ========================================================================= USING =====================================================================================
+using FastEndpoints;
+using Lumina.Presentation.Web.Common.DTO.Common;
+using System.Diagnostics.CodeAnalysis;
+#endregion
+
+namespace Lumina.Presentation.Web.Core.Endpoints.Plugins.InstallPlugin;
+
+///
+/// Class used for providing a textual description for the endpoint, for OpenAPI.
+///
+[ExcludeFromCodeCoverage]
+public class InstallPluginEndpointSummary : Summary
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public InstallPluginEndpointSummary()
+ {
+ Summary = "Installs a plugin.";
+ Description = "Installs the plugin uploaded in the multipart form of the request, placing its assemblies into the plugin storage directory of the API. The plugin is loaded by the API at its next startup.";
+
+ Response(200, "The plugin was successfully installed.", example: new SuccessResponse(true));
+ }
+}
diff --git a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ar-SA.resx b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ar-SA.resx
index d4cd5950..df7a2beb 100644
--- a/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ar-SA.resx
+++ b/src/Lumina.Presentation.Web/Core/Resources/Common/Middlewares/ExceptionHandlingMiddleware.ar-SA.resx
@@ -1,4 +1,4 @@
-
+