mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Adds the music track stream endpoint
Adds the track stream route, its query, validator and handler, a flat stream projection in the track repository, and an endpoint that streams the audio file with HTTP range support. Excludes the route from the eventual consistency pipeline through endpoint metadata and limits it per user with a concurrency limiter. Missing, unreadable and out of scope files are reported as not found without leaking the path. Adds the API and request documentation and the stream tests.
This commit is contained in:
1 parent
0ad6e1307b
commit
4ffa81fffe
18 files changed
+985
No files matched your search
@@ -0,0 +1,8 @@
|
||||
namespace Lumina.Presentation.Api.Common.Http;
|
||||
|
||||
/// <summary>
|
||||
/// Marker metadata that opts an endpoint out of the eventual consistency pipeline, so that a long lived response (for example a track stream) never holds the request's database transaction open.
|
||||
/// </summary>
|
||||
public sealed class SkipEventualConsistencyMetadata
|
||||
{
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Exceptions;
|
||||
using Lumina.Presentation.Api.Common.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -39,6 +40,14 @@ public class EventualConsistencyMiddleware
|
||||
/// <param name="domainEventQueue">In memory queue containing the queued domain events.</param>
|
||||
public async Task InvokeAsync(HttpContext context, IDomainEventPublisher domainEventPublisher, LuminaDbContext dbContext, IDomainEventsQueue domainEventQueue)
|
||||
{
|
||||
// Endpoints that serve long lived responses (for example a track stream) opt out through endpoint metadata, so that their response never
|
||||
// holds the request's database transaction open; the opt out is metadata based, so it follows the endpoint even when its route changes.
|
||||
if (context.GetEndpoint()?.Metadata.GetMetadata<SkipEventualConsistencyMetadata>() is not null)
|
||||
{
|
||||
await _next(context).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// begin a new database transaction - this will wrap any database operations performed during this HTTP request in an atomic operation
|
||||
IDbContextTransaction transaction = await dbContext.Database.BeginTransactionAsync(context.RequestAborted).ConfigureAwait(false);
|
||||
// register an action to be executed once the response is completed (the user already received a response for the request)
|
||||
|
||||
+1
@@ -14,5 +14,6 @@ public static partial class ApiRoutes
|
||||
public const string GET_TRACK_BY_ID = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}";
|
||||
public const string UPDATE_TRACK = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}";
|
||||
public const string DELETE_TRACK = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}";
|
||||
public const string STREAM_TRACK = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/stream";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user