Skip to content

Commit

Permalink
feat(replay): Implement minimap rendering functionality
Browse files Browse the repository at this point in the history
This commit adds the following changes:
- Added a new endpoint in the `ReplayController` to trigger minimap rendering on a post's replay.
- Created a new method `RenderMinimap` in the `ReplayController` to handle the minimap rendering logic.
- Added a new service called `MinimapRenderingService` to handle the background job for rendering the minimap.
- Updated the `ReplaysIngestService` to include the MiniMapUri property in the ReplayDTO, which contains the URI of the rendered minimap video file.
- Added a reference to `WowsKarma.Api.Minimap.Client` project in `WowsKarma.Api.csproj`.
- Registered `MinimapRenderingService` as a scoped service in Startup.cs.

The new endpoint allows administrators to trigger minimap rendering on a post's replay by providing the postId. The MinimapRenderingService then enqueues a background job to render and save the minimap video file. The MiniMapUri property is added to ReplayDTO, which contains the URI of the rendered minimap video file.
  • Loading branch information
SakuraIsayeki committed Jul 21, 2023
1 parent 28e1a05 commit fb9d298
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
27 changes: 25 additions & 2 deletions WowsKarma.Api/Controllers/ReplayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using WowsKarma.Api.Data.Models.Replays;
using WowsKarma.Api.Infrastructure.Exceptions;
using WowsKarma.Api.Services;
using WowsKarma.Api.Services.Minimap;
using WowsKarma.Api.Services.Posts;
using WowsKarma.Api.Services.Replays;
using WowsKarma.Common;
Expand Down Expand Up @@ -102,7 +103,7 @@ public async Task<IActionResult> UploadReplayAsync(Guid postId, IFormFile replay
/// <param name="start">Start of date/time range</param>
/// <param name="end">End of date/time range</param>
/// <returns></returns>
[HttpPatch("reprocess/all"), Authorize(Roles = ApiRoles.Administrator)]
[HttpPatch("reprocess/replay/all"), Authorize(Roles = ApiRoles.Administrator)]
public async Task<IActionResult> ReprocessPostsAsync(DateTime start = default, DateTime end = default, CancellationToken ct = default)
{
if (start == default)
Expand All @@ -123,7 +124,7 @@ public async Task<IActionResult> ReprocessPostsAsync(DateTime start = default, D
/// Triggers reporessing on a replay (Usable only by Administrators)
/// </summary>
/// <returns></returns>
[HttpPatch("reprocess/{replayId:guid}"), Authorize(Roles = ApiRoles.Administrator)]
[HttpPatch("reprocess/replay/{replayId:guid}"), Authorize(Roles = ApiRoles.Administrator)]
public async Task<IActionResult> ReprocessReplayAsync(Guid replayId, CancellationToken ct = default)
{
try
Expand All @@ -136,4 +137,26 @@ public async Task<IActionResult> ReprocessReplayAsync(Guid replayId, Cancellatio
return StatusCode(404, $"No replay with GUID {replayId} found.");
}
}

/// <summary>
/// Triggers minimap rendering on a post's replay (Usable only by Administrators)
/// </summary>
/// <param name="postId">The ID of the post to render the replay's minimap for.</param>
/// <param name="postService"></param>
/// <param name="ct">The cancellation token.</param>
/// <response code="202">The job was enqueued successfully.</response>
/// <response code="404">No post with the specified GUID was found.</response>
[HttpPatch("reprocess/minimap/{postId:guid}")]//[Authorize(Roles = ApiRoles.Administrator)]
public IActionResult RenderMinimap(Guid postId,
[FromServices] PostService postService,
CancellationToken ct = default
) {
if (postService.GetPost(postId) is not { } post)
{
return StatusCode(404, $"No post with GUID {postId} found.");
}

BackgroundJob.Enqueue<MinimapRenderingService>(s => s.RenderPostReplayMinimapAsync(post.Id, post.PlayerId, ct));
return StatusCode(202);
}
}
4 changes: 3 additions & 1 deletion WowsKarma.Api/Services/Replays/ReplaysIngestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using WowsKarma.Api.Data;
using WowsKarma.Api.Data.Models.Replays;
using WowsKarma.Api.Infrastructure.Exceptions;
using WowsKarma.Api.Services.Minimap;
using WowsKarma.Common;
using WowsKarma.Common.Models.DTOs.Replays;

Expand Down Expand Up @@ -62,7 +63,8 @@ public async Task<ReplayDTO> GetReplayDTOAsync(Guid id)
ChatMessages = replay.ChatMessages.Adapt<IEnumerable<ReplayChatMessageDTO>>()
.Select(m => m with { Username = replay.Players.FirstOrDefault(p => p.AccountId == m.PlayerId).Name }),
Players = replay.Players.Adapt<IEnumerable<ReplayPlayerDTO>>(),
DownloadUri = (await GenerateReplayDownloadLinkAsync(id)).ToString(),
DownloadUri = $"{_containerClient.Uri}/{ReplayBlobContainer}/{replay.BlobName}",
MiniMapUri = $"{_containerClient.Uri}/{MinimapRenderingService.MinimapBlobContainer}/{replay.Id}.mp4"
};
}

Expand Down
7 changes: 6 additions & 1 deletion WowsKarma.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
using WowsKarma.Api.Infrastructure.Authorization;
using WowsKarma.Api.Infrastructure.Telemetry;
using WowsKarma.Api.Middlewares;
using WowsKarma.Api.Minimap.Client;
using WowsKarma.Api.Services;
using WowsKarma.Api.Services.Authentication;
using WowsKarma.Api.Services.Authentication.Cookie;
using WowsKarma.Api.Services.Authentication.Jwt;
using WowsKarma.Api.Services.Discord;
using WowsKarma.Api.Services.Minimap;
using WowsKarma.Api.Services.Posts;
using WowsKarma.Api.Services.Replays;
using WowsKarma.Api.Utilities;
Expand Down Expand Up @@ -214,12 +216,14 @@ public void ConfigureServices(IServiceCollection services)
AppId = s.GetRequiredService<IConfiguration>()[$"Api:{ApiRegion.ToRegionString()}:AppId"]
?? throw new InvalidOperationException("AppId not found in configuration"),
});

services.AddWowsReplayUnpacker(builder =>
{
builder.AddExtendedData();
});

services.AddMinimapApiClient(options => Configuration.GetSection("MinimapApi").Bind(options));

services.AddHangfireServer();
services.AddHangfire((s, config) =>
{
Expand Down Expand Up @@ -257,6 +261,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddScoped<NotificationService>();
services.AddScoped<ReplaysIngestService>();
services.AddScoped<ReplaysProcessService>();
services.AddScoped<MinimapRenderingService>();

services.AddScoped<IAuthorizationHandler, PlatformBanAuthorizationHandler>();

Expand Down
6 changes: 6 additions & 0 deletions WowsKarma.Api/WowsKarma.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WowsKarma.Api.Minimap.Client\WowsKarma.Api.Minimap.Client.csproj" />
<ProjectReference Include="..\WowsKarma.Common\WowsKarma.Common.csproj" />


</ItemGroup>




</Project>
2 changes: 2 additions & 0 deletions WowsKarma.Common/Models/DTOs/Replays/ReplayDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public record ReplayDTO
public Guid PostId { get; init; }

public string DownloadUri { get; init; }

public string MiniMapUri { get; init; }

public IEnumerable<ReplayPlayerDTO> Players { get; set; }

Expand Down

0 comments on commit fb9d298

Please sign in to comment.