Adds seekable normalized audio track delivery

This commit is contained in:
BinaryAlley committed 2026-10-18 14:55:56 +03:00
1 parent 4e13b23f16
commit 45f9aa3bd5
57 files changed
+3452 -344

No files matched your search

@@ -45,16 +45,20 @@ public abstract class BaseEndpoint<TRequest, TResponse> : Endpoint<TRequest, TRe
protected IResult Problem(Error error)
{
Dictionary<string, object?> extensionsDictionary = [];
int statusCode = error.Type switch
{
ErrorType.Validation => StatusCodes.Status400BadRequest,
ErrorType.Unauthorized => StatusCodes.Status403Forbidden, // DO NOT return Status401Unauthorized, that actually means lack of valid authentication credentials (not logged in)
ErrorType.Failure => StatusCodes.Status403Forbidden,
ErrorType.Forbidden => StatusCodes.Status403Forbidden,
ErrorType.NotFound => StatusCodes.Status404NotFound,
ErrorType.Conflict => StatusCodes.Status409Conflict,
_ => StatusCodes.Status500InternalServerError,
};
// A resource that is temporarily unavailable is a transient condition of the server, not an unexpected failure, so it is reported as
// unavailable rather than as an internal error. A client can retry it, and the playback player does.
int statusCode = error is ResourceUnavailableError
? StatusCodes.Status503ServiceUnavailable
: error.Type switch
{
ErrorType.Validation => StatusCodes.Status400BadRequest,
ErrorType.Unauthorized => StatusCodes.Status403Forbidden, // DO NOT return Status401Unauthorized, that actually means lack of valid authentication credentials (not logged in)
ErrorType.Failure => StatusCodes.Status403Forbidden,
ErrorType.Forbidden => StatusCodes.Status403Forbidden,
ErrorType.NotFound => StatusCodes.Status404NotFound,
ErrorType.Conflict => StatusCodes.Status409Conflict,
_ => StatusCodes.Status500InternalServerError,
};
extensionsDictionary["traceId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
@@ -79,15 +83,11 @@ public abstract class BaseEndpoint<TRequest, TResponse> : Endpoint<TRequest, TRe
// populate the errors dictionary with error codes and their descriptions
foreach (Error error in errors)
{
if (!errorsDictionary.TryGetValue(error.Code, out string[]? value))
errorsDictionary.Add(error.Code, [error.Description]);
else
{
if (!errorsDictionary[error.Code].Contains(error.Description))
errorsDictionary[error.Code] = [.. value, error.Description];
}
}
// add trace identifier to the extensions dictionary for tracing purposes
extensionsDictionary["traceId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
@@ -0,0 +1,48 @@
#region ========================================================================= USING =====================================================================================
using Microsoft.AspNetCore.Http;
using System;
using System.IO;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Common;
/// <summary>
/// A response result that writes an owned stream to the response without buffering it and releases the stream once the response is complete.
/// </summary>
/// <remarks>
/// The result owns the stream, so a lease protected resource that is served through it is always released, including when the client disconnects
/// before the whole content was written. Unlike a result built from bytes, it never materializes the content in memory.
/// </remarks>
public sealed class DisposingStreamResult : IResult
{
private readonly Stream _content;
private readonly string _contentType;
private readonly long? _contentLength;
/// <summary>
/// Initializes a new instance of the <see cref="DisposingStreamResult"/> class.
/// </summary>
/// <param name="content">The stream to write, which this result owns and releases after the response is complete.</param>
/// <param name="contentType">The media type of the content.</param>
/// <param name="contentLength">The length of the content, in bytes, or <see langword="null"/> when it is not known in advance.</param>
public DisposingStreamResult(Stream content, string contentType, long? contentLength)
{
_content = content;
_contentType = contentType;
_contentLength = contentLength;
}
/// <summary>
/// Writes the content stream to the response.
/// </summary>
/// <param name="httpContext">The HTTP context of the request being answered.</param>
public async Task ExecuteAsync(HttpContext httpContext)
{
if (_contentLength.HasValue)
httpContext.Response.ContentLength = _contentLength.Value;
httpContext.Response.ContentType = _contentType;
await using (_content)
await _content.CopyToAsync(httpContext.Response.Body, httpContext.RequestAborted).ConfigureAwait(false);
}
}