2025-07-25 17:57:33 -05:00
|
|
|
using System.Net.Mime;
|
|
|
|
|
using LANCommander.Server.Services;
|
2025-07-27 17:51:50 -05:00
|
|
|
using LANCommander.Server.ImportExport.Services;
|
2025-07-25 17:57:33 -05:00
|
|
|
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
|
|
|
|
|
{
|
2025-07-27 17:51:50 -05:00
|
|
|
private readonly ExportService ExportService;
|
2025-07-25 17:57:33 -05:00
|
|
|
|
|
|
|
|
public ExportController(
|
2025-07-27 17:51:50 -05:00
|
|
|
ExportService exportService,
|
2025-07-25 17:57:33 -05:00
|
|
|
ILogger<ExportController> logger) : base(logger)
|
|
|
|
|
{
|
2025-07-27 17:51:50 -05:00
|
|
|
ExportService = exportService;
|
2025-07-25 17:57:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//[Authorize(Roles = RoleService.AdministratorRoleName)]
|
|
|
|
|
[HttpGet("{contextId:guid}")]
|
|
|
|
|
public async Task ExportAsync(Guid contextId)
|
|
|
|
|
{
|
2025-07-27 17:51:50 -05:00
|
|
|
var context = ExportService.GetContext(contextId);
|
2025-07-25 17:57:33 -05:00
|
|
|
|
|
|
|
|
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\"");
|
|
|
|
|
|
2025-07-27 17:51:50 -05:00
|
|
|
await ExportService.ExportAsync(contextId, Response.Body);
|
2025-07-25 17:57:33 -05:00
|
|
|
}
|
|
|
|
|
}
|