LANCommander/LANCommander.Server/Controllers/GamesController.cs

62 lines
2.3 KiB
C#
Raw Permalink Normal View History

using LANCommander.Server.Services;
using Microsoft.AspNetCore.Authorization;
using LANCommander.SDK.Enums;
using LANCommander.Server.ImportExport.Factories;
2024-08-04 18:44:33 -05:00
namespace LANCommander.Server.Controllers
{
[Authorize(Roles = RoleService.AdministratorRoleName)]
public class GamesController : BaseController
{
2024-08-28 20:34:09 -05:00
private readonly GameService GameService;
private readonly ExportContextFactory ExportContextFactory;
public GamesController(
ILogger<GamesController> logger,
GameService gameService,
ExportContextFactory exportContextFactory) : base(logger)
{
GameService = gameService;
ExportContextFactory = exportContextFactory;
}
public async Task ExportAsync(Guid id)
{
using (var context = ExportContextFactory.Create())
{
var game = await GameService
.Include(g => g.Actions)
.Include(g => g.Archives)
.Include(g => g.BaseGame)
.Include(g => g.Categories)
.Include(g => g.Collections)
.Include(g => g.CustomFields)
.Include(g => g.DependentGames)
.Include(g => g.Developers)
.Include(g => g.Engine)
.Include(g => g.Genres)
.Include(g => g.Media)
.Include(g => g.MultiplayerModes)
.Include(g => g.Platforms)
.Include(g => g.Publishers)
.Include(g => g.Redistributables)
.Include(g => g.Scripts)
.Include(g => g.Tags)
.GetAsync(id);
if (game == null)
{
Response.StatusCode = StatusCodes.Status404NotFound;
return;
}
Response.ContentType = "application/octet-stream";
Response.Headers.Append("Content-Disposition", @$"attachment; filename=""{game.Title}.lcx""");
//await context.PrepareGameExportQueueAsync(game, flags);
await context.ExportQueueAsync(Response.BodyWriter.AsStream());
}
}
}
}