mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 19:11:10 +00:00
Renames project paths from Lumina to Nemera
This commit is contained in:
1 parent
ce6fddb4c9
commit
0f659a4877
6450 files changed
No files matched your search
@@ -0,0 +1,358 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.Exceptions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Api;
|
||||
|
||||
/// <summary>
|
||||
/// Typed client for API access.
|
||||
/// </summary>
|
||||
public class ApiHttpClient : IApiHttpClient
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly HttpContext? _httpContext;
|
||||
private readonly JsonSerializerOptions _jsonOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiHttpClient"/> class.
|
||||
/// </summary>
|
||||
/// <param name="httpClient">Injected HttpClient for interacting with the API.</param>
|
||||
/// <param name="httpContextAccessor">Injected service for providing the current HTTP context.</param>
|
||||
/// <param name="serverConfigurationOptions">Injected server configuration application settings.</param>
|
||||
public ApiHttpClient(HttpClient httpClient, IHttpContextAccessor httpContextAccessor, IOptionsSnapshot<ServerConfigurationDto> serverConfigurationOptions)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_httpContext = httpContextAccessor.HttpContext;
|
||||
// Read the API server configuration values from the configuration, and assign them to the injected client.
|
||||
ServerConfigurationDto serverConfiguration = serverConfigurationOptions.Value;
|
||||
httpClient.BaseAddress = new Uri($"{serverConfiguration.BaseAddress}:{serverConfiguration.Port}/api/v{serverConfiguration.ApiVersion}/");
|
||||
|
||||
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
_jsonOptions = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
Converters = { new JsonStringEnumConverter() }
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the GET request.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
public async Task<TResponse> GetAsync<TResponse>(string endpoint, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = CreateRequest(HttpMethod.Get, endpoint);
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result as a streamable response.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="IAsyncEnumerable{T}"/> object, which allows for asynchronous iteration over the deserialized items.</returns>
|
||||
public async IAsyncEnumerable<TResponse?> GetAsyncEnumerable<TResponse>(string endpoint, [EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = CreateRequest(HttpMethod.Get, endpoint);
|
||||
// Send the request and expect only headers initially - this prevents the client from buffering the entire response.
|
||||
using HttpResponseMessage response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
await using Stream stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
// Deserialize the JSON content asynchronously as an enumerable of TResponse items.
|
||||
await foreach (TResponse? item in JsonSerializer.DeserializeAsyncEnumerable<TResponse>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
yield break;
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>A model containing the raw blob bytes and their content type.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
public async Task<BlobDataDto> GetBlobAsync(string endpoint, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = CreateRequest(HttpMethod.Get, endpoint);
|
||||
using HttpResponseMessage response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
string content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||
throw CreateApiException(content, response, request);
|
||||
}
|
||||
// If the response is successful, read it as a byte array.
|
||||
byte[] responseContent = await response.Content.ReadAsByteArrayAsync(cancellationToken).ConfigureAwait(false);
|
||||
string contentType = response.Content.Headers.ContentType?.ToString() ?? "application/octet-stream";
|
||||
return new BlobDataDto { Data = responseContent, ContentType = contentType };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a DELETE request to the specified <paramref name="endpoint"/> as an asynchronous operation, discarding the response content.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
public async Task DeleteAsync(string endpoint, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = CreateRequest(HttpMethod.Delete, endpoint);
|
||||
await SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a PUT request to the specified <paramref name="endpoint"/> as an asynchronous operation, discarding the response content.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and sent to the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
public async Task PutIgnoringResponseAsync<TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = CreateRequestWithPayload(HttpMethod.Put, endpoint, data);
|
||||
await SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a PUT request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and sent to the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the PUT request.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
public async Task<TResponse> PutAsync<TResponse, TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = CreateRequestWithPayload(HttpMethod.Put, endpoint, data);
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a PUT request with a multipart form containing a single file to the specified <paramref name="endpoint"/> as an asynchronous operation, and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="fileStream">The stream of the file to upload, or <see langword="null"/> to send a multipart form without any file.</param>
|
||||
/// <param name="fileName">The name of the file to upload, or <see langword="null"/> when no file is sent.</param>
|
||||
/// <param name="fieldName">The name of the form field carrying the file.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the PUT request.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
public async Task<TResponse> PutMultipartAsync<TResponse>(string endpoint, Stream? fileStream, string? fileName, string fieldName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using MultipartFormDataContent form = [];
|
||||
if (fileStream is not null)
|
||||
{
|
||||
// The file is streamed as a generic binary part, since the exact content type of the uploaded file is not known.
|
||||
StreamContent fileContent = new(fileStream);
|
||||
fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
|
||||
form.Add(fileContent, fieldName, fileName ?? string.Empty);
|
||||
}
|
||||
|
||||
using HttpRequestMessage request = CreateRequest(HttpMethod.Put, endpoint);
|
||||
request.Content = form;
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request with a multipart form containing a single file to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="fileStream">The stream of the file to upload.</param>
|
||||
/// <param name="fileName">The name of the file to upload.</param>
|
||||
/// <param name="fieldName">The name of the form field carrying the file.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the POST request.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
public async Task<TResponse> PostMultipartAsync<TResponse>(string endpoint, Stream fileStream, string fileName, string fieldName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// The file is streamed as a generic binary part, since the exact content type of the uploaded file is not known.
|
||||
using MultipartFormDataContent form = [];
|
||||
using StreamContent fileContent = new(fileStream);
|
||||
fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
|
||||
form.Add(fileContent, fieldName, fileName);
|
||||
|
||||
using HttpRequestMessage request = CreateRequest(HttpMethod.Post, endpoint);
|
||||
request.Content = form;
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request without a payload to the specified <paramref name="endpoint"/> as an asynchronous operation, discarding the response content.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
public async Task PostIgnoringResponseAsync(string endpoint, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = CreateRequest(HttpMethod.Post, endpoint);
|
||||
await SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request without a payload to the specified <paramref name="endpoint"/> as an asynchronous operation, and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the POST request.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
public async Task<TResponse> PostAsync<TResponse>(string endpoint, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = CreateRequest(HttpMethod.Post, endpoint);
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request to the specified <paramref name="endpoint"/> as an asynchronous operation, discarding the response content.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and sent to the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
public async Task PostIgnoringResponseAsync<TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = CreateRequestWithPayload(HttpMethod.Post, endpoint, data);
|
||||
await SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and sent to the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the POST request.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
public async Task<TResponse> PostAsync<TResponse, TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using HttpRequestMessage request = CreateRequestWithPayload(HttpMethod.Post, endpoint, data);
|
||||
return await SendRequestAsync<TResponse>(request, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an HTTP request for the specified <paramref name="method"/> and <paramref name="endpoint"/>.
|
||||
/// </summary>
|
||||
/// <param name="method">The HTTP method of the request.</param>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <returns>The created <see cref="HttpRequestMessage"/>.</returns>
|
||||
private HttpRequestMessage CreateRequest(HttpMethod method, string endpoint)
|
||||
{
|
||||
HttpRequestMessage request = new(method, endpoint);
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
return request;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an HTTP request for the specified <paramref name="method"/> and <paramref name="endpoint"/>, with the serialized <paramref name="data"/> as its JSON payload.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="method">The HTTP method of the request.</param>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and sent to the API.</param>
|
||||
/// <returns>The created <see cref="HttpRequestMessage"/>.</returns>
|
||||
private HttpRequestMessage CreateRequestWithPayload<TModel>(HttpMethod method, string endpoint, TModel data)
|
||||
{
|
||||
HttpRequestMessage request = CreateRequest(method, endpoint);
|
||||
request.Content = new StringContent(JsonSerializer.Serialize(data, _jsonOptions), Encoding.UTF8, "application/json");
|
||||
return request;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an HTTP request and reads the response content.
|
||||
/// If the request fails, it attempts to deserialize the response content into a <see cref="ProblemDetailsDto"/> and throws an <see cref="ApiException"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The <see cref="HttpRequestMessage"/> to be sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The raw response content.</returns>
|
||||
/// <exception cref="ApiException">Thrown if the response is not successful, with the <see cref="ProblemDetailsDto"/> if available.</exception>
|
||||
private async Task<string> SendRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
using HttpResponseMessage response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
string content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (response.IsSuccessStatusCode)
|
||||
return content;
|
||||
throw CreateApiException(content, response, request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an HTTP request and deserializes the response into the specified type if the request is successful.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="request">The <see cref="HttpRequestMessage"/> to be sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response content as an object of type <typeparamref name="TResponse"/>.</returns>
|
||||
/// <exception cref="ApiException">Thrown if the response is not successful, with the <see cref="ProblemDetailsDto"/> if available.</exception>
|
||||
private async Task<TResponse> SendRequestAsync<TResponse>(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
string content = await SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
// Handle empty content case.
|
||||
if (string.IsNullOrEmpty(content))
|
||||
return default!;
|
||||
return JsonSerializer.Deserialize<TResponse>(content, _jsonOptions)!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the exception thrown when an API request fails.
|
||||
/// </summary>
|
||||
/// <param name="content">The raw response content.</param>
|
||||
/// <param name="response">The failed HTTP response.</param>
|
||||
/// <param name="request">The HTTP request that failed.</param>
|
||||
/// <returns>The created <see cref="ApiException"/>.</returns>
|
||||
private ApiException CreateApiException(string content, HttpResponseMessage response, HttpRequestMessage request)
|
||||
{
|
||||
ProblemDetailsDto? problemDetails = null;
|
||||
// Attempt to deserialize the response content to ProblemDetailsDto if the request fails.
|
||||
try
|
||||
{
|
||||
problemDetails = JsonSerializer.Deserialize<ProblemDetailsDto>(content, _jsonOptions);
|
||||
}
|
||||
catch { /* If we can't deserialize to ProblemDetails, we'll just use the status code. */ }
|
||||
return new ApiException(problemDetails, response.StatusCode, request.RequestUri?.AbsolutePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the authentication header for the current user, if available.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An <see cref="AuthenticationHeaderValue"/> with a Bearer token if the user's token is found, <see langword="null"/> otherwise.
|
||||
/// </returns>
|
||||
private AuthenticationHeaderValue? GetAuthenticationHeader()
|
||||
{
|
||||
string? token = _httpContext?.User?.FindFirst("Token")?.Value;
|
||||
return !string.IsNullOrEmpty(token) ? new AuthenticationHeaderValue("Bearer", token) : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Api;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the streamed response of a remote API request. It exposes the status code, the range related headers and the
|
||||
/// content stream of the response, so that a caller can forward the response to a client without ever buffering its content.
|
||||
/// </summary>
|
||||
public sealed class ApiStreamResult : IAsyncDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// The response header that carries the number of segments of a normalized audio production. It must match the name the API sends.
|
||||
/// </summary>
|
||||
public const string SEGMENT_COUNT_HEADER_NAME = "X-Lumina-Segment-Count";
|
||||
|
||||
/// <summary>
|
||||
/// The response header that carries the exact start of a segment on the track timeline, in seconds. It must match the name the API sends.
|
||||
/// </summary>
|
||||
public const string SEGMENT_START_SECONDS_HEADER_NAME = "X-Segment-Start-Seconds";
|
||||
|
||||
/// <summary>
|
||||
/// The response header that carries the produced duration of the normalized track, in seconds. It must match the name the API sends.
|
||||
/// </summary>
|
||||
public const string TRACK_DURATION_SECONDS_HEADER_NAME = "X-Lumina-Track-Duration-Seconds";
|
||||
|
||||
private readonly HttpResponseMessage _response;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the status code of the response.
|
||||
/// </summary>
|
||||
public HttpStatusCode StatusCode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content stream of the response.
|
||||
/// </summary>
|
||||
public Stream Content { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media type of the content of the response, or <see langword="null"/> when the response declares none.
|
||||
/// </summary>
|
||||
public string? ContentType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the length of the content of the response, or <see langword="null"/> when the response declares none.
|
||||
/// </summary>
|
||||
public long? ContentLength { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the range of the content of the response, when the response is a partial content response.
|
||||
/// </summary>
|
||||
public string? ContentRange { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ranges the remote API accepts, when the response declares them.
|
||||
/// </summary>
|
||||
public string? AcceptRanges { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the entity tag of the content of the response, when the response declares one.
|
||||
/// </summary>
|
||||
public string? ETag { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time the content of the response was last modified, when the response declares it.
|
||||
/// </summary>
|
||||
public DateTimeOffset? LastModified { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the caching instructions of the response, when the response declares them.
|
||||
/// </summary>
|
||||
public string? CacheControl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of segments the normalized audio production holds, when the response is a segment of one and declares it.
|
||||
/// </summary>
|
||||
public int? SegmentCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the exact start of the segment on the track timeline, in seconds, as declared by the API, or <see langword="null"/> when the response
|
||||
/// declares none.
|
||||
/// </summary>
|
||||
public string? SegmentStartSeconds { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the produced duration of the normalized track, in seconds, as declared by the API, or <see langword="null"/> when the response declares none.
|
||||
/// </summary>
|
||||
public int? TrackDurationSeconds { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiStreamResult"/> class.
|
||||
/// </summary>
|
||||
/// <param name="response">The response returned by the remote API.</param>
|
||||
/// <param name="content">The content stream of the response.</param>
|
||||
private ApiStreamResult(HttpResponseMessage response, Stream content)
|
||||
{
|
||||
_response = response;
|
||||
Content = content;
|
||||
StatusCode = response.StatusCode;
|
||||
ContentType = response.Content.Headers.ContentType?.ToString();
|
||||
ContentLength = response.Content.Headers.ContentLength;
|
||||
ContentRange = response.Content.Headers.ContentRange?.ToString();
|
||||
AcceptRanges = response.Headers.AcceptRanges.Count > 0 ? string.Join(", ", response.Headers.AcceptRanges) : null;
|
||||
ETag = response.Headers.ETag?.ToString();
|
||||
LastModified = response.Content.Headers.LastModified;
|
||||
CacheControl = response.Headers.CacheControl?.ToString();
|
||||
// The count is optional, because the same result also represents a track stream, which has no segments. A malformed or negative
|
||||
// value is treated as absent instead of being passed to a caller that would use it to decide where the audio ends.
|
||||
SegmentCount = response.Headers.TryGetValues(SEGMENT_COUNT_HEADER_NAME, out IEnumerable<string>? segmentCountValues)
|
||||
&& int.TryParse(segmentCountValues.FirstOrDefault(), NumberStyles.None, CultureInfo.InvariantCulture, out int parsedSegmentCount)
|
||||
&& parsedSegmentCount >= 0
|
||||
? parsedSegmentCount
|
||||
: null;
|
||||
// The start is forwarded as the API wrote it, so the web hop never reinterprets a decimal with the culture of this application.
|
||||
SegmentStartSeconds = response.Headers.TryGetValues(SEGMENT_START_SECONDS_HEADER_NAME, out IEnumerable<string>? segmentStartValues)
|
||||
? segmentStartValues.FirstOrDefault()
|
||||
: null;
|
||||
TrackDurationSeconds = response.Headers.TryGetValues(TRACK_DURATION_SECONDS_HEADER_NAME, out IEnumerable<string>? trackDurationValues)
|
||||
&& int.TryParse(trackDurationValues.FirstOrDefault(), NumberStyles.None, CultureInfo.InvariantCulture, out int parsedTrackDuration)
|
||||
&& parsedTrackDuration > 0
|
||||
? parsedTrackDuration
|
||||
: null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="ApiStreamResult"/> from a response, without buffering the content of the response.
|
||||
/// </summary>
|
||||
/// <param name="response">The response returned by the remote API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The streamed response.</returns>
|
||||
public static async Task<ApiStreamResult> CreateAsync(HttpResponseMessage response, CancellationToken cancellationToken)
|
||||
{
|
||||
Stream content = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
return new ApiStreamResult(response, content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the content stream and the response it belongs to.
|
||||
/// </summary>
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await Content.DisposeAsync().ConfigureAwait(false);
|
||||
_response.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.Exceptions;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Api;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for typed clients for API access.
|
||||
/// </summary>
|
||||
public interface IApiHttpClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the GET request.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
Task<TResponse> GetAsync<TResponse>(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result as a streamable response.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="IAsyncEnumerable{T}"/> object, which allows for asynchronous iteration over the deserialized items.</returns>
|
||||
IAsyncEnumerable<TResponse?> GetAsyncEnumerable<TResponse>(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>A model containing the raw blob bytes and their content type.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
Task<BlobDataDto> GetBlobAsync(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a DELETE request to the specified <paramref name="endpoint"/> as an asynchronous operation, discarding the response content.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
Task DeleteAsync(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a PUT request to the specified <paramref name="endpoint"/> as an asynchronous operation, discarding the response content.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and sent to the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
Task PutIgnoringResponseAsync<TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a PUT request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and sent to the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the PUT request.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
Task<TResponse> PutAsync<TResponse, TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a PUT request with a multipart form containing a single file to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="fileStream">The stream of the file to upload, or <see langword="null"/> to send a multipart form without any file.</param>
|
||||
/// <param name="fileName">The name of the file to upload, or <see langword="null"/> when no file is sent.</param>
|
||||
/// <param name="fieldName">The name of the form field carrying the file.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the PUT request.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
Task<TResponse> PutMultipartAsync<TResponse>(string endpoint, Stream? fileStream, string? fileName, string fieldName, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request with a multipart form containing a single file to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="fileStream">The stream of the file to upload.</param>
|
||||
/// <param name="fileName">The name of the file to upload.</param>
|
||||
/// <param name="fieldName">The name of the form field carrying the file.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the POST request.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
Task<TResponse> PostMultipartAsync<TResponse>(string endpoint, Stream fileStream, string fileName, string fieldName, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request without a payload to the specified <paramref name="endpoint"/> as an asynchronous operation, discarding the response content.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
Task PostIgnoringResponseAsync(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request without a payload to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the POST request.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
Task<TResponse> PostAsync<TResponse>(string endpoint, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request to the specified <paramref name="endpoint"/> as an asynchronous operation, discarding the response content.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and sent to the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
Task PostIgnoringResponseAsync<TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse">The expected type of the response content.</typeparam>
|
||||
/// <typeparam name="TModel">The expected type of the payload content.</typeparam>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="data">The data to be serialized and sent to the API.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The deserialized response containing the result of the POST request.</returns>
|
||||
/// <exception cref="ApiException">Thrown when the API returns an unsuccessful response.</exception>
|
||||
Task<TResponse> PostAsync<TResponse, TModel>(string endpoint, TModel data, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Api;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for typed clients that stream responses from the remote API without buffering their content.
|
||||
/// </summary>
|
||||
public interface IStreamingApiHttpClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the response as a stream, without ever buffering its content in memory.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="requestHeaders">The range and conditional headers of the incoming request to forward, so that the API,
|
||||
/// which is the only party that knows the entity tag and the modification time of the resource, validates them itself.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The streamed response of the API request, which the caller must dispose once it has finished copying it.</returns>
|
||||
Task<ApiStreamResult> GetStreamAsync(string endpoint, IReadOnlyDictionary<string, string> requestHeaders, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.Common.Exceptions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Api;
|
||||
|
||||
/// <summary>
|
||||
/// Typed client for streaming API access. Unlike <see cref="ApiHttpClient"/>, it never buffers a response in memory and is
|
||||
/// intentionally free of any retry or circuit breaker policy, because a stream is meant to be handed to the client as a whole.
|
||||
/// </summary>
|
||||
public class StreamingApiHttpClient : IStreamingApiHttpClient
|
||||
{
|
||||
private static readonly JsonSerializerOptions s_jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
Converters = { new JsonStringEnumConverter() }
|
||||
};
|
||||
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly HttpContext? _httpContext;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StreamingApiHttpClient"/> class.
|
||||
/// </summary>
|
||||
/// <param name="httpClient">Injected HttpClient for interacting with the API.</param>
|
||||
/// <param name="httpContextAccessor">Injected service for providing the current HTTP context.</param>
|
||||
/// <param name="serverConfigurationOptions">Injected server configuration application settings.</param>
|
||||
public StreamingApiHttpClient(HttpClient httpClient, IHttpContextAccessor httpContextAccessor, IOptionsSnapshot<ServerConfigurationDto> serverConfigurationOptions)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_httpContext = httpContextAccessor.HttpContext;
|
||||
// Read the API server configuration values from the configuration, and assign them to the injected client.
|
||||
ServerConfigurationDto serverConfiguration = serverConfigurationOptions.Value;
|
||||
httpClient.BaseAddress = new Uri($"{serverConfiguration.BaseAddress}:{serverConfiguration.Port}/api/v{serverConfiguration.ApiVersion}/");
|
||||
// A streamed response stays open for as long as the client keeps reading it, so the timeout is generously large, but it is bounded:
|
||||
// an upstream that accepts the request and never answers must not hold a connection and a stream permit open forever. No track, and
|
||||
// no movie, is longer than this.
|
||||
httpClient.Timeout = TimeSpan.FromHours(12);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a GET request to the specified <paramref name="endpoint"/> as an asynchronous operation and returns the response
|
||||
/// as a stream, without ever buffering its content in memory.
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The API endpoint where the request is being sent.</param>
|
||||
/// <param name="requestHeaders">The range and conditional headers of the incoming request to forward, so that the API, which is the only party that knows the entity tag and the modification time of the resource, validates them itself.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The streamed response of the API request, which the caller must dispose once it has finished copying it.</returns>
|
||||
/// <exception cref="ApiException">Thrown if the response is not successful, with the <see cref="ProblemDetailsDto"/> if available.</exception>
|
||||
public async Task<ApiStreamResult> GetStreamAsync(string endpoint, IReadOnlyDictionary<string, string> requestHeaders, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using (HttpRequestMessage request = new(HttpMethod.Get, endpoint))
|
||||
{
|
||||
AuthenticationHeaderValue? authenticationHeader = GetAuthenticationHeader();
|
||||
if (authenticationHeader is not null)
|
||||
request.Headers.Authorization = authenticationHeader;
|
||||
// The range and the conditional headers are forwarded as they are, so that the API, and never this client, decides what a partial response contains.
|
||||
foreach (KeyValuePair<string, string> header in requestHeaders)
|
||||
request.Headers.TryAddWithoutValidation(header.Key, header.Value);
|
||||
|
||||
// Only the headers of the response are awaited, so that its content is streamed to the client instead of being copied into memory first.
|
||||
HttpResponseMessage response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
|
||||
// A not modified response and a range not satisfiable response are valid outcomes of a conditional or ranged request, and their
|
||||
// headers (the entity tag, the last modified date, the content range) are the whole answer, so they are passed through instead of
|
||||
// being turned into an error, which would drop the very headers the caller needs to revalidate or recover.
|
||||
if (!response.IsSuccessStatusCode && response.StatusCode != HttpStatusCode.NotModified && response.StatusCode != HttpStatusCode.RequestedRangeNotSatisfiable)
|
||||
{
|
||||
HttpStatusCode statusCode = response.StatusCode;
|
||||
string content;
|
||||
try
|
||||
{
|
||||
content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// The response is turned into an exception, so it is disposed even when reading its error body fails, otherwise its connection would leak.
|
||||
response.Dispose();
|
||||
}
|
||||
ProblemDetailsDto? problemDetails = null;
|
||||
try
|
||||
{
|
||||
problemDetails = JsonSerializer.Deserialize<ProblemDetailsDto>(content, s_jsonOptions);
|
||||
}
|
||||
catch { /* If we can't deserialize to ProblemDetails, we'll just use the status code. */ }
|
||||
throw new ApiException(problemDetails, statusCode, request.RequestUri?.AbsolutePath);
|
||||
}
|
||||
try
|
||||
{
|
||||
return await ApiStreamResult.CreateAsync(response, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// The response was already received, so it must be disposed if its content stream could not be obtained, otherwise its connection would leak.
|
||||
response.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the authentication header for the current user, if available.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An <see cref="AuthenticationHeaderValue"/> with a Bearer token if the user's token is found, <see langword="null"/> otherwise.
|
||||
/// </returns>
|
||||
private AuthenticationHeaderValue? GetAuthenticationHeader()
|
||||
{
|
||||
string? token = _httpContext?.User?.FindFirst("Token")?.Value;
|
||||
return !string.IsNullOrEmpty(token) ? new AuthenticationHeaderValue("Bearer", token) : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Contains the names of the authorization policies defined in the Web application.
|
||||
/// </summary>
|
||||
public static class AuthorizationPolicies
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the authorization policy that requires the administrator role.
|
||||
/// </summary>
|
||||
public const string REQUIRE_ADMIN_ROLE = "RequireAdminRole";
|
||||
|
||||
/// <summary>
|
||||
/// The name of the authorization policy that requires the permission to create media libraries.
|
||||
/// </summary>
|
||||
public const string REQUIRE_CREATE_LIBRARIES_PERMISSION = "RequireCreateLibrariesPermission";
|
||||
|
||||
/// <summary>
|
||||
/// The name of the authorization policy that requires the application to be initialized.
|
||||
/// </summary>
|
||||
public const string REQUIRE_INITIALIZATION = "RequireInitialization";
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Enums.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Exceptions;
|
||||
using Lumina.Presentation.Web.Common.Http;
|
||||
using Lumina.Presentation.Web.Common.Responses.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Polly.CircuitBreaker;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Security.Claims;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Implements authorization logic for API endpoints by validating user roles, permissions, and policies.
|
||||
/// </summary>
|
||||
public class AuthorizationService : IAuthorizationService
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AuthorizationService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected HTTP typed client for interactions with the API.</param>
|
||||
/// <param name="httpContextAccessor">The <see cref="IHttpContextAccessor"/> used to access the current HTTP context.</param>
|
||||
public AuthorizationService(IApiHttpClient apiHttpClient, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the currently logged in user has a specific permission.
|
||||
/// </summary>
|
||||
/// <param name="permission">The permission to check.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns><see langword="true"/> if the currently logged in user has the specified permission, <see langword="false"/> otherwise.</returns>
|
||||
public async Task<bool> HasPermissionAsync(AuthorizationPermission permission, CancellationToken cancellationToken)
|
||||
{
|
||||
GetAuthorizationResponse authorization = await GetUserAuthorizationAsync(cancellationToken).ConfigureAwait(false);
|
||||
return authorization.Permissions.Contains(permission);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the currently logged in user belongs to a specific role.
|
||||
/// </summary>
|
||||
/// <param name="role">The role to check.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns><see langword="true"/> if the currently logged in user is in the specified role, <see langword="false"/> otherwise.</returns>
|
||||
public async Task<bool> IsInRoleAsync(string role, CancellationToken cancellationToken)
|
||||
{
|
||||
GetAuthorizationResponse authorization = await GetUserAuthorizationAsync(cancellationToken).ConfigureAwait(false);
|
||||
return authorization.Role == role;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves user authorization details from the authorization service.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The user's authorization details.</returns>
|
||||
private async Task<GetAuthorizationResponse> GetUserAuthorizationAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
// Anonymous users and users without an identifier claim have no role or permissions, so deny without querying the API.
|
||||
string? userId = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
return new GetAuthorizationResponse(Guid.Empty, string.Empty, []);
|
||||
try
|
||||
{
|
||||
return await _apiHttpClient.GetAsync<GetAuthorizationResponse>($"auth/get-authorization?userId={Uri.EscapeDataString(userId)}", cancellationToken);
|
||||
}
|
||||
catch (ApiException exception) when (exception.HttpStatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
// This is the only place that knows the request was the current-user authorization check. Convert a 404 here into an explicit exception, so the middleware can
|
||||
// invalidate the stale session without guessing from the request path. Do not move this classification into the middleware: it only sees a generic ApiException,
|
||||
// and a caller-controlled path can contain the authorization route text.
|
||||
throw new CurrentUserAuthorizationException(exception.ProblemDetails, exception.HttpStatusCode, exception.RequestPath);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
HttpContext? httpContext = _httpContextAccessor.HttpContext;
|
||||
if (httpContext is null || httpContext.RequestAborted.IsCancellationRequested)
|
||||
throw;
|
||||
if (!IsApiOutage(exception))
|
||||
throw;
|
||||
bool isPageNavigation = (httpContext.Request.Headers.Accept.Count == 0 && httpContext.Request.Headers.Range.Count == 0)
|
||||
|| httpContext.Request.Headers.Accept.Any(accept => accept?.Contains("text/html", StringComparison.OrdinalIgnoreCase) == true)
|
||||
|| string.Equals(httpContext.Request.Headers["Sec-Fetch-Mode"].ToString(), "navigate", StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(httpContext.Request.Headers["Sec-Fetch-Dest"].ToString(), "document", StringComparison.OrdinalIgnoreCase);
|
||||
if (!isPageNavigation)
|
||||
throw;
|
||||
// The page is still rendered while the API is unreachable, with no role and no permissions, and the request is marked so
|
||||
// that the page reports the failure to the user. API requests keep propagating the failure as a JSON error.
|
||||
httpContext.Items[HttpContextItemKeys.SERVER_UNREACHABLE] = true;
|
||||
return new GetAuthorizationResponse(Guid.Empty, string.Empty, []);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the exception means that the API could not answer, as opposed to an authorization answer from the API.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception thrown by the API call.</param>
|
||||
/// <returns><see langword="true"/> for a connection, timeout, circuit breaker or server failure; otherwise <see langword="false"/>.</returns>
|
||||
private static bool IsApiOutage(Exception exception)
|
||||
{
|
||||
return exception is HttpRequestException or BrokenCircuitException or TaskCanceledException
|
||||
|| (exception is ApiException apiException && (int)apiException.HttpStatusCode >= 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Authorization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the service for managing authorization.
|
||||
/// </summary>
|
||||
public interface IAuthorizationService
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether the currently logged in user has a specific permission.
|
||||
/// </summary>
|
||||
/// <param name="permission">The permission to check.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns><see langword="true"/> if the currently logged in user has the specified permission, <see langword="false"/> otherwise.</returns>
|
||||
Task<bool> HasPermissionAsync(AuthorizationPermission permission, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the currently logged in user belongs to a specific role.
|
||||
/// </summary>
|
||||
/// <param name="role">The role to check.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns><see langword="true"/> if the currently logged in user is in the specified role, <see langword="false"/> otherwise.</returns>
|
||||
Task<bool> IsInRoleAsync(string role, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// FastEndpoints pre-processor that runs the application initialization check before the endpoint handler executes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The check runs the <c>RequireInitialization</c> authorization policy, which queries the remote API and records the pending super admin setup state in the session.
|
||||
/// Its result is deliberately ignored, because the pages that use this processor must be reachable both before and after the application is initialized.
|
||||
/// </remarks>
|
||||
/// <typeparam name="TRequest">The type of the request of the endpoint to which this pre-processor is applied.</typeparam>
|
||||
public class InitializationCheckPreProcessor<TRequest> : IPreProcessor<TRequest> where TRequest : notnull
|
||||
{
|
||||
/// <summary>
|
||||
/// Runs the initialization check for the current request.
|
||||
/// </summary>
|
||||
/// <param name="preProcessorContext">The pre-processor context for the current request.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public async Task PreProcessAsync(IPreProcessorContext<TRequest> preProcessorContext, CancellationToken cancellationToken)
|
||||
{
|
||||
HttpContext httpContext = preProcessorContext.HttpContext;
|
||||
Microsoft.AspNetCore.Authorization.IAuthorizationService authorizationService = httpContext.RequestServices.GetRequiredService<Microsoft.AspNetCore.Authorization.IAuthorizationService>();
|
||||
await authorizationService.AuthorizeAsync(httpContext.User, httpContext, AuthorizationPolicies.REQUIRE_INITIALIZATION).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Exceptions;
|
||||
using Lumina.Presentation.Web.Common.Http;
|
||||
using Lumina.Presentation.Web.Common.Responses.UsersManagement;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Polly.CircuitBreaker;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the <see cref="InitializationRequirement"/> to ensure that the application is initialized before allowing authorization.
|
||||
/// </summary>
|
||||
public class InitializationHandler : AuthorizationHandler<InitializationRequirement>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InitializationHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected HTTP typed client for interactions with the API.</param>
|
||||
public InitializationHandler(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks the application initialization status and authorizes the requirement if initialized.
|
||||
/// </summary>
|
||||
/// <param name="authorizationHandlerContext">The authorization context.</param>
|
||||
/// <param name="initializationRequirement">The initialization requirement to be evaluated.</param>
|
||||
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext authorizationHandlerContext, InitializationRequirement initializationRequirement)
|
||||
{
|
||||
try
|
||||
{
|
||||
InitializationResponse result = await _apiHttpClient.GetAsync<InitializationResponse>("initialization/").ConfigureAwait(false);
|
||||
HttpContext? httpContext = authorizationHandlerContext.Resource as HttpContext;
|
||||
if (result.IsInitialized)
|
||||
{
|
||||
// Admin account was registered, remove this requirement from the session.
|
||||
httpContext?.Session.Remove(HttpContextItemKeys.PENDING_SUPER_ADMIN_SETUP);
|
||||
authorizationHandlerContext.Succeed(initializationRequirement);
|
||||
}
|
||||
else // Store in session that super admin setup is needed.
|
||||
httpContext?.Session.SetString(HttpContextItemKeys.PENDING_SUPER_ADMIN_SETUP, "true");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
HttpContext? httpContext = GetPageNavigationDuringApiOutage(authorizationHandlerContext, exception);
|
||||
if (httpContext is null)
|
||||
throw;
|
||||
// The initialization state cannot be read while the API is unreachable, but the requested page is still rendered, and
|
||||
// the failure is reported to the user there. The data calls of the page keep failing on their own.
|
||||
httpContext.Items[HttpContextItemKeys.SERVER_UNREACHABLE] = true;
|
||||
authorizationHandlerContext.Succeed(initializationRequirement);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current HTTP context when the provided exception is an API outage on a page navigation, and <see langword="null"/> otherwise.
|
||||
/// </summary>
|
||||
/// <param name="authorizationHandlerContext">The authorization context whose resource holds the HTTP context.</param>
|
||||
/// <param name="exception">The exception thrown by the initialization check against the API.</param>
|
||||
/// <returns>The HTTP context of the page navigation, or <see langword="null"/> when the exception must propagate.</returns>
|
||||
private static HttpContext? GetPageNavigationDuringApiOutage(AuthorizationHandlerContext authorizationHandlerContext, Exception exception)
|
||||
{
|
||||
if (authorizationHandlerContext.Resource is not HttpContext httpContext)
|
||||
return null;
|
||||
if (httpContext.RequestAborted.IsCancellationRequested)
|
||||
return null;
|
||||
if (exception is not ApiException and not HttpRequestException and not BrokenCircuitException and not TaskCanceledException)
|
||||
return null;
|
||||
if (exception is ApiException apiException && (int)apiException.HttpStatusCode < 500)
|
||||
return null;
|
||||
bool isPageNavigation = (httpContext.Request.Headers.Accept.Count == 0 && httpContext.Request.Headers.Range.Count == 0)
|
||||
|| httpContext.Request.Headers.Accept.Any(accept => accept?.Contains("text/html", StringComparison.OrdinalIgnoreCase) == true)
|
||||
|| string.Equals(httpContext.Request.Headers["Sec-Fetch-Mode"].ToString(), "navigate", StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(httpContext.Request.Headers["Sec-Fetch-Dest"].ToString(), "document", StringComparison.OrdinalIgnoreCase);
|
||||
return isPageNavigation ? httpContext : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Defines a requirement for initialization status in the authorization process.
|
||||
/// </summary>
|
||||
public class InitializationRequirement : IAuthorizationRequirement
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the timeout duration, in minutes, for caching the initialization check.
|
||||
/// </summary>
|
||||
public int CacheTimeoutMinutes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="InitializationRequirement"/> class.
|
||||
/// </summary>
|
||||
/// <param name="cacheTimeoutMinutes">The cache timeout in minutes for the initialization status.</param>
|
||||
public InitializationRequirement(int cacheTimeoutMinutes = 5)
|
||||
{
|
||||
CacheTimeoutMinutes = cacheTimeoutMinutes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Http;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the <see cref="PermissionRequirement"/> by checking the currently logged in user's permissions against the remote API.
|
||||
/// </summary>
|
||||
public class PermissionAuthorizationHandler : AuthorizationHandler<PermissionRequirement>
|
||||
{
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PermissionAuthorizationHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="authorizationService">Injected service for authorization checks against the remote API.</param>
|
||||
/// <param name="httpContextAccessor">Injected accessor for the current HTTP context.</param>
|
||||
public PermissionAuthorizationHandler(IAuthorizationService authorizationService, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_authorizationService = authorizationService;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Succeeds the requirement when the currently logged in user is an administrator, or holds any of the required permissions.
|
||||
/// </summary>
|
||||
/// <param name="authorizationHandlerContext">The authorization context.</param>
|
||||
/// <param name="permissionRequirement">The permission requirement to evaluate.</param>
|
||||
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext authorizationHandlerContext, PermissionRequirement permissionRequirement)
|
||||
{
|
||||
// The API lets administrators do what the permission allows even when they do not hold it, so the Web does not deny them what the API grants.
|
||||
if (await _authorizationService.IsInRoleAsync("Admin", CancellationToken.None).ConfigureAwait(false))
|
||||
{
|
||||
authorizationHandlerContext.Succeed(permissionRequirement);
|
||||
return;
|
||||
}
|
||||
foreach (AuthorizationPermission permission in permissionRequirement.Permissions)
|
||||
{
|
||||
if (await _authorizationService.HasPermissionAsync(permission, CancellationToken.None).ConfigureAwait(false))
|
||||
{
|
||||
authorizationHandlerContext.Succeed(permissionRequirement);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// The authorization service marks a page navigation when the API could not answer. The page itself is still rendered, with
|
||||
// no permission granted, and it reports the failure to the user; the API remains the enforcement point for every data call.
|
||||
// Endpoint routing passes the Endpoint, not the HttpContext, as the authorization resource, so the current request is read
|
||||
// from the accessor instead. Only an authenticated user is allowed through, because the outage is not a reason to expose a
|
||||
// page to an anonymous visitor.
|
||||
HttpContext? httpContext = _httpContextAccessor.HttpContext;
|
||||
if (httpContext?.User.Identity?.IsAuthenticated == true && httpContext.Items[HttpContextItemKeys.SERVER_UNREACHABLE] is true)
|
||||
authorizationHandlerContext.Succeed(permissionRequirement);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Defines a requirement that the user must hold at least one of the specified permissions.
|
||||
/// </summary>
|
||||
public class PermissionRequirement : IAuthorizationRequirement
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the permissions that allow access, of which the user must hold at least one.
|
||||
/// </summary>
|
||||
public AuthorizationPermission[] Permissions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PermissionRequirement"/> class.
|
||||
/// </summary>
|
||||
/// <param name="permissions">The permissions that allow access.</param>
|
||||
public PermissionRequirement(params AuthorizationPermission[] permissions)
|
||||
{
|
||||
Permissions = permissions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Http;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the <see cref="RoleRequirement"/> by checking the currently logged in user's role against the remote API.
|
||||
/// </summary>
|
||||
public class RoleAuthorizationHandler : AuthorizationHandler<RoleRequirement>
|
||||
{
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RoleAuthorizationHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="authorizationService">Injected service for authorization checks against the remote API.</param>
|
||||
/// <param name="httpContextAccessor">Injected accessor for the current HTTP context.</param>
|
||||
public RoleAuthorizationHandler(IAuthorizationService authorizationService, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_authorizationService = authorizationService;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Succeeds the requirement when the currently logged in user belongs to any of the required roles.
|
||||
/// </summary>
|
||||
/// <param name="authorizationHandlerContext">The authorization context.</param>
|
||||
/// <param name="roleRequirement">The role requirement to evaluate.</param>
|
||||
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext authorizationHandlerContext, RoleRequirement roleRequirement)
|
||||
{
|
||||
foreach (string role in roleRequirement.Roles)
|
||||
{
|
||||
if (await _authorizationService.IsInRoleAsync(role, CancellationToken.None).ConfigureAwait(false))
|
||||
{
|
||||
authorizationHandlerContext.Succeed(roleRequirement);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// The authorization service marks a page navigation when the API could not answer. The page itself is still rendered, with
|
||||
// no role granted, and it reports the failure to the user; the API remains the enforcement point for every data call.
|
||||
// Endpoint routing passes the Endpoint, not the HttpContext, as the authorization resource, so the current request is read
|
||||
// from the accessor instead. Only an authenticated user is allowed through, because the outage is not a reason to expose a
|
||||
// page to an anonymous visitor.
|
||||
HttpContext? httpContext = _httpContextAccessor.HttpContext;
|
||||
if (httpContext?.User.Identity?.IsAuthenticated == true && httpContext.Items[HttpContextItemKeys.SERVER_UNREACHABLE] is true)
|
||||
authorizationHandlerContext.Succeed(roleRequirement);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Defines a requirement that the user must belong to at least one of the specified roles.
|
||||
/// </summary>
|
||||
public class RoleRequirement : IAuthorizationRequirement
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the roles that allow access, of which the user must belong to at least one.
|
||||
/// </summary>
|
||||
public string[] Roles { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RoleRequirement"/> class.
|
||||
/// </summary>
|
||||
/// <param name="roles">The roles that allow access.</param>
|
||||
public RoleRequirement(params string[] roles)
|
||||
{
|
||||
Roles = roles;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.Enums.AudioLibrary;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the rating of an audio media element.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Value: {Value}; MaxValue: {MaxValue}")]
|
||||
public class AudioRatingDto : RatingDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the source of the audio rating (e.g., a specific website or platform).
|
||||
/// </summary>
|
||||
public AudioRatingSource? Source { get; set; }
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a music album that the user deleted and can restore.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the deleted album.</param>
|
||||
/// <param name="LibraryId">The Id of the media library the deleted album belongs to.</param>
|
||||
/// <param name="ArtistId">The Id of the artist the deleted album belongs to.</param>
|
||||
/// <param name="ArtistName">The name of the artist the deleted album belongs to.</param>
|
||||
/// <param name="Title">The title of the deleted album.</param>
|
||||
/// <param name="DeletedOnUtc">The date and time when the album was deleted.</param>
|
||||
/// <param name="CoverPath">The relative path of the stored cover image of the deleted album, when it has one.</param>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public sealed record DeletedMusicAlbumDto(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
Guid ArtistId,
|
||||
string ArtistName,
|
||||
string Title,
|
||||
DateTime DeletedOnUtc,
|
||||
string? CoverPath
|
||||
);
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a music artist that the user deleted and can restore.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the deleted artist.</param>
|
||||
/// <param name="LibraryId">The Id of the media library the deleted artist belongs to.</param>
|
||||
/// <param name="Name">The name of the deleted artist.</param>
|
||||
/// <param name="DeletedOnUtc">The date and time when the artist was deleted.</param>
|
||||
/// <param name="CoverPath">The relative path of the stored cover image of the deleted artist, when it has one.</param>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
public sealed record DeletedMusicArtistDto(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
string Name,
|
||||
DateTime DeletedOnUtc,
|
||||
string? CoverPath
|
||||
);
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object carrying the data needed by the deleted items page of a music library.
|
||||
/// </summary>
|
||||
/// <param name="Library">The media library whose deleted music items are shown.</param>
|
||||
/// <param name="DeletedArtists">The deleted artists of the media library, ordered by the time they were deleted, most recent first.</param>
|
||||
/// <param name="DeletedAlbums">The deleted albums of the media library, ordered by the time they were deleted, most recent first.</param>
|
||||
/// <param name="DeletedTracks">The deleted tracks of the media library, ordered by the time they were deleted, most recent first.</param>
|
||||
public sealed record DeletedMusicItemsPageDto(
|
||||
LibraryDto Library,
|
||||
IReadOnlyList<DeletedMusicArtistDto> DeletedArtists,
|
||||
IReadOnlyList<DeletedMusicAlbumDto> DeletedAlbums,
|
||||
IReadOnlyList<DeletedMusicTrackDto> DeletedTracks
|
||||
);
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a music track that the user deleted and can restore.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the deleted track.</param>
|
||||
/// <param name="LibraryId">The Id of the media library the deleted track belongs to.</param>
|
||||
/// <param name="ArtistId">The Id of the artist the deleted track belongs to.</param>
|
||||
/// <param name="ArtistName">The name of the artist the deleted track belongs to.</param>
|
||||
/// <param name="AlbumId">The Id of the album the deleted track belongs to.</param>
|
||||
/// <param name="AlbumTitle">The title of the album the deleted track belongs to.</param>
|
||||
/// <param name="Title">The title of the deleted track.</param>
|
||||
/// <param name="Path">The file system path of the deleted track.</param>
|
||||
/// <param name="DeletedOnUtc">The date and time when the track was deleted.</param>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public sealed record DeletedMusicTrackDto(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
Guid ArtistId,
|
||||
string ArtistName,
|
||||
Guid AlbumId,
|
||||
string AlbumTitle,
|
||||
string Title,
|
||||
string Path,
|
||||
DateTime DeletedOnUtc
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for an ISRC (International Standard Recording Code) of a track.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Value: {Value}")]
|
||||
public class IsrcDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the ISRC.
|
||||
/// </summary>
|
||||
public string? Value { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaContributors;
|
||||
using Lumina.Presentation.Web.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object carrying the full details of an album, as stored in the media library.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Title: {Metadata?.Title}")]
|
||||
public class MusicAlbumDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the album.
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the artist the album belongs to.
|
||||
/// </summary>
|
||||
public Guid ArtistId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the artist the album belongs to.
|
||||
/// </summary>
|
||||
public string ArtistName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the media library this album belongs to.
|
||||
/// </summary>
|
||||
public Guid LibraryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of the image representing the album, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the stored artwork of the album, in display order, so that all of its pieces can be presented, not just the cover.
|
||||
/// </summary>
|
||||
public List<MediaArtworkDto>? Artwork { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the album metadata of the album.
|
||||
/// </summary>
|
||||
public MusicAlbumMetadataDto? Metadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the physical or digital medium of the album, if applicable.
|
||||
/// </summary>
|
||||
public MusicMediaFormat? MediaFormat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the outermost physical packaging of the album, if applicable.
|
||||
/// </summary>
|
||||
public MusicReleasePackaging? Packaging { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the barcode of the album, if applicable.
|
||||
/// </summary>
|
||||
public string? Barcode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the catalog numbers of the album, if applicable.
|
||||
/// </summary>
|
||||
public List<string>? CatalogNumbers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the label that issued the album, if applicable.
|
||||
/// </summary>
|
||||
public string? Label { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ASIN (Amazon Standard Identification Number) of the album, if applicable.
|
||||
/// </summary>
|
||||
public string? ASIN { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the MusicBrainz identifier of the release, if applicable.
|
||||
/// </summary>
|
||||
public Guid? MusicBrainzReleaseId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the MusicBrainz identifier of the release group, if applicable.
|
||||
/// </summary>
|
||||
public Guid? MusicBrainzReleaseGroupId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the MusicBrainz identifier of the release artist, if applicable.
|
||||
/// </summary>
|
||||
public Guid? MusicBrainzReleaseArtistId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the album was created.
|
||||
/// </summary>
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional date and time when the album was updated.
|
||||
/// </summary>
|
||||
public DateTime? UpdatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of references to the media contributors that performed on the album, each with the role they played.
|
||||
/// </summary>
|
||||
public List<MediaContributorReferenceDto>? Contributors { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ratings for this album.
|
||||
/// </summary>
|
||||
public List<AudioRatingDto>? Ratings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of tracks of the album.
|
||||
/// </summary>
|
||||
public List<MusicTrackDto>? Tracks { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a lightweight album element, containing only the properties needed by the client for card-style navigation.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public class MusicAlbumLiteDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the album.
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the album.
|
||||
/// </summary>
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of tracks of the release.
|
||||
/// </summary>
|
||||
public int TotalTracks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of the image representing the album, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the release year of the album (the re-release year, if available, or the original release year), if known.
|
||||
/// </summary>
|
||||
public int? ReleaseYear { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the set of types of the release.
|
||||
/// </summary>
|
||||
public List<MusicReleaseType>? ReleaseTypes { get; set; }
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.Enums.AudioLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the metadata of an album.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public class MusicAlbumMetadataDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the album.
|
||||
/// </summary>
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the original title of the album, if different from the current title.
|
||||
/// </summary>
|
||||
public string? OriginalTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a brief description or summary of the album.
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the disambiguation comment of the album, used to distinguish albums with the same title.
|
||||
/// </summary>
|
||||
public string? Disambiguation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the release information, including release date and other relevant details.
|
||||
/// </summary>
|
||||
public ReleaseInfoDto? ReleaseInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the language of the album.
|
||||
/// </summary>
|
||||
public LanguageInfoDto? Language { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the original language of the album, if it has been translated.
|
||||
/// </summary>
|
||||
public LanguageInfoDto? OriginalLanguage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of tags that further describe or categorize the album.
|
||||
/// </summary>
|
||||
public List<TagDto>? Tags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of genres associated with the album.
|
||||
/// </summary>
|
||||
public List<GenreDto>? Genres { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the script used by the language of the release of the album.
|
||||
/// </summary>
|
||||
public string? Script { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the set of types of the release.
|
||||
/// </summary>
|
||||
public List<MusicReleaseType>? ReleaseTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the status of the release.
|
||||
/// </summary>
|
||||
public MusicReleaseStatus? ReleaseStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of discs of the release.
|
||||
/// </summary>
|
||||
public int? TotalDiscs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of tracks of the release.
|
||||
/// </summary>
|
||||
public int? TotalTracks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the specific release (edition) the album files match, if different from the release group title.
|
||||
/// </summary>
|
||||
public string? ReleaseTitle { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a MusicBrainz area, the geographic area a music artist is associated with.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
public class MusicAreaDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the MusicBrainz identifier of the area.
|
||||
/// </summary>
|
||||
public Guid? MusicBrainzAreaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the area.
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the sort name of the area, if applicable.
|
||||
/// </summary>
|
||||
public string? SortName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the disambiguation comment of the area, if applicable.
|
||||
/// </summary>
|
||||
public string? Disambiguation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the MusicBrainz type of the area, if applicable.
|
||||
/// </summary>
|
||||
public string? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ISO 3166 code of the area, if applicable.
|
||||
/// </summary>
|
||||
public string? Iso3166Code { get; set; }
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for an alternative name of a music artist.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
public class MusicArtistAliasDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the alias.
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the sort name of the alias, if applicable.
|
||||
/// </summary>
|
||||
public string? SortName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the alias, if applicable.
|
||||
/// </summary>
|
||||
public string? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the locale the alias is used in, if applicable.
|
||||
/// </summary>
|
||||
public string? Locale { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this is the primary alias of the artist.
|
||||
/// </summary>
|
||||
public bool IsPrimary { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date the alias began being used, if applicable.
|
||||
/// </summary>
|
||||
public DateOnly? BeginDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date the alias stopped being used, if applicable.
|
||||
/// </summary>
|
||||
public DateOnly? EndDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the alias is no longer used.
|
||||
/// </summary>
|
||||
public bool IsEnded { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaContributors;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object carrying the full details of a music artist, as stored in the media library.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Name: {Metadata?.Name}")]
|
||||
public class MusicArtistDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the artist.
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the media library this artist belongs to.
|
||||
/// </summary>
|
||||
public Guid LibraryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of the image representing the artist, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the metadata of the artist.
|
||||
/// </summary>
|
||||
public MusicArtistMetadataDto? Metadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the website of the artist, if applicable.
|
||||
/// </summary>
|
||||
public string? Website { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the MusicBrainz identifier of the artist, if applicable.
|
||||
/// </summary>
|
||||
public Guid? MusicBrainzArtistId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of IPI (Interested Party Information) codes of the artist.
|
||||
/// </summary>
|
||||
public List<string>? Ipis { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ISNI (International Standard Name Identifier) codes of the artist.
|
||||
/// </summary>
|
||||
public List<string>? Isnis { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the artist was created.
|
||||
/// </summary>
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional date and time when the artist was updated.
|
||||
/// </summary>
|
||||
public DateTime? UpdatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of references to the media contributors that make up the artist, each with the role they played.
|
||||
/// </summary>
|
||||
public List<MediaContributorReferenceDto>? Contributors { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ratings for this artist.
|
||||
/// </summary>
|
||||
public List<AudioRatingDto>? Ratings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of albums of the artist, each with its own list of tracks.
|
||||
/// </summary>
|
||||
public List<MusicAlbumDto>? Albums { get; set; }
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a lightweight music artist element, containing only the properties needed by the client for card-style navigation.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
public class MusicArtistLiteDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the artist.
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the artist.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of the image representing the artist, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; set; }
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the metadata of a music artist.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
public class MusicArtistMetadataDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the artist.
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the sort name of the artist, a variant of the name used when sorting artists, if applicable.
|
||||
/// </summary>
|
||||
public string? SortName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the disambiguation comment of the artist, used to distinguish artists with the same name, if applicable.
|
||||
/// </summary>
|
||||
public string? Disambiguation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the artist, if applicable.
|
||||
/// </summary>
|
||||
public MusicArtistType? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the gender of the artist, applicable only to artists that are persons or characters, if applicable.
|
||||
/// </summary>
|
||||
public MusicArtistGender? Gender { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ISO 3166-1 alpha-2 code of the country the artist is associated with, if applicable.
|
||||
/// </summary>
|
||||
public string? Country { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the area the artist is primarily identified with, if applicable.
|
||||
/// </summary>
|
||||
public MusicAreaDto? Area { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the area the artist began in, if applicable.
|
||||
/// </summary>
|
||||
public MusicAreaDto? BeginArea { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the area the artist ended in, if applicable.
|
||||
/// </summary>
|
||||
public MusicAreaDto? EndArea { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date the artist started existing, if applicable.
|
||||
/// </summary>
|
||||
public DateOnly? LifeSpanBegin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date the artist stopped existing, if applicable.
|
||||
/// </summary>
|
||||
public DateOnly? LifeSpanEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the artist no longer exists.
|
||||
/// </summary>
|
||||
public bool IsEnded { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of genres associated with the artist.
|
||||
/// </summary>
|
||||
public List<GenreDto>? Genres { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of tags that further describe or categorize the artist.
|
||||
/// </summary>
|
||||
public List<TagDto>? Tags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of alternative names of the artist.
|
||||
/// </summary>
|
||||
public List<MusicArtistAliasDto>? Aliases { get; set; }
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a track returned by a randomized shuffle query.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public class MusicShuffleTrackDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the track.
|
||||
/// </summary>
|
||||
public Guid TrackId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the track.
|
||||
/// </summary>
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the duration of the track in seconds.
|
||||
/// </summary>
|
||||
public int DurationInSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the album the track belongs to.
|
||||
/// </summary>
|
||||
public Guid AlbumId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the album the track belongs to.
|
||||
/// </summary>
|
||||
public string AlbumTitle { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the artist the album belongs to.
|
||||
/// </summary>
|
||||
public Guid ArtistId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of the cover of the album, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaContributors;
|
||||
using Lumina.Presentation.Web.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object carrying the full details of a track, as stored in the media library.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Title: {Metadata?.Title}")]
|
||||
public class MusicTrackDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the track.
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the album the track belongs to.
|
||||
/// </summary>
|
||||
public Guid AlbumId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the media library this track belongs to.
|
||||
/// </summary>
|
||||
public Guid LibraryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the file system path of the track.
|
||||
/// </summary>
|
||||
public string Path { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the audio metadata of the track.
|
||||
/// </summary>
|
||||
public MusicTrackMetadataDto? Metadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of the track on its disc.
|
||||
/// </summary>
|
||||
public int TrackNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of the disc the track belongs to, if applicable.
|
||||
/// </summary>
|
||||
public int? DiscNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the script used by the language of the track, if applicable.
|
||||
/// </summary>
|
||||
public string? Script { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the musical key of the track, if applicable.
|
||||
/// </summary>
|
||||
public MusicKey? Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the tempo of the track in beats per minute, if applicable.
|
||||
/// </summary>
|
||||
public int? Bpm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the work the track is a recording of, if applicable.
|
||||
/// </summary>
|
||||
public MusicWorkDto? Work { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the MusicBrainz identifier of the recording, if applicable.
|
||||
/// </summary>
|
||||
public Guid? MusicBrainzRecordingId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the MusicBrainz identifier of the track, if applicable.
|
||||
/// </summary>
|
||||
public Guid? MusicBrainzTrackId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the track was created.
|
||||
/// </summary>
|
||||
public DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional date and time when the track was updated.
|
||||
/// </summary>
|
||||
public DateTime? UpdatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of moods of the track.
|
||||
/// </summary>
|
||||
public List<MoodDto>? Moods { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ISRC (International Standard Recording Code) of the track.
|
||||
/// </summary>
|
||||
public List<IsrcDto>? Isrcs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of references to the media contributors that performed on the track, each with the role they played.
|
||||
/// </summary>
|
||||
public List<MediaContributorReferenceDto>? Contributors { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ratings for this track.
|
||||
/// </summary>
|
||||
public List<AudioRatingDto>? Ratings { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a lightweight track element, containing only the properties needed by the client to display the tracks of an album.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public class MusicTrackLiteDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the track.
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the track.
|
||||
/// </summary>
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of the track on its disc.
|
||||
/// </summary>
|
||||
public int TrackNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of the disc the track belongs to, if applicable.
|
||||
/// </summary>
|
||||
public int? DiscNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the duration of the track in seconds.
|
||||
/// </summary>
|
||||
public int DurationInSeconds { get; set; }
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the audio metadata of a track.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public class MusicTrackMetadataDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the track.
|
||||
/// </summary>
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the original title of the track, if different from the current title.
|
||||
/// </summary>
|
||||
public string? OriginalTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a brief description or summary of the track.
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the disambiguation comment of the track, used to distinguish tracks with the same title.
|
||||
/// </summary>
|
||||
public string? Disambiguation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the release information, including release date and other relevant details.
|
||||
/// </summary>
|
||||
public ReleaseInfoDto? ReleaseInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the language of the track.
|
||||
/// </summary>
|
||||
public LanguageInfoDto? Language { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the original language of the track, if it has been translated.
|
||||
/// </summary>
|
||||
public LanguageInfoDto? OriginalLanguage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of tags that further describe or categorize the track.
|
||||
/// </summary>
|
||||
public List<TagDto>? Tags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of genres associated with the track.
|
||||
/// </summary>
|
||||
public List<GenreDto>? Genres { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the recording of the track is a video recording.
|
||||
/// </summary>
|
||||
public bool IsVideo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the duration of the audio of the track in seconds.
|
||||
/// </summary>
|
||||
public int? DurationInSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the sample rate of the audio of the track in Hz.
|
||||
/// </summary>
|
||||
public int? SampleRate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of audio channels of the track.
|
||||
/// </summary>
|
||||
public int? Channels { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the bit depth of the audio of the track.
|
||||
/// </summary>
|
||||
public int? BitDepth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the audio codec used by the track.
|
||||
/// </summary>
|
||||
public string? AudioCodec { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the bitrate of the audio of the track in kbps.
|
||||
/// </summary>
|
||||
public int? Bitrate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the AcoustID fingerprint identifier of the audio file of the track.
|
||||
/// </summary>
|
||||
public string? AcoustId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ReplayGain track gain of the track in decibels.
|
||||
/// </summary>
|
||||
public decimal? ReplayGainTrackGain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ReplayGain track peak of the track.
|
||||
/// </summary>
|
||||
public decimal? ReplayGainTrackPeak { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ReplayGain album gain of the track in decibels.
|
||||
/// </summary>
|
||||
public decimal? ReplayGainAlbumGain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ReplayGain album peak of the track.
|
||||
/// </summary>
|
||||
public decimal? ReplayGainAlbumPeak { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a MusicBrainz work, the musical composition a track is a recording of.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public class MusicWorkDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the MusicBrainz identifier of the work.
|
||||
/// </summary>
|
||||
public Guid? MusicBrainzWorkId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the work.
|
||||
/// </summary>
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the MusicBrainz type of the work, if applicable.
|
||||
/// </summary>
|
||||
public string? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of languages of the work.
|
||||
/// </summary>
|
||||
public List<LanguageInfoDto>? Languages { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ISWC (International Standard Musical Work Code) of the work.
|
||||
/// </summary>
|
||||
public List<string>? Iswcs { get; set; }
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the playback manifest of a track, describing the format of its stored audio, the delivery the server decided on for the requesting player, and the path of its stream.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("TrackId: {TrackId} IsDirectPlay: {IsDirectPlay}")]
|
||||
public class PlaybackManifestDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the track the manifest describes.
|
||||
/// </summary>
|
||||
public Guid TrackId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the duration of the audio of the track, in seconds.
|
||||
/// </summary>
|
||||
public int DurationInSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the container of the audio file of the track, as stored by the probe.
|
||||
/// </summary>
|
||||
public string? SourceContainer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the codec of the audio of the track, as stored by the probe.
|
||||
/// </summary>
|
||||
public string? SourceCodec { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the sample rate of the audio of the track, in Hz.
|
||||
/// </summary>
|
||||
public int SampleRate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of audio channels of the track.
|
||||
/// </summary>
|
||||
public int Channels { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the bit depth of the audio of the track.
|
||||
/// </summary>
|
||||
public int? BitDepth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ReplayGain track gain of the track, in decibels.
|
||||
/// </summary>
|
||||
public decimal? ReplayGainTrackGain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ReplayGain track peak of the track.
|
||||
/// </summary>
|
||||
public decimal? ReplayGainTrackPeak { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ReplayGain album gain of the track, in decibels.
|
||||
/// </summary>
|
||||
public decimal? ReplayGainAlbumGain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ReplayGain album peak of the track.
|
||||
/// </summary>
|
||||
public decimal? ReplayGainAlbumPeak { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the player can play the stored audio as it is, without the server changing its container or its codec.
|
||||
/// </summary>
|
||||
public bool IsDirectPlay { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the container of the audio the server delivers, when the delivery is not a direct play.
|
||||
/// </summary>
|
||||
public string? DeliveryContainer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the codec of the audio the server delivers, when the delivery is not a direct play.
|
||||
/// </summary>
|
||||
public string? DeliveryCodec { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the shape the delivered audio is addressed and seeked by, when the delivery is not a direct play.
|
||||
/// </summary>
|
||||
public PlaybackDeliveryShape? DeliveryShape { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the duration of each segment of the delivered audio, in seconds, when the delivery is addressed as time addressed segments.
|
||||
/// </summary>
|
||||
public int? SegmentDurationSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the delivered audio can be seeked by the player.
|
||||
/// </summary>
|
||||
public bool IsSeekable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of the track stream. The API returns it relative to itself; this web application replaces it with
|
||||
/// the URL of its own streaming proxy, so that the browser never reaches the API server directly.
|
||||
/// </summary>
|
||||
public string StreamPath { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the opaque handle of the normalized delivery. The API returns it so the segment route can address exactly the delivery
|
||||
/// the manifest declared. It is <see langword="null"/> for a direct play.
|
||||
/// </summary>
|
||||
public string? DeliveryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path template of the segment route of the normalized delivery. The API returns it relative to itself with a
|
||||
/// <c>{deliveryId}</c> and a <c>{segmentIndex}</c> placeholder; this web application replaces it with the URL of its own segment proxy, so
|
||||
/// that the browser never reaches the API server directly. It is <see langword="null"/> for a direct play.
|
||||
/// </summary>
|
||||
public string? SegmentStreamPathTemplate { get; set; }
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the response of an update music cover operation.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("CoverPath: {CoverPath}")]
|
||||
public class UpdateMusicCoverDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the relative path of the stored cover image.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for an authorization permission.
|
||||
/// </summary>
|
||||
/// <param name="Id">The unique identifier of the permission.</param>
|
||||
/// <param name="PermissionName">The name of the permission.</param>
|
||||
[DebuggerDisplay("Id: {Id}; PermissionName: {PermissionName}")]
|
||||
public record PermissionDto(
|
||||
Guid Id,
|
||||
AuthorizationPermission PermissionName
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for an authorization role.
|
||||
/// </summary>
|
||||
/// <param name="Id">The unique identifier of the role.</param>
|
||||
/// <param name="RoleName">The name of the role.</param>
|
||||
[DebuggerDisplay("Id: {Id}; RoleName: {RoleName}")]
|
||||
public record RoleDto(
|
||||
Guid Id,
|
||||
string RoleName
|
||||
);
|
||||
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a model for an authorization role with its permissions.
|
||||
/// </summary>
|
||||
/// <param name="Role">The authorization role.</param>
|
||||
/// <param name="Permissions">The permissions of the authorization role.</param>
|
||||
[DebuggerDisplay("Role: {Role}")]
|
||||
public record RolePermissionsDto(
|
||||
RoleDto Role,
|
||||
PermissionDto[] Permissions
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.UsersManagement;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a user with its authorization permissions.
|
||||
/// </summary>
|
||||
/// <param name="User">The user.</param>
|
||||
/// <param name="Permissions">The authorization permissions of the user.</param>
|
||||
[DebuggerDisplay("User: {User}")]
|
||||
public record UserPermissionsDto(
|
||||
UserDto User,
|
||||
PermissionDto[] Permissions
|
||||
);
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the data shown on the error page.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("RequestId: {RequestId}; ShouldShowRequestId: {ShouldShowRequestId}")]
|
||||
public class ErrorViewDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the request identifier to display.
|
||||
/// </summary>
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the request identifier should be shown.
|
||||
/// </summary>
|
||||
public bool ShouldShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a request to get genre information.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Name}")]
|
||||
public class GenreDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the name of the genre element of the media item.
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a request to get language information.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{LanguageName}")]
|
||||
public class LanguageInfoDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the ISO 639-1 two-letter language code.
|
||||
/// </summary>
|
||||
public string? LanguageCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full name of the language in English.
|
||||
/// </summary>
|
||||
public string? LanguageName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an optional native name of the language.
|
||||
/// </summary>
|
||||
public string? NativeName { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaLibrary;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a stored piece of artwork of a media item.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Type: {Type}; Ordinal: {Ordinal}; Path: {Path}")]
|
||||
public class MediaArtworkDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the artwork, like the cover or the back of the media item.
|
||||
/// </summary>
|
||||
public ArtworkType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ordinal of the artwork within its type, so that multiple artworks of the same type can be ordered.
|
||||
/// </summary>
|
||||
public int Ordinal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the relative path of the stored artwork file.
|
||||
/// </summary>
|
||||
public string Path { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a mood of a media element.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
public class MoodDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the mood.
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Notifications;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for notifications.
|
||||
/// </summary>
|
||||
/// <param name="Id">The id of the notification.</param>
|
||||
/// <param name="Message">The message of the notification.</param>
|
||||
/// <param name="Type">The type of the notification.</param>
|
||||
[DebuggerDisplay("Id: {Id}; Message: {Message}")]
|
||||
public record struct NotificationDto(
|
||||
Guid Id,
|
||||
string Message,
|
||||
NotificationType Type
|
||||
);
|
||||
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a page of elements together with its pagination metadata.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the elements of the page.</typeparam>
|
||||
/// <param name="Data">The elements of the requested page.</param>
|
||||
/// <param name="CurrentPage">The one based number of the returned page.</param>
|
||||
/// <param name="PerPage">The number of elements requested per page.</param>
|
||||
/// <param name="Count">The total number of elements that match the filter, even when only a page of them is returned.</param>
|
||||
/// <param name="NumberOfPages">The total number of pages that match the filter.</param>
|
||||
[DebuggerDisplay("CurrentPage: {CurrentPage}; PerPage: {PerPage}; Count: {Count}")]
|
||||
public sealed record PaginatedDto<T>(
|
||||
List<T> Data,
|
||||
int CurrentPage,
|
||||
int PerPage,
|
||||
int Count,
|
||||
int NumberOfPages
|
||||
);
|
||||
@@ -0,0 +1,52 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object that follows the RFC 9457 standard for problem details in HTTP APIs.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Title} ({Status})")]
|
||||
public class ProblemDetailsDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the URI reference that identifies the problem type.
|
||||
/// </summary>
|
||||
[JsonPropertyName("type")]
|
||||
public string? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a short, human-readable summary of the problem type.
|
||||
/// </summary>
|
||||
[JsonPropertyName("title")]
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP status code generated by the server for this occurrence of the problem.
|
||||
/// </summary>
|
||||
[JsonPropertyName("status")]
|
||||
public int? Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a detailed explanation specific to this occurrence of the problem.
|
||||
/// </summary>
|
||||
[JsonPropertyName("detail")]
|
||||
public string? Detail { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a URI reference that identifies the specific occurrence of the problem.
|
||||
/// </summary>
|
||||
[JsonPropertyName("instance")]
|
||||
public string? Instance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets additional extension data that may be included with the problem details.
|
||||
/// This allows for including extra, non-standard fields in the problem details.
|
||||
/// </summary>
|
||||
[JsonExtensionData]
|
||||
public IDictionary<string, JsonElement>? Extensions { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a rating.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Value: {Value}; MaxValue: {MaxValue}")]
|
||||
public abstract class RatingDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the numeric value of the rating.
|
||||
/// </summary>
|
||||
public decimal? Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum possible rating value.
|
||||
/// </summary>
|
||||
public decimal? MaxValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional number of votes or reviews this rating is based on.
|
||||
/// </summary>
|
||||
public int? VoteCount { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Common;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a request to get release information.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("OriginalReleaseDate: {OriginalReleaseDate}")]
|
||||
public class ReleaseInfoDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the optional original release date of the media item.
|
||||
/// </summary>
|
||||
public DateOnly? OriginalReleaseDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional original release year of the media item.
|
||||
/// This is useful when only the year of original release is known.
|
||||
/// </summary>
|
||||
public int? OriginalReleaseYear { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional re-release or reissue date of the media item.
|
||||
/// </summary>
|
||||
public DateOnly? ReReleaseDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional re-release or reissue year of the media item.
|
||||
/// </summary>
|
||||
public int? ReReleaseYear { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional country or region of release.
|
||||
/// </summary>
|
||||
public ReleaseCountry? ReleaseCountry { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional release version or edition. (e.g. "Original", "Director's Cut", "2.0").
|
||||
/// </summary>
|
||||
public string? ReleaseVersion { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Response data transfer object for the JSON responses of the web application that do not carry a payload.
|
||||
/// </summary>
|
||||
/// <param name="IsSuccess">Whether the operation succeeded or not.</param>
|
||||
public record SuccessResponse(
|
||||
[property: JsonPropertyName("success")] bool IsSuccess
|
||||
);
|
||||
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Response data transfer object for the JSON responses of the web application that carry a payload.
|
||||
/// </summary>
|
||||
/// <typeparam name="TData">The type of the payload of the response.</typeparam>
|
||||
/// <param name="IsSuccess">Whether the operation succeeded or not.</param>
|
||||
/// <param name="Data">The payload of the response.</param>
|
||||
public record SuccessResponse<TData>(
|
||||
[property: JsonPropertyName("success")] bool IsSuccess,
|
||||
[property: JsonPropertyName("data")] TData? Data
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a request to get tag information.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
public class TagDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the name of the tag element of the media item.
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for deserializing encryption settings.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Section name: {SECTION_NAME}")]
|
||||
public class EncryptionSettingsDto
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the configuration section that holds the encryption settings.
|
||||
/// </summary>
|
||||
public const string SECTION_NAME = "EncryptionSettings";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Base64 encoded secret key used to encrypt and decrypt protected data.
|
||||
/// </summary>
|
||||
public required string SecretKey { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for deserializing server configuration settings.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Section name: {SECTION_NAME}")]
|
||||
public class ServerConfigurationDto
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the configuration section that holds the server settings.
|
||||
/// </summary>
|
||||
public const string SECTION_NAME = "ServerConfiguration";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the version of the remote API used in the request URL.
|
||||
/// </summary>
|
||||
public required char ApiVersion { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the remote API server address.
|
||||
/// </summary>
|
||||
public required string BaseAddress { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the remote API server port.
|
||||
/// </summary>
|
||||
public required ushort Port { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Favorites;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Favorites;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a favorite of the current user.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the favorite.</param>
|
||||
/// <param name="MediaKind">The kind of the favorited media item.</param>
|
||||
/// <param name="MediaItemId">The Id of the favorited media item.</param>
|
||||
/// <param name="FavoritedOnUtc">The date and time when the media item was favorited.</param>
|
||||
[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; MediaItemId: {MediaItemId}")]
|
||||
public sealed record FavoriteDto(
|
||||
Guid Id,
|
||||
FavoriteMediaKind MediaKind,
|
||||
Guid MediaItemId,
|
||||
DateTime FavoritedOnUtc
|
||||
);
|
||||
@@ -0,0 +1,34 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Favorites;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Favorites;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a favorite of the current user together with the display details of the media item it references.
|
||||
/// </summary>
|
||||
/// <param name="MediaKind">The kind of the favorited media item.</param>
|
||||
/// <param name="MediaItemId">The Id of the favorited media item.</param>
|
||||
/// <param name="IsAvailable">Whether the media item still exists and can be accessed by the user. When <see langword="false"/>, every display field is empty.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the media item, or an empty Guid when the item is not available.</param>
|
||||
/// <param name="Title">The title of the media item, or an empty string when the item is not available.</param>
|
||||
/// <param name="CollectionId">The Id of the collection that contains the media item, or an empty Guid when there is none.</param>
|
||||
/// <param name="CollectionTitle">The title of the collection that contains the media item, or an empty string when there is none.</param>
|
||||
/// <param name="CreatorId">The Id of the creator of the media item, or an empty Guid when there is none.</param>
|
||||
/// <param name="CreatorName">The name of the creator of the media item, or an empty string when there is none.</param>
|
||||
/// <param name="CoverPath">The path of the cover art of the media item, if available.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; MediaItemId: {MediaItemId}")]
|
||||
public sealed record FavoriteItemDto(
|
||||
FavoriteMediaKind MediaKind,
|
||||
Guid MediaItemId,
|
||||
bool IsAvailable,
|
||||
Guid LibraryId,
|
||||
string Title,
|
||||
Guid CollectionId,
|
||||
string CollectionTitle,
|
||||
Guid CreatorId,
|
||||
string CreatorName,
|
||||
string? CoverPath
|
||||
);
|
||||
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Favorites;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object that tells which of the checked media items are favorites of the current user.
|
||||
/// </summary>
|
||||
/// <param name="FavoritedMediaItemIds">The Ids, among the checked ones, of the media items that are favorites of the current user.</param>
|
||||
[DebuggerDisplay("Favorited: {FavoritedMediaItemIds.Count}")]
|
||||
public sealed record FavoriteStatusDto(
|
||||
List<Guid> FavoritedMediaItemIds
|
||||
);
|
||||
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a model for storing binary data (blob).
|
||||
/// </summary>
|
||||
[DebuggerDisplay("ContentType: {ContentType} (Data.Length)")]
|
||||
public class BlobDataDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the binary data as a byte array.
|
||||
/// </summary>
|
||||
public byte[] Data { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the content type (MIME type) of the blob data, such as "image/png" for an image or "application/pdf" for a PDF document.
|
||||
/// </summary>
|
||||
public string ContentType { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for directories displayed in custom directory/file browser dialogs.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public class DirectoryDto : FileSystemItemDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the children items of the directory.
|
||||
/// </summary>
|
||||
public List<FileSystemItemDto> Items { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for files displayed in custom directory/file browser dialogs.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public class FileDto : FileSystemItemDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the size of the file, in bytes.
|
||||
/// </summary>
|
||||
public long Size { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Base data transfer object for files and directories displayed in custom directory/file browser dialogs.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public abstract class FileSystemItemDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the full path to the file system item.
|
||||
/// </summary>
|
||||
public string? Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the file system item.
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the creation date of the file system item.
|
||||
/// </summary>
|
||||
public DateTime DateCreated { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the modification date of the file system item.
|
||||
/// </summary>
|
||||
public DateTime DateModified { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the file system item is hidden.
|
||||
/// </summary>
|
||||
public bool IsHidden { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.FileSystem;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a file system node.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public class FileSystemTreeNodeDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the full path of the file or directory.
|
||||
/// </summary>
|
||||
public string Path { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the file or directory.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the item, indicating whether it is a file, directory, or drive.
|
||||
/// </summary>
|
||||
public FileSystemItemType ItemType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the file or directory is hidden.
|
||||
/// </summary>
|
||||
public bool IsHidden { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the node is expanded.
|
||||
/// </summary>
|
||||
public bool IsExpanded { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the child nodes have been loaded.
|
||||
/// </summary>
|
||||
public bool ChildrenLoaded { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of child nodes.
|
||||
/// </summary>
|
||||
public List<FileSystemTreeNodeDto> Children { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.FileSystem;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object containing the file system platform type.
|
||||
/// </summary>`
|
||||
[DebuggerDisplay("PlatformType: {PlatformType}")]
|
||||
public class FileSystemTypeDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the file system platform type.
|
||||
/// </summary>
|
||||
public PlatformType PlatformType { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a response to the inquiry about the existence of a file system path.
|
||||
/// </summary>
|
||||
/// <param name="Exists">Whether a file system path exists or not.</param>
|
||||
[DebuggerDisplay("Exists: {Exists}")]
|
||||
public record PathExistsDto(
|
||||
bool Exists
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a response containing a file system path.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public class PathSegmentDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the returned path.
|
||||
/// </summary>
|
||||
public string Path { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a file system path separator.
|
||||
/// </summary>
|
||||
/// <param name="Separator">The system's path separator.</param>
|
||||
[DebuggerDisplay("Separator: {Separator}")]
|
||||
public record PathSeparatorDto(
|
||||
string Separator
|
||||
);
|
||||
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a response to the inquiry about the validity of a file system path.
|
||||
/// </summary>
|
||||
/// <param name="IsValid">Whether a file system path is valid or not.</param>
|
||||
[DebuggerDisplay("IsValid: {IsValid}")]
|
||||
public record PathValidDto(
|
||||
bool IsValid
|
||||
);
|
||||
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a lightweight book element, containing only the properties needed by the client for card-style navigation.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public class BookLiteDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the book.
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the book.
|
||||
/// </summary>
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the release year of the book (re-release year, if available, or original release year), if known.
|
||||
/// </summary>
|
||||
public int? ReleaseYear { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of the image representing the cover of the book, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the data of the media libraries management page.
|
||||
/// </summary>
|
||||
/// <param name="CanManageLibraries">Whether the current user can change and delete their media libraries, which takes the permission to manage media libraries, or the administrator role.</param>
|
||||
[DebuggerDisplay("CanManageLibraries: {CanManageLibraries}")]
|
||||
public sealed record LibrariesIndexPageDto(
|
||||
bool CanManageLibraries
|
||||
);
|
||||
@@ -0,0 +1,109 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a library element.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public class LibraryDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier of the media library.
|
||||
/// </summary>
|
||||
public Guid? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the library.
|
||||
/// </summary>
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the library.
|
||||
/// </summary>
|
||||
public string? LibraryType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of the image file used as the cover for the library.
|
||||
/// </summary>
|
||||
public string? CoverImage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the collection of directories that contain the library files.
|
||||
/// </summary>
|
||||
public List<string> ContentLocations { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this media library is enabled or not. A disabled media library is never shown or changed.
|
||||
/// </summary>
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this media library is locked or not. A locked media library is displayed, but is never changed or updated.
|
||||
/// </summary>
|
||||
public bool IsLocked { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this media library should update the metadata of its elements from the web, or not.
|
||||
/// </summary>
|
||||
public bool CanDownloadMetadataFromWeb { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this media library should copy the downloaded metadata into the media library content locations, or not.
|
||||
/// </summary>
|
||||
public bool ShouldSaveMetadataInMediaDirectories { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this media library should skip the directories whose contents have not changed since the last scan, during the scan. This is an opt-in setting, because it relies on directory metadata,
|
||||
/// which does not change when the contents of an existing file are edited, and such edits could be missed while this setting is enabled.
|
||||
/// </summary>
|
||||
public bool ShouldSkipUnchangedDirectoriesDuringScan { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this media library should skip hidden files and directories during the scan, or not. When absent, the default is off on create, and the stored value is kept on update.
|
||||
/// </summary>
|
||||
public bool? ShouldSkipHiddenFilesAndDirectoriesDuringScan { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the content of this media library is stored on a solid state drive, in which case the file discovery and content hashing stages read the files in parallel.
|
||||
/// </summary>
|
||||
public bool IsContentOnSsd { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the consumption progress of the media library items is tracked, or not. When absent, the default of the library type is used on create, and the stored value is kept on update.
|
||||
/// </summary>
|
||||
public bool? ShouldTrackConsumptionProgress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the percentage of a media library item that must be consumed for its session to be considered completed. When absent, the default of the library type is used on create,
|
||||
/// and the stored value is kept on update.
|
||||
/// </summary>
|
||||
public int? CompletionThresholdPercentage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ordered parts of the template describing the structure of the media library on disk.
|
||||
/// </summary>
|
||||
public List<LibraryPathTemplatePartDto> PathTemplateParts { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the metadata providers of the media library, in the order in which they are tried, and whether each one is enabled. When absent, the providers are configured
|
||||
/// with their defaults on create, and on update the stored configurations are kept, or reconciled with the library type when it changes.
|
||||
/// </summary>
|
||||
public List<LibraryProviderSelectionDto>? MetadataProviders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the artwork providers of the media library, in the order in which they are tried, and whether each one is enabled. When absent, the providers are configured
|
||||
/// with their defaults on create, and on update the stored configurations are kept, or reconciled with the library type when it changes.
|
||||
/// </summary>
|
||||
public List<LibraryProviderSelectionDto>? ArtworkProviders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the book readers of the media library, and whether each one is enabled. When absent, the readers are configured with their defaults on create, and on update
|
||||
/// the stored configurations are kept, or reconciled with the library type when it changes.
|
||||
/// </summary>
|
||||
public List<LibraryProviderSelectionDto>? BookReaders { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a path part available for a media library type.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Kind: {Kind}")]
|
||||
public class LibraryPathPartDefinitionDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the kind of the path part.
|
||||
/// </summary>
|
||||
public string Kind { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value type captured by the path part.
|
||||
/// </summary>
|
||||
public string ValueType { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default representation of the path part.
|
||||
/// </summary>
|
||||
public string DefaultRepresentation { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the path part is optional by default.
|
||||
/// </summary>
|
||||
public bool IsOptionalByDefault { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the path template catalog of a media library type.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Parts: {Parts.Count}; DefaultTemplateParts: {DefaultTemplateParts.Count}")]
|
||||
public class LibraryPathTemplateCatalogDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the path parts that can be used in the path template of the library type.
|
||||
/// </summary>
|
||||
public List<LibraryPathPartDefinitionDto> Parts { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ordered parts of the default path template of the library type.
|
||||
/// </summary>
|
||||
public List<LibraryPathTemplatePartDto> DefaultTemplateParts { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for one part of the path template of a media library.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Kind: {Kind}; Representation: {Representation}")]
|
||||
public class LibraryPathTemplatePartDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the kind of the path part.
|
||||
/// </summary>
|
||||
public string Kind { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the literal text or the value mask of the path part.
|
||||
/// </summary>
|
||||
public string Representation { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the path part can be absent from the path.
|
||||
/// </summary>
|
||||
public bool IsOptional { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the choice made for one metadata provider, artwork provider or book reader of a media library.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("PluginId: {PluginId}; IsEnabled: {IsEnabled}")]
|
||||
public class LibraryProviderSelectionDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier of the plugin providing the metadata provider, artwork provider or book reader.
|
||||
/// </summary>
|
||||
public Guid PluginId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the provider or reader is enabled for the media library. Optional, the stored state is kept when absent, and a provider or reader without a stored state starts disabled.
|
||||
/// </summary>
|
||||
public bool? IsEnabled { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a media library scan job progress model.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("CompletedItems: {CompletedItems}; TotalItems: {TotalItems}")]
|
||||
public class LibraryScanJobProgressDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the number of completed items of the media library scan job.
|
||||
/// </summary>
|
||||
public int CompletedItems { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the total number of items of the media library scan job.
|
||||
/// </summary>
|
||||
public int TotalItems { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current operation being performed by the media library scan job.
|
||||
/// </summary>
|
||||
public string? CurrentOperation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ratio between the total number and the completed number of items, as a percentage.
|
||||
/// </summary>
|
||||
public decimal ProgressPercentage { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a media library scan progress model.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("ScanId: {ScanId}; UserId: {UserId}; LibraryId: {LibraryId}")]
|
||||
public class LibraryScanProgressDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier of the media library scan.
|
||||
/// </summary>
|
||||
public Guid ScanId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier of the user initiating this media library scan.
|
||||
/// </summary>
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier of the media library that is scanned.
|
||||
/// </summary>
|
||||
public Guid LibraryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of completed jobs of the media library scan job.
|
||||
/// </summary>
|
||||
public int CompletedJobs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the total number of jobs of the media library scan job.
|
||||
/// </summary>
|
||||
public int TotalJobs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional current job progress of the media library scan.
|
||||
/// </summary>
|
||||
public LibraryScanJobProgressDto? CurrentJobProgress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the status of the media library scan.
|
||||
/// </summary>
|
||||
public string? Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ratio between the total number and the completed number of jobs, as a percentage.
|
||||
/// </summary>
|
||||
public decimal OverallProgressPercentage { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a media library scan response.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("ScanId: {ScanId} LibraryId: {LibraryId}")]
|
||||
public class ScanLibraryDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the media library scan.
|
||||
/// </summary>
|
||||
public Guid? ScanId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the scanned media library.
|
||||
/// </summary>
|
||||
public Guid? LibraryId { get; set; }
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the consumption statistics of every user, together with their combined totals.
|
||||
/// </summary>
|
||||
/// <param name="Total">The combined consumption statistics of every user.</param>
|
||||
/// <param name="Users">The consumption statistics of each user.</param>
|
||||
[DebuggerDisplay("UserCount: {Users.Count}; CountedSessionCount: {Total.CountedSessionCount}")]
|
||||
public sealed record AllUsersConsumptionStatisticsDto(
|
||||
ConsumptionTotalsDto Total,
|
||||
IReadOnlyList<ConsumptionSummaryDto> Users
|
||||
);
|
||||
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a media item of the consumption history, together with its aggregated consumption counts and display details.
|
||||
/// </summary>
|
||||
/// <param name="MediaKind">The kind of the consumed media item.</param>
|
||||
/// <param name="MediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the media item.</param>
|
||||
/// <param name="IsAvailable">Whether the media item still exists and can be accessed by the user. When <see langword="false"/>, the title, collection title, creator name, and cover path are blank, while the identity and aggregation fields remain.</param>
|
||||
/// <param name="Title">The title of the media item, or an empty string when the item is not available.</param>
|
||||
/// <param name="CollectionTitle">The title of the collection that contains the media item, or an empty string when there is none.</param>
|
||||
/// <param name="CreatorName">The name of the creator of the media item, or an empty string when there is none.</param>
|
||||
/// <param name="CoverPath">The path of the cover art of the media item, if available.</param>
|
||||
/// <param name="LastConsumedOnUtc">The date and time when the media item was last consumed.</param>
|
||||
/// <param name="CountedSessionCount">The number of consumption sessions of the media item that count towards statistics.</param>
|
||||
/// <param name="CompletedSessionCount">The number of consumption sessions of the media item that completed.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed in the media item, over all of its sessions, in seconds.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; MediaItemId: {MediaItemId}; CountedSessionCount: {CountedSessionCount}")]
|
||||
public sealed record ConsumedItemDto(
|
||||
MediaKind MediaKind,
|
||||
Guid MediaItemId,
|
||||
Guid LibraryId,
|
||||
bool IsAvailable,
|
||||
string Title,
|
||||
string CollectionTitle,
|
||||
string CreatorName,
|
||||
string? CoverPath,
|
||||
DateTime LastConsumedOnUtc,
|
||||
int CountedSessionCount,
|
||||
int CompletedSessionCount,
|
||||
double ConsumedDurationInSeconds
|
||||
);
|
||||
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a media consumption session of the current user.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the consumption record.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the consumed media item.</param>
|
||||
/// <param name="MediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="MediaKind">The kind of media that was consumed.</param>
|
||||
/// <param name="Status">The state of the consumption session.</param>
|
||||
/// <param name="StartedOnUtc">The date and time when the session started.</param>
|
||||
/// <param name="LastActivityOnUtc">The date and time when the session last received activity.</param>
|
||||
/// <param name="EndedOnUtc">The date and time when the session completed or stopped, if it has ended.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed by the session, in seconds.</param>
|
||||
/// <param name="LastPosition">The last known position for the media item, if any.</param>
|
||||
/// <param name="LastProgressFraction">The latest reported progress fraction of the media item.</param>
|
||||
/// <param name="ConsecutivePagesRead">The number of consecutive pages read in the session.</param>
|
||||
[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; Status: {Status}")]
|
||||
public sealed record ConsumptionRecordDto(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
Guid MediaItemId,
|
||||
MediaKind MediaKind,
|
||||
ConsumptionStatus Status,
|
||||
DateTime StartedOnUtc,
|
||||
DateTime LastActivityOnUtc,
|
||||
DateTime? EndedOnUtc,
|
||||
double ConsumedDurationInSeconds,
|
||||
MediaPositionDto? LastPosition,
|
||||
double LastProgressFraction,
|
||||
int ConsecutivePagesRead
|
||||
);
|
||||
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the consumption statistics of a user.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user the statistics belong to.</param>
|
||||
/// <param name="TotalConsumedDurationInSeconds">The total duration consumed over every recorded session, in seconds.</param>
|
||||
/// <param name="CountedSessionCount">The number of recorded sessions that count towards statistics.</param>
|
||||
/// <param name="CompletedSessionCount">The number of recorded sessions that completed.</param>
|
||||
/// <param name="StoppedSessionCount">The number of recorded sessions that stopped before they completed and count towards statistics.</param>
|
||||
/// <param name="CompletionRate">The fraction of the counted sessions that completed, between 0 and 1, or 0 when there is no counted session.</param>
|
||||
/// <param name="MediaKindSummaries">The consumption statistics broken down by media kind.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}; CountedSessionCount: {CountedSessionCount}")]
|
||||
public sealed record ConsumptionSummaryDto(
|
||||
Guid UserId,
|
||||
double TotalConsumedDurationInSeconds,
|
||||
int CountedSessionCount,
|
||||
int CompletedSessionCount,
|
||||
int StoppedSessionCount,
|
||||
double CompletionRate,
|
||||
IReadOnlyList<MediaKindConsumptionSummaryDto> MediaKindSummaries
|
||||
);
|
||||
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the combined consumption statistics of every user.
|
||||
/// </summary>
|
||||
/// <param name="TotalConsumedDurationInSeconds">The total duration consumed over every recorded session of every user, in seconds.</param>
|
||||
/// <param name="CountedSessionCount">The number of recorded sessions of every user that count towards statistics.</param>
|
||||
/// <param name="CompletedSessionCount">The number of recorded sessions of every user that completed.</param>
|
||||
/// <param name="StoppedSessionCount">The number of recorded sessions of every user that stopped before they completed and count towards statistics.</param>
|
||||
/// <param name="CompletionRate">The fraction of the counted sessions of every user that completed, between 0 and 1, or 0 when there is no counted session.</param>
|
||||
/// <param name="MediaKindSummaries">The combined consumption statistics broken down by media kind.</param>
|
||||
[DebuggerDisplay("CountedSessionCount: {CountedSessionCount}; CompletedSessionCount: {CompletedSessionCount}")]
|
||||
public sealed record ConsumptionTotalsDto(
|
||||
double TotalConsumedDurationInSeconds,
|
||||
int CountedSessionCount,
|
||||
int CompletedSessionCount,
|
||||
int StoppedSessionCount,
|
||||
double CompletionRate,
|
||||
IReadOnlyList<MediaKindConsumptionSummaryDto> MediaKindSummaries
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the consumption statistics of a genre, grouped across media kinds.
|
||||
/// </summary>
|
||||
/// <param name="Name">The lowercase name of the genre.</param>
|
||||
/// <param name="ConsumedItemCount">The number of distinct media items that carry the genre and were consumed.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed in the media items that carry the genre, in seconds.</param>
|
||||
[DebuggerDisplay("Name: {Name}; ConsumedItemCount: {ConsumedItemCount}")]
|
||||
public sealed record GenreConsumptionDto(
|
||||
string Name,
|
||||
int ConsumedItemCount,
|
||||
double ConsumedDurationInSeconds
|
||||
);
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the consumption statistics of one kind of media.
|
||||
/// </summary>
|
||||
/// <param name="MediaKind">The kind of media the statistics belong to.</param>
|
||||
/// <param name="TotalConsumedDurationInSeconds">The total duration consumed over every recorded session of the media kind, in seconds.</param>
|
||||
/// <param name="CountedSessionCount">The number of recorded sessions of the media kind that count towards statistics.</param>
|
||||
/// <param name="CompletedSessionCount">The number of recorded sessions of the media kind that completed.</param>
|
||||
/// <param name="StoppedSessionCount">The number of recorded sessions of the media kind that stopped before they completed and count towards statistics.</param>
|
||||
/// <param name="CompletionRate">The fraction of the counted sessions of the media kind that completed, between 0 and 1.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; CountedSessionCount: {CountedSessionCount}")]
|
||||
public sealed record MediaKindConsumptionSummaryDto(
|
||||
MediaKind MediaKind,
|
||||
double TotalConsumedDurationInSeconds,
|
||||
int CountedSessionCount,
|
||||
int CompletedSessionCount,
|
||||
int StoppedSessionCount,
|
||||
double CompletionRate
|
||||
);
|
||||
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a position reached in a media item during a consumption session.
|
||||
/// </summary>
|
||||
/// <param name="Kind">The kind of representation used by the position.</param>
|
||||
/// <param name="TimeOffsetSeconds">The position within the media item, in seconds, when the position is a time offset.</param>
|
||||
/// <param name="Location">The opaque locator within the media item, when the position is not a time offset.</param>
|
||||
[DebuggerDisplay("Kind: {Kind}; TimeOffsetSeconds: {TimeOffsetSeconds}")]
|
||||
public sealed record MediaPositionDto(
|
||||
MediaPositionKind Kind,
|
||||
double? TimeOffsetSeconds,
|
||||
string? Location
|
||||
);
|
||||
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the point at which a user can resume consuming a media item.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the resume point.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the media item.</param>
|
||||
/// <param name="MediaItemId">The Id of the media item to resume.</param>
|
||||
/// <param name="MediaKind">The kind of media that is resumed.</param>
|
||||
/// <param name="LastPosition">The position at which the media item can be resumed.</param>
|
||||
/// <param name="LastProgressFraction">The progress fraction at which the media item can be resumed.</param>
|
||||
/// <param name="LastConsumedOnUtc">The date and time when the media item was last consumed.</param>
|
||||
[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; MediaItemId: {MediaItemId}")]
|
||||
public sealed record ResumePointDto(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
Guid MediaItemId,
|
||||
MediaKind MediaKind,
|
||||
MediaPositionDto LastPosition,
|
||||
double LastProgressFraction,
|
||||
DateTime LastConsumedOnUtc
|
||||
);
|
||||
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the data and the proxy routes of the statistics page.
|
||||
/// </summary>
|
||||
/// <param name="Title">The localized title of the page.</param>
|
||||
/// <param name="IsAdmin">Whether the current user is an administrator and can select another user or all users.</param>
|
||||
/// <param name="CurrentUserId">The Id of the current user, or <see langword="null"/> when it cannot be determined.</param>
|
||||
/// <param name="Culture">The culture of the page.</param>
|
||||
/// <param name="GetStatisticsUrl">The route that returns the statistics of the selected user.</param>
|
||||
/// <param name="GetAllUsersStatisticsUrl">The route that returns the statistics of every user.</param>
|
||||
/// <param name="GetRecentlyConsumedUrl">The route that returns the recently consumed media items of the selected user.</param>
|
||||
/// <param name="GetMostConsumedUrl">The route that returns the most consumed media items of the selected user.</param>
|
||||
/// <param name="GetTagConsumptionUrl">The route that returns the tag consumption of the selected user.</param>
|
||||
/// <param name="GetGenreConsumptionUrl">The route that returns the genre consumption of the selected user.</param>
|
||||
/// <param name="GetLibrariesUrl">The route that returns the libraries available for the library filter.</param>
|
||||
/// <param name="GetUsersUrl">The route that returns the users available for the administrator user selector, or an empty string for a regular user.</param>
|
||||
/// <param name="DeleteConsumptionItemHistoryUrl">The route that deletes every consumption record of a media item.</param>
|
||||
/// <param name="ClearConsumptionHistoryUrl">The route that deletes the consumption history of the selected user.</param>
|
||||
/// <param name="ClearResumePointsUrl">The route that deletes the resume points of the selected user.</param>
|
||||
[DebuggerDisplay("IsAdmin: {IsAdmin}; CurrentUserId: {CurrentUserId}")]
|
||||
public sealed record StatisticsPageDto(
|
||||
string Title,
|
||||
bool IsAdmin,
|
||||
Guid? CurrentUserId,
|
||||
string Culture,
|
||||
string GetStatisticsUrl,
|
||||
string GetAllUsersStatisticsUrl,
|
||||
string GetRecentlyConsumedUrl,
|
||||
string GetMostConsumedUrl,
|
||||
string GetTagConsumptionUrl,
|
||||
string GetGenreConsumptionUrl,
|
||||
string GetLibrariesUrl,
|
||||
string GetUsersUrl,
|
||||
string DeleteConsumptionItemHistoryUrl,
|
||||
string ClearConsumptionHistoryUrl,
|
||||
string ClearResumePointsUrl
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the consumption statistics of a tag, grouped across media kinds.
|
||||
/// </summary>
|
||||
/// <param name="Name">The lowercase name of the tag.</param>
|
||||
/// <param name="ConsumedItemCount">The number of distinct media items that carry the tag and were consumed.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed in the media items that carry the tag, in seconds.</param>
|
||||
[DebuggerDisplay("Name: {Name}; ConsumedItemCount: {ConsumedItemCount}")]
|
||||
public sealed record TagConsumptionDto(
|
||||
string Name,
|
||||
int ConsumedItemCount,
|
||||
double ConsumedDurationInSeconds
|
||||
);
|
||||
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaContributors;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaContributors;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a media contributor.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
public class MediaContributorDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the name of the contributor.
|
||||
/// </summary>
|
||||
public MediaContributorNameDto? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the canonical role of the contributor, used as the key of its localized display string.
|
||||
/// </summary>
|
||||
public MediaContributorRole? Role { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaContributors;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a media contributor name.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("DisplayName: {DisplayName}")]
|
||||
public class MediaContributorNameDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the name by which the contributor is popularly known.
|
||||
/// </summary>
|
||||
public string? DisplayName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the legal name of the contributor.
|
||||
/// </summary>
|
||||
public string? LegalName { get; set; }
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaContributors;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaContributors;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the reference to a media contributor in a media item, carrying the role the contributor played.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{ContributorId} - {Role}")]
|
||||
public class MediaContributorReferenceDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier of the media contributor.
|
||||
/// </summary>
|
||||
public Guid ContributorId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the role the contributor played.
|
||||
/// </summary>
|
||||
public MediaContributorRole? Role { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Playlists;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the editable scalars of a playlist after a details update.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the playlist.</param>
|
||||
/// <param name="Name">The name of the playlist.</param>
|
||||
/// <param name="Description">The description of the playlist, if applicable.</param>
|
||||
/// <param name="Type">The kind of media the playlist holds.</param>
|
||||
/// <param name="UpdatedOnUtc">The date and time when the playlist was last updated, if applicable.</param>
|
||||
[DebuggerDisplay("Id: {Id}; Name: {Name}")]
|
||||
public sealed record PlaylistDetailsDto(
|
||||
Guid Id,
|
||||
string Name,
|
||||
string? Description,
|
||||
PlaylistType Type,
|
||||
DateTime? UpdatedOnUtc
|
||||
);
|
||||
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.Enums.Playlists;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a playlist together with a page of its ordered entries.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the playlist.</param>
|
||||
/// <param name="Name">The name of the playlist.</param>
|
||||
/// <param name="Description">The description of the playlist, if applicable.</param>
|
||||
/// <param name="Type">The kind of media the playlist holds.</param>
|
||||
/// <param name="Entries">The page of ordered entries of the playlist, together with its pagination metadata.</param>
|
||||
/// <param name="CreatedOnUtc">The date and time when the playlist was created.</param>
|
||||
/// <param name="UpdatedOnUtc">The date and time when the playlist was last updated, if applicable.</param>
|
||||
[DebuggerDisplay("Id: {Id}; Name: {Name}; Entries: {Entries.Count}")]
|
||||
public sealed record PlaylistDto(
|
||||
Guid Id,
|
||||
string Name,
|
||||
string? Description,
|
||||
PlaylistType Type,
|
||||
PaginatedDto<PlaylistEntryDto> Entries,
|
||||
DateTime CreatedOnUtc,
|
||||
DateTime? UpdatedOnUtc
|
||||
);
|
||||
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the result of appending several tracks to a playlist.
|
||||
/// </summary>
|
||||
/// <param name="PlaylistId">The Id of the playlist the entries were added to.</param>
|
||||
/// <param name="AddedCount">The number of entries that were appended, including repeated tracks.</param>
|
||||
/// <param name="UpdatedOnUtc">The date and time when the playlist was last updated, if applicable.</param>
|
||||
[DebuggerDisplay("PlaylistId: {PlaylistId}; AddedCount: {AddedCount}")]
|
||||
public sealed record PlaylistEntriesAddedDto(
|
||||
Guid PlaylistId,
|
||||
int AddedCount,
|
||||
DateTime? UpdatedOnUtc
|
||||
);
|
||||
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for an entry appended to a playlist.
|
||||
/// </summary>
|
||||
/// <param name="PlaylistId">The Id of the playlist the entry was added to.</param>
|
||||
/// <param name="Entry">The added entry.</param>
|
||||
/// <param name="UpdatedOnUtc">The date and time when the playlist was last updated, if applicable.</param>
|
||||
[DebuggerDisplay("PlaylistId: {PlaylistId}; Entry: {Entry.Id}")]
|
||||
public sealed record PlaylistEntryAddedDto(
|
||||
Guid PlaylistId,
|
||||
PlaylistEntryDto Entry,
|
||||
DateTime? UpdatedOnUtc
|
||||
);
|
||||
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Playlists;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for an ordered playlist entry together with the display details of the media item it references.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the entry.</param>
|
||||
/// <param name="MediaItemId">The Id of the media item referenced by the entry.</param>
|
||||
/// <param name="MediaItemType">The kind of media item referenced by the entry.</param>
|
||||
/// <param name="Position">The zero based position of the entry in the playlist.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the media item, or an empty Guid when the item no longer exists.</param>
|
||||
/// <param name="CollectionId">The Id of the collection that contains the media item, or an empty Guid when the item no longer exists.</param>
|
||||
/// <param name="CreatorId">The Id of the creator of the media item, or an empty Guid when the item no longer exists.</param>
|
||||
/// <param name="MediaItemTitle">The title of the media item, or an empty string when the item no longer exists.</param>
|
||||
/// <param name="CollectionTitle">The title of the collection that contains the media item, or an empty string when the item no longer exists.</param>
|
||||
/// <param name="CreatorName">The name of the creator of the media item, or an empty string when the item no longer exists.</param>
|
||||
/// <param name="DurationInSeconds">The duration of the media item in seconds, or zero when the item no longer exists.</param>
|
||||
/// <param name="CoverPath">The path of the cover art of the collection, if available.</param>
|
||||
[DebuggerDisplay("Id: {Id}; MediaItemId: {MediaItemId}; Position: {Position}")]
|
||||
public sealed record PlaylistEntryDto(
|
||||
Guid Id,
|
||||
Guid MediaItemId,
|
||||
PlaylistMediaItemType MediaItemType,
|
||||
int Position,
|
||||
Guid LibraryId,
|
||||
Guid CollectionId,
|
||||
Guid CreatorId,
|
||||
string MediaItemTitle,
|
||||
string CollectionTitle,
|
||||
string CreatorName,
|
||||
int DurationInSeconds,
|
||||
string? CoverPath
|
||||
);
|
||||
@@ -0,0 +1,21 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the result of moving one entry of a playlist to a new position.
|
||||
/// </summary>
|
||||
/// <param name="PlaylistId">The Id of the playlist whose entry was moved.</param>
|
||||
/// <param name="EntryId">The Id of the moved entry.</param>
|
||||
/// <param name="Position">The new zero based position of the entry.</param>
|
||||
/// <param name="UpdatedOnUtc">The date and time when the playlist was last updated, if applicable.</param>
|
||||
[DebuggerDisplay("PlaylistId: {PlaylistId}; EntryId: {EntryId}; Position: {Position}")]
|
||||
public sealed record PlaylistEntryMovedDto(
|
||||
Guid PlaylistId,
|
||||
Guid EntryId,
|
||||
int Position,
|
||||
DateTime? UpdatedOnUtc
|
||||
);
|
||||
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Playlists;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a playlist in a list, without its entries.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the playlist.</param>
|
||||
/// <param name="Name">The name of the playlist.</param>
|
||||
/// <param name="Description">The description of the playlist, if applicable.</param>
|
||||
/// <param name="Type">The kind of media the playlist holds.</param>
|
||||
/// <param name="EntryCount">The number of entries of the playlist.</param>
|
||||
/// <param name="CreatedOnUtc">The date and time when the playlist was created.</param>
|
||||
/// <param name="UpdatedOnUtc">The date and time when the playlist was last updated, if applicable.</param>
|
||||
[DebuggerDisplay("Id: {Id}; Name: {Name}; EntryCount: {EntryCount}")]
|
||||
public sealed record PlaylistSummaryDto(
|
||||
Guid Id,
|
||||
string Name,
|
||||
string? Description,
|
||||
PlaylistType Type,
|
||||
int EntryCount,
|
||||
DateTime CreatedOnUtc,
|
||||
DateTime? UpdatedOnUtc
|
||||
);
|
||||
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for an artwork provider configured for a media library.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
public class LibraryArtworkProviderDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier of the plugin providing the artwork.
|
||||
/// </summary>
|
||||
public Guid PluginId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the display name of the artwork provider.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the artwork provider is enabled for the media library.
|
||||
/// </summary>
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the rank of the artwork provider, determining the order in which providers are tried.
|
||||
/// </summary>
|
||||
public int Rank { get; set; }
|
||||
}
|
||||
Loaded 100 of 6450 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user