Beispiel #1
0
        public object Get(GetShareImage request)
        {
            var share = _sharingManager.GetShareInfo(request.Id);

            if (share == null)
            {
                throw new ResourceNotFoundException();
            }
            if (share.ExpirationDate <= DateTime.UtcNow)
            {
                throw new ResourceNotFoundException();
            }

            var item = _libraryManager.GetItemById(share.ItemId);

            var image = item.GetImageInfo(ImageType.Primary, 0);

            if (image != null)
            {
                return(ToStaticFileResult(image.Path));
            }

            // Grab a dlna icon if nothing else is available
            using (var response = _dlnaManager.GetIcon("logo240.jpg"))
            {
                using (var ms = new MemoryStream())
                {
                    response.Stream.CopyTo(ms);

                    ms.Position = 0;
                    var bytes = ms.ToArray();
                    return(ResultFactory.GetResult(bytes, "image/" + response.Format.ToString().ToLower()));
                }
            }
        }
Beispiel #2
0
        public async Task <object> Get(GetShareImage request)
        {
            var share = _sharingManager.GetShareInfo(request.Id);

            if (share == null)
            {
                throw new ResourceNotFoundException();
            }
            if (share.ExpirationDate <= DateTime.UtcNow)
            {
                throw new ResourceNotFoundException();
            }

            var item = _libraryManager.GetItemById(share.ItemId);

            var image = item.GetImageInfo(ImageType.Primary, 0);

            if (image != null)
            {
                if (image.IsLocalFile)
                {
                    return(await _resultFactory.GetStaticFileResult(Request, image.Path).ConfigureAwait(false));
                }

                try
                {
                    // Don't fail the request over this
                    var updatedImage = await _libraryManager.ConvertImageToLocal(item, image, 0).ConfigureAwait(false);

                    return(await _resultFactory.GetStaticFileResult(Request, updatedImage.Path).ConfigureAwait(false));
                }
                catch
                {
                }
            }

            // Grab a dlna icon if nothing else is available
            using (var response = _dlnaManager.GetIcon("logo240.jpg"))
            {
                using (var ms = new MemoryStream())
                {
                    response.Stream.CopyTo(ms);

                    ms.Position = 0;
                    var bytes = ms.ToArray();
                    return(ResultFactory.GetResult(bytes, "image/" + response.Format.ToString().ToLower()));
                }
            }
        }