2025-07-27 17:51:50 -05:00
|
|
|
|
using LANCommander.Server.Services;
|
2023-12-14 19:09:00 -06:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2025-11-16 12:31:25 -06:00
|
|
|
|
|
2025-07-27 17:51:50 -05:00
|
|
|
|
using LANCommander.Server.ImportExport.Factories;
|
2023-12-14 19:09:00 -06:00
|
|
|
|
|
2024-08-04 18:44:33 -05:00
|
|
|
|
namespace LANCommander.Server.Controllers
|
2023-12-14 19:09:00 -06:00
|
|
|
|
{
|
2024-10-16 02:06:02 -05:00
|
|
|
|
[Authorize(Roles = RoleService.AdministratorRoleName)]
|
2023-12-14 19:09:00 -06:00
|
|
|
|
public class GamesController : BaseController
|
|
|
|
|
|
{
|
2024-08-28 20:34:09 -05:00
|
|
|
|
private readonly GameService GameService;
|
2025-07-27 17:51:50 -05:00
|
|
|
|
private readonly ExportContextFactory ExportContextFactory;
|
2023-12-14 19:09:00 -06:00
|
|
|
|
|
2024-08-28 20:33:59 -05:00
|
|
|
|
public GamesController(
|
|
|
|
|
|
ILogger<GamesController> logger,
|
2025-11-16 12:31:25 -06:00
|
|
|
|
SettingsProvider<Settings.Settings> settingsProvider,
|
2024-08-28 20:33:59 -05:00
|
|
|
|
GameService gameService,
|
2025-11-16 12:31:25 -06:00
|
|
|
|
ExportContextFactory exportContextFactory) : base(logger, settingsProvider)
|
2023-12-14 19:09:00 -06:00
|
|
|
|
{
|
|
|
|
|
|
GameService = gameService;
|
2025-07-27 17:51:50 -05:00
|
|
|
|
ExportContextFactory = exportContextFactory;
|
2023-12-14 19:09:00 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-01 02:27:06 -05:00
|
|
|
|
public async Task ExportAsync(Guid id)
|
2023-12-14 19:09:00 -06:00
|
|
|
|
{
|
2025-07-27 17:51:50 -05:00
|
|
|
|
using (var context = ExportContextFactory.Create())
|
2024-01-08 18:22:00 -06:00
|
|
|
|
{
|
2025-07-15 20:32:46 -05:00
|
|
|
|
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)
|
2024-01-08 18:22:00 -06:00
|
|
|
|
{
|
2025-07-15 20:32:46 -05:00
|
|
|
|
Response.StatusCode = StatusCodes.Status404NotFound;
|
|
|
|
|
|
return;
|
2024-01-08 18:22:00 -06:00
|
|
|
|
}
|
2025-07-15 20:32:46 -05:00
|
|
|
|
|
|
|
|
|
|
Response.ContentType = "application/octet-stream";
|
|
|
|
|
|
Response.Headers.Append("Content-Disposition", @$"attachment; filename=""{game.Title}.lcx""");
|
2024-01-08 18:22:00 -06:00
|
|
|
|
|
2025-07-19 17:39:55 -05:00
|
|
|
|
//await context.PrepareGameExportQueueAsync(game, flags);
|
2025-07-15 20:32:46 -05:00
|
|
|
|
await context.ExportQueueAsync(Response.BodyWriter.AsStream());
|
2024-01-08 18:22:00 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-12-14 19:09:00 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|