mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 13:01:10 +00:00
Adds plugin upload from the web client
This commit is contained in:
1 parent
d84823f6d2
commit
b3ffb5dfab
57 files changed
+2774
-16
No files matched your search
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Service for installing plugins from an uploaded archive into the plugin storage directory.
|
||||
/// </summary>
|
||||
public interface IPluginInstaller
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="archive">The archive stream of the uploaded plugin.</param>
|
||||
/// <param name="fileName">The file name of the uploaded plugin.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Success>> InstallAsync(Stream archive, string fileName, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Command for installing a plugin from an uploaded archive, placing its assemblies into the plugin storage directory.
|
||||
/// </summary>
|
||||
/// <param name="Archive">The archive stream of the uploaded plugin.</param>
|
||||
/// <param name="FileName">The file name of the uploaded plugin.</param>
|
||||
[DebuggerDisplay("FileName: {FileName}")]
|
||||
public record InstallPluginCommand(
|
||||
Stream? Archive,
|
||||
string? FileName
|
||||
) : ICommand;
|
||||
+75
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command to install a plugin from an uploaded archive.
|
||||
/// </summary>
|
||||
public class InstallPluginCommandHandler : ICommandHandler<InstallPluginCommand, Result<Success>>
|
||||
{
|
||||
private readonly IPluginInstaller _pluginInstaller;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IValidator<InstallPluginCommand> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InstallPluginCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="pluginInstaller">Injected service for installing plugins into the plugin storage directory.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public InstallPluginCommandHandler(
|
||||
IPluginInstaller pluginInstaller,
|
||||
ICurrentUserService currentUserService,
|
||||
IAuthorizationService authorizationService,
|
||||
IValidator<InstallPluginCommand> validator)
|
||||
{
|
||||
_pluginInstaller = pluginInstaller;
|
||||
_currentUserService = currentUserService;
|
||||
_authorizationService = authorizationService;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to install a plugin from an uploaded archive.
|
||||
/// </summary>
|
||||
/// <param name="command">The command to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async Task<Result<Success>> HandleAsync(InstallPluginCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> 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<Success> installResult = await _pluginInstaller.InstallAsync(command.Archive!, command.FileName!, cancellationToken).ConfigureAwait(false);
|
||||
if (installResult.IsFailure)
|
||||
return installResult.Errors;
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
+27
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="InstallPluginCommand"/>.
|
||||
/// </summary>
|
||||
public class InstallPluginCommandValidator : AbstractValidator<InstallPluginCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InstallPluginCommandValidator"/> class.
|
||||
/// </summary>
|
||||
public InstallPluginCommandValidator()
|
||||
{
|
||||
RuleFor(command => command.Archive)
|
||||
.NotNull()
|
||||
.WithError(Errors.Plugins.PluginArchiveCannotBeNull);
|
||||
|
||||
RuleFor(command => command.FileName)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Plugins.PluginFileNameCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -108,6 +108,7 @@ public static class InfrastructureLayerServices
|
||||
PluginLoadResultDto pluginLoadResult = PluginLoader.LoadPlugins(pluginsDirectory, services);
|
||||
services.AddSingleton<IPluginManager>(new PluginManager(pluginLoadResult.Plugins));
|
||||
services.AddScoped<IPluginSettingsStore, PluginSettingsStore>();
|
||||
services.AddScoped<IPluginInstaller, PluginInstaller>();
|
||||
services.AddSingleton(serviceProvider => new PluginDetectionSyncJob(
|
||||
serviceProvider.GetRequiredService<IServiceScopeFactory>(),
|
||||
serviceProvider.GetRequiredService<IPluginManager>(),
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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<string, SemaphoreSlim> s_pluginDirectoryGates = new(StringComparer.Ordinal);
|
||||
private readonly string _pluginsDirectory;
|
||||
private readonly SemaphoreSlim _mutationGate;
|
||||
private readonly ILogger<PluginInstaller> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginInstaller"/> class.
|
||||
/// </summary>
|
||||
/// <param name="pluginsSettings">The injected plugins configuration options.</param>
|
||||
/// <param name="logger">The logger for this service.</param>
|
||||
public PluginInstaller(IOptions<PluginsSettingsDto> pluginsSettings, ILogger<PluginInstaller> logger)
|
||||
{
|
||||
_pluginsDirectory = Path.Combine(AppContext.BaseDirectory, pluginsSettings.Value.Directory);
|
||||
_mutationGate = s_pluginDirectoryGates.GetOrAdd(_pluginsDirectory, static _ => new SemaphoreSlim(1, 1));
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Installs the plugin from the provided archive, placing its assemblies into the plugin storage directory.
|
||||
/// </summary>
|
||||
/// <param name="archive">The archive stream of the uploaded plugin.</param>
|
||||
/// <param name="fileName">The file name of the uploaded plugin.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Success>> 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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies a single plugin assembly into the plugin storage directory.
|
||||
/// </summary>
|
||||
/// <param name="assemblyStream">The stream of the plugin assembly.</param>
|
||||
/// <param name="assemblyFileName">The file name of the plugin assembly.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="archive">The stream of the uploaded ZIP archive.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
private async Task<Result<Success>> 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;
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
+68
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/plugins</c> route.
|
||||
/// </summary>
|
||||
public class InstallPluginEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<InstallPluginCommand, Result<Success>> _installPluginCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InstallPluginEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="installPluginCommandHandler">Injected service for handling install plugin commands.</param>
|
||||
public InstallPluginEndpoint(ICommandHandler<InstallPluginCommand, Result<Success>> installPluginCommandHandler)
|
||||
{
|
||||
_installPluginCommandHandler = installPluginCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.POST);
|
||||
Routes(ApiRoutes.Plugins.INSTALL_PLUGIN);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Installs the plugin uploaded in the multipart form of the request, placing its assemblies into the plugin storage directory.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> 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<Success> result = await _installPluginCommandHandler.HandleAsync(command, cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(), Problem);
|
||||
}
|
||||
}
|
||||
+110
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="InstallPluginEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class InstallPluginEndpointSummary : Summary<InstallPluginEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InstallPluginEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
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<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PluginArchiveCannotBeNull"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
+63
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/admin/manage-plugins/api-install-plugin</c> route.
|
||||
/// </summary>
|
||||
public class InstallPluginEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InstallPluginEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public InstallPluginEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Installs the plugin uploaded in the multipart form of the request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> 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<PluginDto>(ApiRoutes.Plugins.INSTALL_PLUGIN, archiveStream, archive.FileName, "archive", cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess();
|
||||
}
|
||||
}
|
||||
+25
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="InstallPluginEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class InstallPluginEndpointSummary : Summary<InstallPluginEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InstallPluginEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
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));
|
||||
}
|
||||
}
|
||||
+16
-1
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -723,4 +723,19 @@
|
||||
<data name="VolumeNumberMustBeGreaterThanZero" xml:space="preserve">
|
||||
<value>يجب أن يكون رقم المجلد أكبر من الصفر!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveContainsNoAssemblies" xml:space="preserve">
|
||||
<value>أرشيف المكوّن الإضافي المرفوع لا يحتوي على تجميعات!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveCannotBeNull" xml:space="preserve">
|
||||
<value>لا يمكن أن يكون أرشيف المكوّن الإضافي فارغاً!</value>
|
||||
</data>
|
||||
<data name="PluginFileNameCannotBeEmpty" xml:space="preserve">
|
||||
<value>لا يمكن أن يكون اسم ملف المكوّن الإضافي فارغاً!</value>
|
||||
</data>
|
||||
<data name="UnsupportedPluginFileType" xml:space="preserve">
|
||||
<value>نوع ملف المكوّن الإضافي المرفوع غير مدعوم!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveNotReadable" xml:space="preserve">
|
||||
<value>تعذّرت قراءة أرشيف المكوّن الإضافي المرفوع!</value>
|
||||
</data>
|
||||
</root>
|
||||
+16
-1
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -723,4 +723,19 @@
|
||||
<data name="VolumeNumberMustBeGreaterThanZero" xml:space="preserve">
|
||||
<value>Bandnummer muss größer als null sein!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveContainsNoAssemblies" xml:space="preserve">
|
||||
<value>Das hochgeladene Plugin-Archiv enthält keine Assemblys!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveCannotBeNull" xml:space="preserve">
|
||||
<value>Das Plugin-Archiv darf nicht null sein!</value>
|
||||
</data>
|
||||
<data name="PluginFileNameCannotBeEmpty" xml:space="preserve">
|
||||
<value>Der Dateiname des Plugins darf nicht leer sein!</value>
|
||||
</data>
|
||||
<data name="UnsupportedPluginFileType" xml:space="preserve">
|
||||
<value>Der Dateityp des hochgeladenen Plugins wird nicht unterstützt!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveNotReadable" xml:space="preserve">
|
||||
<value>Das hochgeladene Plugin-Archiv konnte nicht gelesen werden!</value>
|
||||
</data>
|
||||
</root>
|
||||
+16
-1
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -723,4 +723,19 @@
|
||||
<data name="VolumeNumberMustBeGreaterThanZero" xml:space="preserve">
|
||||
<value>Volume number must be greater than zero!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveContainsNoAssemblies" xml:space="preserve">
|
||||
<value>The uploaded plugin archive contains no assemblies!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveCannotBeNull" xml:space="preserve">
|
||||
<value>The plugin archive cannot be null!</value>
|
||||
</data>
|
||||
<data name="PluginFileNameCannotBeEmpty" xml:space="preserve">
|
||||
<value>The plugin file name cannot be empty!</value>
|
||||
</data>
|
||||
<data name="UnsupportedPluginFileType" xml:space="preserve">
|
||||
<value>The uploaded plugin file type is not supported!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveNotReadable" xml:space="preserve">
|
||||
<value>The plugin archive could not be read!</value>
|
||||
</data>
|
||||
</root>
|
||||
+16
-1
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -723,4 +723,19 @@
|
||||
<data name="VolumeNumberMustBeGreaterThanZero" xml:space="preserve">
|
||||
<value>¡El número de volumen debe ser mayor que cero!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveContainsNoAssemblies" xml:space="preserve">
|
||||
<value>El archivo del plugin subido no contiene ensamblados!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveCannotBeNull" xml:space="preserve">
|
||||
<value>El archivo del plugin no puede ser nulo!</value>
|
||||
</data>
|
||||
<data name="PluginFileNameCannotBeEmpty" xml:space="preserve">
|
||||
<value>El nombre del archivo del plugin no puede estar vacío!</value>
|
||||
</data>
|
||||
<data name="UnsupportedPluginFileType" xml:space="preserve">
|
||||
<value>El tipo de archivo del plugin subido no es compatible!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveNotReadable" xml:space="preserve">
|
||||
<value>No se pudo leer el archivo del plugin subido!</value>
|
||||
</data>
|
||||
</root>
|
||||
+16
-1
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -723,4 +723,19 @@
|
||||
<data name="VolumeNumberMustBeGreaterThanZero" xml:space="preserve">
|
||||
<value>Le numéro de volume doit être supérieur à zéro !</value>
|
||||
</data>
|
||||
<data name="PluginArchiveContainsNoAssemblies" xml:space="preserve">
|
||||
<value>L'archive du plugin téléversé ne contient aucun assembly !</value>
|
||||
</data>
|
||||
<data name="PluginArchiveCannotBeNull" xml:space="preserve">
|
||||
<value>L'archive du plugin ne peut pas etre nulle !</value>
|
||||
</data>
|
||||
<data name="PluginFileNameCannotBeEmpty" xml:space="preserve">
|
||||
<value>Le nom du fichier du plugin ne peut pas etre vide !</value>
|
||||
</data>
|
||||
<data name="UnsupportedPluginFileType" xml:space="preserve">
|
||||
<value>Le type de fichier du plugin téléversé n est pas pris en charge !</value>
|
||||
</data>
|
||||
<data name="PluginArchiveNotReadable" xml:space="preserve">
|
||||
<value>L'archive du plugin téléversé n a pas pu être lue !</value>
|
||||
</data>
|
||||
</root>
|
||||
+16
-1
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -723,4 +723,19 @@
|
||||
<data name="VolumeNumberMustBeGreaterThanZero" xml:space="preserve">
|
||||
<value>Il numero del volume deve essere maggiore di zero!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveContainsNoAssemblies" xml:space="preserve">
|
||||
<value>L'archivio del plugin caricato non contiene assembly!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveCannotBeNull" xml:space="preserve">
|
||||
<value>L'archivio del plugin non può essere nullo!</value>
|
||||
</data>
|
||||
<data name="PluginFileNameCannotBeEmpty" xml:space="preserve">
|
||||
<value>Il nome del file del plugin non può essere vuoto!</value>
|
||||
</data>
|
||||
<data name="UnsupportedPluginFileType" xml:space="preserve">
|
||||
<value>Il tipo di file del plugin caricato non è supportato!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveNotReadable" xml:space="preserve">
|
||||
<value>Non è stato possibile leggere l archivio del plugin caricato!</value>
|
||||
</data>
|
||||
</root>
|
||||
+16
-1
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -723,4 +723,19 @@
|
||||
<data name="VolumeNumberMustBeGreaterThanZero" xml:space="preserve">
|
||||
<value>巻数は0より大きくなければなりません!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveContainsNoAssemblies" xml:space="preserve">
|
||||
<value>アップロードされたプラグインアーカイブにアセンブリが含まれていません!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveCannotBeNull" xml:space="preserve">
|
||||
<value>プラグインアーカイブを null にすることはできません!</value>
|
||||
</data>
|
||||
<data name="PluginFileNameCannotBeEmpty" xml:space="preserve">
|
||||
<value>プラグインのファイル名を空にすることはできません!</value>
|
||||
</data>
|
||||
<data name="UnsupportedPluginFileType" xml:space="preserve">
|
||||
<value>アップロードされたプラグインのファイルタイプはサポートされていません!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveNotReadable" xml:space="preserve">
|
||||
<value>アップロードされたプラグインアーカイブを読み取れませんでした!</value>
|
||||
</data>
|
||||
</root>
|
||||
+16
-1
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -723,4 +723,19 @@
|
||||
<data name="VolumeNumberMustBeGreaterThanZero" xml:space="preserve">
|
||||
<value>Volume number must be greater than zero!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveContainsNoAssemblies" xml:space="preserve">
|
||||
<value>The uploaded plugin archive contains no assemblies!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveCannotBeNull" xml:space="preserve">
|
||||
<value>The plugin archive cannot be null!</value>
|
||||
</data>
|
||||
<data name="PluginFileNameCannotBeEmpty" xml:space="preserve">
|
||||
<value>The plugin file name cannot be empty!</value>
|
||||
</data>
|
||||
<data name="UnsupportedPluginFileType" xml:space="preserve">
|
||||
<value>The uploaded plugin file type is not supported!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveNotReadable" xml:space="preserve">
|
||||
<value>The plugin archive could not be read!</value>
|
||||
</data>
|
||||
</root>
|
||||
+16
-1
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -723,4 +723,19 @@
|
||||
<data name="VolumeNumberMustBeGreaterThanZero" xml:space="preserve">
|
||||
<value>Numărul volumului trebuie să fie mai mare decât zero!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveContainsNoAssemblies" xml:space="preserve">
|
||||
<value>Arhiva pluginului încărcat nu conține niciun assembly!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveCannotBeNull" xml:space="preserve">
|
||||
<value>Arhiva pluginului nu poate fi nulă!</value>
|
||||
</data>
|
||||
<data name="PluginFileNameCannotBeEmpty" xml:space="preserve">
|
||||
<value>Numele fișierului pluginului nu poate fi gol!</value>
|
||||
</data>
|
||||
<data name="UnsupportedPluginFileType" xml:space="preserve">
|
||||
<value>Tipul de fișier al pluginului încărcat nu este acceptat!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveNotReadable" xml:space="preserve">
|
||||
<value>Arhiva pluginului încărcat nu a putut fi citită!</value>
|
||||
</data>
|
||||
</root>
|
||||
+16
-1
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -723,4 +723,19 @@
|
||||
<data name="VolumeNumberMustBeGreaterThanZero" xml:space="preserve">
|
||||
<value>Номер тому має бути більшим за нуль!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveContainsNoAssemblies" xml:space="preserve">
|
||||
<value>Архів завантаженого плагіна не містить збірок!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveCannotBeNull" xml:space="preserve">
|
||||
<value>Архів плагіна не може бути null!</value>
|
||||
</data>
|
||||
<data name="PluginFileNameCannotBeEmpty" xml:space="preserve">
|
||||
<value>Ім'я файлу плагіна не може бути порожнім!</value>
|
||||
</data>
|
||||
<data name="UnsupportedPluginFileType" xml:space="preserve">
|
||||
<value>Тип файлу завантаженого плагіна не підтримується!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveNotReadable" xml:space="preserve">
|
||||
<value>Не вдалося прочитати архів завантаженого плагіна!</value>
|
||||
</data>
|
||||
</root>
|
||||
+16
-1
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -723,4 +723,19 @@
|
||||
<data name="VolumeNumberMustBeGreaterThanZero" xml:space="preserve">
|
||||
<value>卷号必须大于零!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveContainsNoAssemblies" xml:space="preserve">
|
||||
<value>上传的插件存档中不包含程序集!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveCannotBeNull" xml:space="preserve">
|
||||
<value>插件存档不能为空!</value>
|
||||
</data>
|
||||
<data name="PluginFileNameCannotBeEmpty" xml:space="preserve">
|
||||
<value>插件文件名不能为空!</value>
|
||||
</data>
|
||||
<data name="UnsupportedPluginFileType" xml:space="preserve">
|
||||
<value>不支持上传的插件文件类型!</value>
|
||||
</data>
|
||||
<data name="PluginArchiveNotReadable" xml:space="preserve">
|
||||
<value>无法读取上传的插件存档!</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -156,4 +156,13 @@
|
||||
<data name="SettingsSaved" xml:space="preserve">
|
||||
<value>تم حفظ الإعدادات</value>
|
||||
</data>
|
||||
<data name="PluginUploadedRestartRequired" xml:space="preserve">
|
||||
<value>تم رفع المكوّن الإضافي. سيقوم API بتحميله عند إعادة التشغيل التالية.</value>
|
||||
</data>
|
||||
<data name="Upload" xml:space="preserve">
|
||||
<value>رفع</value>
|
||||
</data>
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>فشل الرفع</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -156,4 +156,13 @@
|
||||
<data name="SettingsSaved" xml:space="preserve">
|
||||
<value>Einstellungen gespeichert</value>
|
||||
</data>
|
||||
<data name="PluginUploadedRestartRequired" xml:space="preserve">
|
||||
<value>Plugin hochgeladen. Die API lädt es beim nächsten Neustart.</value>
|
||||
</data>
|
||||
<data name="Upload" xml:space="preserve">
|
||||
<value>Hochladen</value>
|
||||
</data>
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Upload fehlgeschlagen</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -156,4 +156,13 @@
|
||||
<data name="SettingsSaved" xml:space="preserve">
|
||||
<value>Settings saved</value>
|
||||
</data>
|
||||
<data name="PluginUploadedRestartRequired" xml:space="preserve">
|
||||
<value>Plugin uploaded. The API will load it on its next restart.</value>
|
||||
</data>
|
||||
<data name="Upload" xml:space="preserve">
|
||||
<value>Upload</value>
|
||||
</data>
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Upload failed</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -156,4 +156,13 @@
|
||||
<data name="SettingsSaved" xml:space="preserve">
|
||||
<value>Configuración guardada</value>
|
||||
</data>
|
||||
<data name="PluginUploadedRestartRequired" xml:space="preserve">
|
||||
<value>Plugin subido. La API lo cargará en su próximo reinicio.</value>
|
||||
</data>
|
||||
<data name="Upload" xml:space="preserve">
|
||||
<value>Subir</value>
|
||||
</data>
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Error al subir</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -156,4 +156,13 @@
|
||||
<data name="SettingsSaved" xml:space="preserve">
|
||||
<value>Paramètres enregistrés</value>
|
||||
</data>
|
||||
<data name="PluginUploadedRestartRequired" xml:space="preserve">
|
||||
<value>Plugin téléversé. L API le chargera à son prochain redémarrage.</value>
|
||||
</data>
|
||||
<data name="Upload" xml:space="preserve">
|
||||
<value>Téléverser</value>
|
||||
</data>
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Échec du téléversement</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -156,4 +156,13 @@
|
||||
<data name="SettingsSaved" xml:space="preserve">
|
||||
<value>Impostazioni salvate</value>
|
||||
</data>
|
||||
<data name="PluginUploadedRestartRequired" xml:space="preserve">
|
||||
<value>Plugin caricato. L API lo caricherà al prossimo riavvio.</value>
|
||||
</data>
|
||||
<data name="Upload" xml:space="preserve">
|
||||
<value>Carica</value>
|
||||
</data>
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Caricamento non riuscito</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -156,4 +156,13 @@
|
||||
<data name="SettingsSaved" xml:space="preserve">
|
||||
<value>設定を保存しました</value>
|
||||
</data>
|
||||
<data name="PluginUploadedRestartRequired" xml:space="preserve">
|
||||
<value>プラグインがアップロードされました。APIは次回再起動時に読み込みます。</value>
|
||||
</data>
|
||||
<data name="Upload" xml:space="preserve">
|
||||
<value>アップロード</value>
|
||||
</data>
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>アップロードに失敗しました</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -156,4 +156,13 @@
|
||||
<data name="SettingsSaved" xml:space="preserve">
|
||||
<value>Settings saved</value>
|
||||
</data>
|
||||
<data name="PluginUploadedRestartRequired" xml:space="preserve">
|
||||
<value>Plugin uploaded. The API will load it on its next restart.</value>
|
||||
</data>
|
||||
<data name="Upload" xml:space="preserve">
|
||||
<value>Upload</value>
|
||||
</data>
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Upload failed</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -156,4 +156,13 @@
|
||||
<data name="SettingsSaved" xml:space="preserve">
|
||||
<value>Setări salvate</value>
|
||||
</data>
|
||||
<data name="PluginUploadedRestartRequired" xml:space="preserve">
|
||||
<value>Plugin încărcat. API-ul îl va încărca la următoarea repornire.</value>
|
||||
</data>
|
||||
<data name="Upload" xml:space="preserve">
|
||||
<value>Încarcă</value>
|
||||
</data>
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Încărcarea a eșuat</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
@@ -156,4 +156,13 @@
|
||||
<data name="SettingsSaved" xml:space="preserve">
|
||||
<value>Налаштування збережено</value>
|
||||
</data>
|
||||
<data name="PluginUploadedRestartRequired" xml:space="preserve">
|
||||
<value>Плагін завантажено. API завантажить його під час наступного перезапуску.</value>
|
||||
</data>
|
||||
<data name="Upload" xml:space="preserve">
|
||||
<value>Завантажити</value>
|
||||
</data>
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>Не вдалося завантажити</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -156,4 +156,13 @@
|
||||
<data name="SettingsSaved" xml:space="preserve">
|
||||
<value>设置已保存</value>
|
||||
</data>
|
||||
<data name="PluginUploadedRestartRequired" xml:space="preserve">
|
||||
<value>插件已上传。API将在下次重启时加载它。</value>
|
||||
</data>
|
||||
<data name="Upload" xml:space="preserve">
|
||||
<value>上传</value>
|
||||
</data>
|
||||
<data name="UploadFailed" xml:space="preserve">
|
||||
<value>上传失败</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -27,6 +27,10 @@
|
||||
@_localizer["Plugins"]
|
||||
</h1>
|
||||
</div>
|
||||
<div class="form-row" style="margin-bottom: 0.75rem;">
|
||||
<button id="btn-upload-plugin" type="button" class="confirm-button">@_localizer["Upload"]</button>
|
||||
<input id="plugin-upload-input" type="file" accept=".zip,.dll" hidden />
|
||||
</div>
|
||||
@if (Model.Length > 0)
|
||||
{
|
||||
<table class="w-100 text-light-two">
|
||||
@@ -179,14 +183,48 @@
|
||||
}
|
||||
};
|
||||
|
||||
const uploadButton = document.getElementById('btn-upload-plugin');
|
||||
const uploadInput = document.getElementById('plugin-upload-input');
|
||||
const installUrl = '@_urlService.GetAbsoluteUrl(WebRoutes.Plugins.INSTALL_PLUGIN)';
|
||||
|
||||
// uploads the selected plugin archive as a multipart request, keeping the antiforgery token
|
||||
async function handleUploadInputChange() {
|
||||
const file = uploadInput.files[0];
|
||||
if (!file)
|
||||
return;
|
||||
const formData = new FormData();
|
||||
formData.append('archive', file);
|
||||
formData.append('__RequestVerificationToken', document.querySelector('input[name="__RequestVerificationToken"]')?.value ?? '');
|
||||
const response = await fetch(installUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'X-Requested-With': 'XMLHttpRequest' },
|
||||
body: formData
|
||||
});
|
||||
if (response.ok) {
|
||||
notificationService.show('@_localizer["PluginUploadedRestartRequired"]', NotificationType.SUCCESS);
|
||||
uploadInput.value = '';
|
||||
} else {
|
||||
notificationService.show('@_localizer["UploadFailed"]', NotificationType.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
// opens the file picker when the upload button is clicked
|
||||
function handleUploadButtonClick() {
|
||||
uploadInput.click();
|
||||
}
|
||||
|
||||
// add listeners
|
||||
document.addEventListener('click', handleSettingsToggleClick);
|
||||
document.addEventListener('click', handleSavePluginSettingsClick);
|
||||
uploadButton.addEventListener('click', handleUploadButtonClick);
|
||||
uploadInput.addEventListener('change', handleUploadInputChange);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
document.removeEventListener('click', handleSettingsToggleClick);
|
||||
document.removeEventListener('click', handleSavePluginSettingsClick);
|
||||
uploadButton.removeEventListener('click', handleUploadButtonClick);
|
||||
uploadInput.removeEventListener('change', handleUploadInputChange);
|
||||
});
|
||||
|
||||
// store all cleanups for this view on window object using the scriptId
|
||||
|
||||
Reference in new issue
Block a user