Improved token refresh mechanism
This commit is contained in:
@@ -34,7 +34,7 @@ public class StreamProxyController : ControllerBase
|
||||
/// <summary>
|
||||
/// Proxies HLS master manifest requests.
|
||||
/// </summary>
|
||||
/// <param name="itemId">The item ID.</param>
|
||||
/// <param name="itemId">The item ID from URL path.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>The HLS manifest with rewritten URLs.</returns>
|
||||
[HttpGet("{itemId}/master.m3u8")]
|
||||
@@ -47,12 +47,15 @@ public class StreamProxyController : ControllerBase
|
||||
{
|
||||
_logger.LogInformation("Proxy request for master manifest - ItemId: {ItemId}", itemId);
|
||||
|
||||
// Try to resolve the actual item ID (path ID might be a session ID during transcoding)
|
||||
var actualItemId = ResolveItemId(itemId);
|
||||
|
||||
try
|
||||
{
|
||||
// Build the base proxy URL for this item
|
||||
// Build the base proxy URL for this item (use original itemId from path to maintain URL structure)
|
||||
var baseProxyUrl = $"{Request.Scheme}://{Request.Host}/Plugins/SRFPlay/Proxy/{itemId}";
|
||||
|
||||
var manifestContent = await _proxyService.GetRewrittenManifestAsync(itemId, baseProxyUrl, cancellationToken).ConfigureAwait(false);
|
||||
var manifestContent = await _proxyService.GetRewrittenManifestAsync(actualItemId, baseProxyUrl, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (manifestContent == null)
|
||||
{
|
||||
@@ -89,10 +92,13 @@ public class StreamProxyController : ControllerBase
|
||||
var fullPath = $"{manifestPath}.m3u8";
|
||||
_logger.LogInformation("Proxy request for variant manifest - ItemId: {ItemId}, Path: {Path}", itemId, fullPath);
|
||||
|
||||
// Try to resolve the actual item ID
|
||||
var actualItemId = ResolveItemId(itemId);
|
||||
|
||||
try
|
||||
{
|
||||
// Fetch the variant manifest as a segment
|
||||
var manifestData = await _proxyService.GetSegmentAsync(itemId, fullPath, cancellationToken).ConfigureAwait(false);
|
||||
var manifestData = await _proxyService.GetSegmentAsync(actualItemId, fullPath, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (manifestData == null)
|
||||
{
|
||||
@@ -133,9 +139,12 @@ public class StreamProxyController : ControllerBase
|
||||
{
|
||||
_logger.LogDebug("Proxy request for segment - ItemId: {ItemId}, Path: {SegmentPath}", itemId, segmentPath);
|
||||
|
||||
// Try to resolve the actual item ID
|
||||
var actualItemId = ResolveItemId(itemId);
|
||||
|
||||
try
|
||||
{
|
||||
var segmentData = await _proxyService.GetSegmentAsync(itemId, segmentPath, cancellationToken).ConfigureAwait(false);
|
||||
var segmentData = await _proxyService.GetSegmentAsync(actualItemId, segmentPath, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (segmentData == null)
|
||||
{
|
||||
@@ -156,6 +165,24 @@ public class StreamProxyController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the actual item ID from the request.
|
||||
/// </summary>
|
||||
/// <param name="pathItemId">The item ID from the URL path.</param>
|
||||
/// <returns>The resolved item ID.</returns>
|
||||
private string ResolveItemId(string pathItemId)
|
||||
{
|
||||
// Check if there's an itemId query parameter (fallback for transcoding sessions)
|
||||
if (Request.Query.TryGetValue("itemId", out var queryItemId) && !string.IsNullOrEmpty(queryItemId))
|
||||
{
|
||||
_logger.LogDebug("Using itemId from query parameter: {QueryItemId} (path had: {PathItemId})", queryItemId.ToString(), pathItemId);
|
||||
return queryItemId.ToString();
|
||||
}
|
||||
|
||||
// Use the path item ID as-is
|
||||
return pathItemId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rewrites segment URLs in a manifest to point to proxy.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user