Adds music player consumption reporting and its Web proxy endpoints

This commit is contained in:
BinaryAlley committed 2026-10-25 18:08:44 +02:00
1 parent 00d7eff777
commit bfa7b190b2
20 files changed
+1599 -21

No files matched your search

@@ -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,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,22 @@
namespace Lumina.Presentation.Web.Common.Enums.MediaConsumption;
/// <summary>
/// Enumeration for the states of a media consumption session.
/// </summary>
public enum ConsumptionStatus
{
/// <summary>
/// The consumption session started and has not ended yet.
/// </summary>
InProgress,
/// <summary>
/// The consumption session reached its explicit completion or the completion threshold of its library.
/// </summary>
Completed,
/// <summary>
/// The consumption session ended before it completed.
/// </summary>
Stopped
}
@@ -0,0 +1,17 @@
namespace Lumina.Presentation.Web.Common.Enums.MediaConsumption;
/// <summary>
/// Enumeration for the kinds of position that a media consumption session can report.
/// </summary>
public enum MediaPositionKind
{
/// <summary>
/// The position is a time offset within the media item.
/// </summary>
TimeOffset,
/// <summary>
/// The position is an opaque locator within the media item, such as a reading location of a book.
/// </summary>
Location
}
@@ -0,0 +1,18 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.Requests.MediaConsumption;
/// <summary>
/// Represents a request to report that a media consumption session completed.
/// </summary>
/// <param name="Position">The final position reported for the media item, if the client knows it. Optional.</param>
/// <param name="ProgressFraction">The fraction of the media item that the client reached, between 0 and 1. Required.</param>
/// <param name="ConsumedDurationInSeconds">The active duration consumed by the session, in seconds. Required.</param>
[DebuggerDisplay("ProgressFraction: {ProgressFraction}; ConsumedDurationInSeconds: {ConsumedDurationInSeconds}")]
public sealed record CompleteConsumptionRequest(
MediaPositionRequest? Position,
double? ProgressFraction,
double? ConsumedDurationInSeconds
);
@@ -0,0 +1,18 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.Requests.MediaConsumption;
/// <summary>
/// Represents a request to report a position in a media consumption session.
/// </summary>
/// <param name="Kind">The kind of the position. Required.</param>
/// <param name="TimeOffsetSeconds">The position within the media item, in seconds, when the position is a time offset. Optional.</param>
/// <param name="Location">The opaque locator within the media item, when the position is not a time offset. Optional.</param>
[DebuggerDisplay("Kind: {Kind}; TimeOffsetSeconds: {TimeOffsetSeconds}")]
public sealed record MediaPositionRequest(
string? Kind,
double? TimeOffsetSeconds,
string? Location
);
@@ -0,0 +1,20 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.Requests.MediaConsumption;
/// <summary>
/// Represents a request to report the progress of a media consumption session.
/// </summary>
/// <param name="Position">The last position reported for the media item, if the client knows it. Optional.</param>
/// <param name="ProgressFraction">The fraction of the media item that the client reached, between 0 and 1. Required.</param>
/// <param name="ConsumedDurationInSeconds">The active duration consumed by the session, in seconds. Required.</param>
/// <param name="ConsecutivePagesRead">The number of consecutive pages read in the current session, used by page based media such as books and ignored for other kinds. Defaults to 0. Optional.</param>
[DebuggerDisplay("ProgressFraction: {ProgressFraction}; ConsumedDurationInSeconds: {ConsumedDurationInSeconds}; ConsecutivePagesRead: {ConsecutivePagesRead}")]
public sealed record ReportConsumptionProgressRequest(
MediaPositionRequest? Position,
double? ProgressFraction,
double? ConsumedDurationInSeconds,
int ConsecutivePagesRead = 0
);
@@ -0,0 +1,18 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Presentation.Web.Common.Requests.MediaConsumption;
/// <summary>
/// Represents a request to report that a media consumption session stopped.
/// </summary>
/// <param name="Position">The final position reported for the media item, if the client knows it. Optional.</param>
/// <param name="ProgressFraction">The fraction of the media item that the client reached, between 0 and 1. Required.</param>
/// <param name="ConsumedDurationInSeconds">The active duration consumed by the session, in seconds. Required.</param>
[DebuggerDisplay("ProgressFraction: {ProgressFraction}; ConsumedDurationInSeconds: {ConsumedDurationInSeconds}")]
public sealed record StopConsumptionRequest(
MediaPositionRequest? Position,
double? ProgressFraction,
double? ConsumedDurationInSeconds
);
@@ -0,0 +1,18 @@
namespace Lumina.Presentation.Web.Common.Routes;
/// <summary>
/// Class for the collection of remote API routes called by this Web application.
/// </summary>
public static partial class ApiRoutes
{
/// <summary>
/// Routes for the media consumption lifecycle endpoints of the remote API.
/// </summary>
public static class MediaConsumption
{
public const string START_CONSUMPTION = "libraries/{libraryId}/media-items/{mediaKind}/{mediaItemId}/consumption-records";
public const string REPORT_CONSUMPTION_PROGRESS = "users/me/consumption-records/{recordId}/progress";
public const string COMPLETE_CONSUMPTION = "users/me/consumption-records/{recordId}/complete";
public const string STOP_CONSUMPTION = "users/me/consumption-records/{recordId}/stop";
}
}
@@ -0,0 +1,18 @@
namespace Lumina.Presentation.Web.Common.Routes;
/// <summary>
/// Class for the collection of routes defined in the Web application.
/// </summary>
public static partial class WebRoutes
{
/// <summary>
/// Routes for the media consumption lifecycle actions the browser clients report to, proxied to the remote API.
/// </summary>
public static class MediaConsumption
{
public const string START_CONSUMPTION = "{culture}/media-consumption/api-start-consumption/{libraryId}/{mediaKind}/{mediaItemId}";
public const string REPORT_CONSUMPTION_PROGRESS = "{culture}/media-consumption/api-report-consumption-progress/{recordId}";
public const string COMPLETE_CONSUMPTION = "{culture}/media-consumption/api-complete-consumption/{recordId}";
public const string STOP_CONSUMPTION = "{culture}/media-consumption/api-stop-consumption/{recordId}";
}
}