Adds a new section "Scripting" in the server UI where PowerShell modules can be defined. These can be used for defining a library of functions that can be used in any script. These modules are automatically synced to the launcher and imported upon script execution.
32 lines
1 KiB
C#
32 lines
1 KiB
C#
using LANCommander.Server.Services;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace LANCommander.Server.Endpoints;
|
|
|
|
public static class ModulesEndpoints
|
|
{
|
|
public static void MapModulesEndpoints(this IEndpointRouteBuilder routes)
|
|
{
|
|
var group = routes.MapGroup("/api/Modules").RequireAuthorization();
|
|
|
|
group.MapGet("/", GetAsync);
|
|
group.MapGet("/Download", DownloadAsync);
|
|
}
|
|
|
|
internal static IResult GetAsync([FromServices] ModuleService moduleService)
|
|
{
|
|
var names = moduleService.GetModules().Select(m => m.Name);
|
|
|
|
return TypedResults.Ok(names);
|
|
}
|
|
|
|
internal static IResult DownloadAsync([FromServices] ModuleService moduleService)
|
|
{
|
|
var archivePath = moduleService.GetModulesArchive();
|
|
|
|
var stream = new FileStream(archivePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096,
|
|
FileOptions.DeleteOnClose | FileOptions.Asynchronous);
|
|
|
|
return TypedResults.File(stream, "application/octet-stream", "Modules.zip");
|
|
}
|
|
}
|