feat: Stream Now instant-play of a random track from the nav button
This commit is contained in:
@@ -51,6 +51,32 @@ public class TrackClient
|
||||
: ApiResult<PagedResult<TrackDto>>.CreateFailResult("Failed to deserialize response");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches a random track from the public library. A 404 means the library is empty — a valid
|
||||
/// state, not an error — so it returns a pass result with a null value. Any other non-success
|
||||
/// status is a genuine failure.
|
||||
/// </summary>
|
||||
public async Task<ApiResult<TrackDto?>> GetRandom()
|
||||
{
|
||||
var response = await _http.GetAsync("api/track/random");
|
||||
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
||||
return ApiResult<TrackDto?>.CreatePassResult(null);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return ApiResult<TrackDto?>.CreateFailResult($"HTTP {(int)response.StatusCode}");
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
var track = JsonSerializer.Deserialize<TrackDto>(json, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
|
||||
return track is not null
|
||||
? ApiResult<TrackDto?>.CreatePassResult(track)
|
||||
: ApiResult<TrackDto?>.CreateFailResult("Failed to deserialize response");
|
||||
}
|
||||
|
||||
public async Task<ApiResult<TrackDto>> GetTrack(string entryKey)
|
||||
{
|
||||
var response = await _http.GetAsync($"api/track/meta/by-key/{Uri.EscapeDataString(entryKey)}");
|
||||
|
||||
Reference in New Issue
Block a user