using System.Net; using System.Net.Http.Headers; using Jellyfin.Plugin.YandexMusic.Yandex; namespace Jellyfin.Plugin.YandexMusic.Providers; /// Creates image responses for search results. internal static class ImageResponseFactory { /// Downloads an image and wraps it into an HTTP response. public static async Task FromUrlAsync( YandexMusicClient client, string url, CancellationToken cancellationToken) { var bytes = await client.GetImageBytesAsync(url, cancellationToken).ConfigureAwait(false); if (bytes is null) { return new HttpResponseMessage(HttpStatusCode.NotFound); } var content = new ByteArrayContent(bytes); content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg"); return new HttpResponseMessage(HttpStatusCode.OK) { Content = content }; } }