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:
BinaryAlley committed 2026-10-13 22:18:36 +03:00
1 parent 0ad6e1307b
commit 4ffa81fffe
18 files changed
+985

No files matched your search

@@ -0,0 +1,61 @@
#region ========================================================================= USING =====================================================================================
using System;
#endregion
namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
/// <summary>
/// Data transfer object for a track, containing the data needed to stream, or to describe the streaming of, its audio file.
/// </summary>
public sealed record TrackStreamDto
{
/// <summary>
/// Gets the file system path of the track.
/// </summary>
public required string Path { get; init; }
/// <summary>
/// Gets the Id of the media library the track belongs to.
/// </summary>
public required Guid LibraryId { get; init; }
/// <summary>
/// Gets the Id of the album the track belongs to.
/// </summary>
public required Guid AlbumId { get; init; }
/// <summary>
/// Gets the Id of the artist that owns the album the track belongs to.
/// </summary>
public required Guid ArtistId { get; init; }
/// <summary>
/// Gets the audio codec used by the audio file of the track, if applicable.
/// </summary>
public string? AudioCodec { get; init; }
/// <summary>
/// Gets the duration of the audio of the track in seconds.
/// </summary>
public int DurationInSeconds { get; init; }
/// <summary>
/// Gets the sample rate of the audio of the track in Hz.
/// </summary>
public int SampleRate { get; init; }
/// <summary>
/// Gets the number of audio channels of the track.
/// </summary>
public int Channels { get; init; }
/// <summary>
/// Gets the bit depth of the audio of the track, if applicable.
/// </summary>
public int? BitDepth { get; init; }
/// <summary>
/// Gets the bitrate of the audio of the track in kbps, if applicable.
/// </summary>
public int? Bitrate { get; init; }
}
@@ -58,6 +58,22 @@ public interface ITrackRepository : IRepository<TrackEntity>,
/// <returns>An <see cref="Result{TValue}"/> containing either the <see cref="TrackEntity"/> stored at the provided path, or an error.</returns>
Task<Result<TrackEntity?>> GetByPathAsync(Guid libraryId, string path, CancellationToken cancellationToken);
/// <summary>
/// Gets the data needed to stream the audio file of the track identified by <paramref name="trackId"/>, when it belongs to the album identified by
/// <paramref name="albumId"/> and to the media library identified by <paramref name="libraryId"/>, and that album belongs to the artist identified by
/// <paramref name="artistId"/>.
/// </summary>
/// <param name="libraryId">The Id of the media library the track must belong to.</param>
/// <param name="albumId">The Id of the album the track must belong to.</param>
/// <param name="artistId">The Id of the artist that must own the album the track belongs to.</param>
/// <param name="trackId">The Id of the track whose streaming data is retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either the <see cref="TrackStreamDto"/> of the track, <see langword="null"/> when no track matches the
/// provided identifiers, or an error.
/// </returns>
Task<Result<TrackStreamDto?>> GetTrackStreamInfoAsync(Guid libraryId, Guid albumId, Guid artistId, Guid trackId, CancellationToken cancellationToken);
/// <summary>
/// Resets the enrichment state of the tracks stored at the provided <paramref name="paths"/> in the media library identified by
/// <paramref name="libraryId"/>, together with their albums and artists, so that they are re-enriched, because their content changed since the last scan.