Esempio n. 1
0
    public void Should_Work_With_Path_Prefix_Without_Trailing_Slash()
    {
        var artwork     = "jellyfin://Items/2/Images/3?tag=4";
        var address     = "https://some.jellyfin.server/jellyfin";
        var mediaSource = new JellyfinMediaSource
        {
            Connections = new List <JellyfinConnection>
            {
                new() { Address = address }
            }
        };

        Url url = JellyfinUrl.ForArtwork(Some(mediaSource), artwork);

        url.ToString().Should().Be("https://some.jellyfin.server/jellyfin/Items/2/Images/3?tag=4");
    }
Esempio n. 2
0
    private async Task <IActionResult> GetJellyfinArtwork(string path, CancellationToken cancellationToken)
    {
        Either <BaseError, JellyfinConnectionParametersViewModel> connectionParameters =
            await _mediator.Send(new GetJellyfinConnectionParameters(), cancellationToken);

        return(await connectionParameters.Match <Task <IActionResult> >(
                   Left : _ => new NotFoundResult().AsTask <IActionResult>(),
                   Right : async vm =>
        {
            HttpClient client = _httpClientFactory.CreateClient();

            Url fullPath = JellyfinUrl.ForArtwork(vm.Address, path);
            HttpResponseMessage response = await client.GetAsync(
                fullPath,
                HttpCompletionOption.ResponseHeadersRead,
                cancellationToken);
            Stream stream = await response.Content.ReadAsStreamAsync(cancellationToken);

            return new FileStreamResult(
                stream,
                response.Content.Headers.ContentType?.MediaType ?? "image/jpeg");
        }));
    }