Exemple #1
0
        public async Task <ActionResult> GetAttachment(
            [FromRoute, Required] Guid videoId,
            [FromRoute, Required] string mediaSourceId,
            [FromRoute, Required] int index)
        {
            try
            {
                var item = _libraryManager.GetItemById(videoId);
                if (item == null)
                {
                    return(NotFound());
                }

                var(attachment, stream) = await _attachmentExtractor.GetAttachment(
                    item,
                    mediaSourceId,
                    index,
                    CancellationToken.None)
                                          .ConfigureAwait(false);

                var contentType = string.IsNullOrWhiteSpace(attachment.MimeType)
                    ? MediaTypeNames.Application.Octet
                    : attachment.MimeType;

                return(new FileStreamResult(stream, contentType));
            }
            catch (ResourceNotFoundException e)
            {
                return(NotFound(e.Message));
            }
        }
Exemple #2
0
        private Task <(MediaAttachment, Stream)> GetAttachment(GetAttachment request)
        {
            var item = _libraryManager.GetItemById(request.Id);

            return(_attachmentExtractor.GetAttachment(item,
                                                      request.MediaSourceId,
                                                      request.Index,
                                                      CancellationToken.None));
        }