LANCommander/LANCommander.Server/Controllers/Api/ExportController.cs
Pat Hartl 6ec919d1be Separate import and export functionality
This refactor splits the import and export functionality out of the ImportContext and adds an ExportContext. This also introduced separate importer and exporter implementations.

Additionally, adding archive, save, scripts, and server files to the final export archive has been implemented at the exporter implementation for each instead of handling it in the context. This should be a good pattern if other files need to be added down the road.
2025-07-27 17:51:50 -05:00

40 lines
No EOL
1.3 KiB
C#

using System.Net.Mime;
using LANCommander.Server.Services;
using LANCommander.Server.ImportExport.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Mvc;
namespace LANCommander.Server.Controllers.Api;
//[Authorize(AuthenticationSchemes = "Bearer")]
[Route("api/[controller]")]
[ApiController]
public class ExportController : BaseApiController
{
private readonly ExportService ExportService;
public ExportController(
ExportService exportService,
ILogger<ExportController> logger) : base(logger)
{
ExportService = exportService;
}
//[Authorize(Roles = RoleService.AdministratorRoleName)]
[HttpGet("{contextId:guid}")]
public async Task ExportAsync(Guid contextId)
{
var context = ExportService.GetContext(contextId);
var syncIOFeature = HttpContext.Features.Get<IHttpBodyControlFeature>();
if (syncIOFeature != null)
syncIOFeature.AllowSynchronousIO = true;
Response.ContentType = MediaTypeNames.Application.Octet;
Response.Headers.Append("Content-Disposition", $"attachment; filename=\"export.lcx\"");
await ExportService.ExportAsync(contextId, Response.Body);
}
}