Add waveform profile HTTP transport: API endpoint, public proxy, content client method
This commit is contained in:
@@ -106,4 +106,38 @@ public class TrackProxyController : ControllerBase
|
||||
HttpContext.Response.RegisterForDispose(upstream);
|
||||
return File(stream, contentType, enableRangeProcessing: false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Proxies a track's stored waveform profile (JSON) from DeepDrftAPI. Unauthenticated,
|
||||
/// same posture as the audio stream forward. The profile is small JSON, so it is buffered
|
||||
/// and relayed rather than streamed; a 404 from upstream (no profile stored) passes through.
|
||||
/// </summary>
|
||||
[HttpGet("{trackId}/waveform")]
|
||||
public async Task<ActionResult> GetWaveform(string trackId, CancellationToken ct = default)
|
||||
{
|
||||
var path = $"api/track/{Uri.EscapeDataString(trackId)}/waveform";
|
||||
|
||||
HttpResponseMessage upstream;
|
||||
try
|
||||
{
|
||||
upstream = await _upstream.GetAsync(path, HttpCompletionOption.ResponseHeadersRead, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Upstream call to DeepDrftAPI track/{TrackId}/waveform failed", trackId);
|
||||
return StatusCode(502, "Upstream unavailable");
|
||||
}
|
||||
|
||||
using (upstream)
|
||||
{
|
||||
if (!upstream.IsSuccessStatusCode)
|
||||
{
|
||||
_logger.LogWarning("DeepDrftAPI track/{TrackId}/waveform returned {Status}", trackId, (int)upstream.StatusCode);
|
||||
return StatusCode((int)upstream.StatusCode);
|
||||
}
|
||||
|
||||
var json = await upstream.Content.ReadAsStringAsync(ct);
|
||||
return Content(json, "application/json");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user