From a41d5fcea4ee082bb49ddac34a1606204e12e8e8 Mon Sep 17 00:00:00 2001 From: crobibero Date: Sun, 19 Apr 2020 17:36:05 -0600 Subject: [PATCH 01/17] Move AttachmentsService to AttachmentsController --- .../Controllers/AttachmentsController.cs | 86 +++++++++++++++++++ .../Attachments/AttachmentService.cs | 63 -------------- MediaBrowser.Api/MediaBrowser.Api.csproj | 4 + 3 files changed, 90 insertions(+), 63 deletions(-) create mode 100644 Jellyfin.Api/Controllers/AttachmentsController.cs delete mode 100644 MediaBrowser.Api/Attachments/AttachmentService.cs diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/AttachmentsController.cs new file mode 100644 index 0000000000..5d48a79b9b --- /dev/null +++ b/Jellyfin.Api/Controllers/AttachmentsController.cs @@ -0,0 +1,86 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Common.Extensions; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.MediaEncoding; +using MediaBrowser.Controller.Net; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Jellyfin.Api.Controllers +{ + /// + /// Attachments controller. + /// + [Route("Videos")] + [Authenticated] + public class AttachmentsController : Controller + { + private readonly ILibraryManager _libraryManager; + private readonly IAttachmentExtractor _attachmentExtractor; + + /// + /// Initializes a new instance of the class. + /// + /// Instance of the interface. + /// Instance of the interface. + public AttachmentsController( + ILibraryManager libraryManager, + IAttachmentExtractor attachmentExtractor) + { + _libraryManager = libraryManager; + _attachmentExtractor = attachmentExtractor; + } + + /// + /// Get video attachment. + /// + /// Video ID. + /// Media Source ID. + /// Attachment Index. + /// Attachment. + [HttpGet("{VideoID}/{MediaSourceID}/Attachments/{Index}")] + [Produces("application/octet-stream")] + [ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)] + public async Task GetAttachment( + [FromRoute] Guid videoId, + [FromRoute] string mediaSourceId, + [FromRoute] 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 = "application/octet-stream"; + if (string.IsNullOrWhiteSpace(attachment.MimeType)) + { + contentType = attachment.MimeType; + } + + return new FileStreamResult(stream, contentType); + } + catch (ResourceNotFoundException e) + { + return StatusCode(StatusCodes.Status404NotFound, e.Message); + } + catch (Exception e) + { + return StatusCode(StatusCodes.Status500InternalServerError, e.Message); + } + } + } +} diff --git a/MediaBrowser.Api/Attachments/AttachmentService.cs b/MediaBrowser.Api/Attachments/AttachmentService.cs deleted file mode 100644 index 1632ca1b06..0000000000 --- a/MediaBrowser.Api/Attachments/AttachmentService.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.MediaEncoding; -using MediaBrowser.Controller.Net; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Services; -using Microsoft.Extensions.Logging; - -namespace MediaBrowser.Api.Attachments -{ - [Route("/Videos/{Id}/{MediaSourceId}/Attachments/{Index}", "GET", Summary = "Gets specified attachment.")] - public class GetAttachment - { - [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] - public Guid Id { get; set; } - - [ApiMember(Name = "MediaSourceId", Description = "MediaSourceId", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] - public string MediaSourceId { get; set; } - - [ApiMember(Name = "Index", Description = "The attachment stream index", IsRequired = true, DataType = "int", ParameterType = "path", Verb = "GET")] - public int Index { get; set; } - } - - public class AttachmentService : BaseApiService - { - private readonly ILibraryManager _libraryManager; - private readonly IAttachmentExtractor _attachmentExtractor; - - public AttachmentService( - ILogger logger, - IServerConfigurationManager serverConfigurationManager, - IHttpResultFactory httpResultFactory, - ILibraryManager libraryManager, - IAttachmentExtractor attachmentExtractor) - : base(logger, serverConfigurationManager, httpResultFactory) - { - _libraryManager = libraryManager; - _attachmentExtractor = attachmentExtractor; - } - - public async Task Get(GetAttachment request) - { - var (attachment, attachmentStream) = await GetAttachment(request).ConfigureAwait(false); - var mime = string.IsNullOrWhiteSpace(attachment.MimeType) ? "application/octet-stream" : attachment.MimeType; - - return ResultFactory.GetResult(Request, attachmentStream, mime); - } - - private Task<(MediaAttachment, Stream)> GetAttachment(GetAttachment request) - { - var item = _libraryManager.GetItemById(request.Id); - - return _attachmentExtractor.GetAttachment(item, - request.MediaSourceId, - request.Index, - CancellationToken.None); - } - } -} diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index 0d62cf8c59..5ca74d4238 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -9,6 +9,10 @@ + + + + netstandard2.1 false From 1fc682541050e074227736f0c8556d53f98228a1 Mon Sep 17 00:00:00 2001 From: crobibero Date: Sun, 19 Apr 2020 17:37:15 -0600 Subject: [PATCH 02/17] nullable --- Jellyfin.Api/Controllers/AttachmentsController.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/AttachmentsController.cs index 5d48a79b9b..f4c1a761fb 100644 --- a/Jellyfin.Api/Controllers/AttachmentsController.cs +++ b/Jellyfin.Api/Controllers/AttachmentsController.cs @@ -1,3 +1,5 @@ +#nullable enable + using System; using System.Threading; using System.Threading.Tasks; From 08eba82bb7bebe277f6b106fa48994bb98c3dd41 Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 21 Apr 2020 07:52:33 -0600 Subject: [PATCH 03/17] Remove exception handler --- Jellyfin.Api/Controllers/AttachmentsController.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/AttachmentsController.cs index f4c1a761fb..aeeaf5cbdc 100644 --- a/Jellyfin.Api/Controllers/AttachmentsController.cs +++ b/Jellyfin.Api/Controllers/AttachmentsController.cs @@ -79,10 +79,6 @@ namespace Jellyfin.Api.Controllers { return StatusCode(StatusCodes.Status404NotFound, e.Message); } - catch (Exception e) - { - return StatusCode(StatusCodes.Status500InternalServerError, e.Message); - } } } } From 466e20ea8cb8c262605d06dc01eff4463559d9b0 Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 21 Apr 2020 13:57:11 -0600 Subject: [PATCH 04/17] move to ActionResult --- Jellyfin.Api/Controllers/AttachmentsController.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/AttachmentsController.cs index aeeaf5cbdc..351401de18 100644 --- a/Jellyfin.Api/Controllers/AttachmentsController.cs +++ b/Jellyfin.Api/Controllers/AttachmentsController.cs @@ -44,10 +44,9 @@ namespace Jellyfin.Api.Controllers /// Attachment. [HttpGet("{VideoID}/{MediaSourceID}/Attachments/{Index}")] [Produces("application/octet-stream")] - [ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)] - public async Task GetAttachment( + public async Task> GetAttachment( [FromRoute] Guid videoId, [FromRoute] string mediaSourceId, [FromRoute] int index) From f3da5dc8b7fef7e5fdeddff941c6d99063a1fd97 Mon Sep 17 00:00:00 2001 From: crobibero Date: Thu, 23 Apr 2020 10:04:37 -0600 Subject: [PATCH 05/17] Fix Authorize attributes --- Jellyfin.Api/Controllers/AttachmentsController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/AttachmentsController.cs index 351401de18..b0cdfb86e9 100644 --- a/Jellyfin.Api/Controllers/AttachmentsController.cs +++ b/Jellyfin.Api/Controllers/AttachmentsController.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.MediaEncoding; -using MediaBrowser.Controller.Net; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -16,7 +16,7 @@ namespace Jellyfin.Api.Controllers /// Attachments controller. /// [Route("Videos")] - [Authenticated] + [Authorize] public class AttachmentsController : Controller { private readonly ILibraryManager _libraryManager; From 7516e3ebbec82b732e8e4355ae108e7030e1e00e Mon Sep 17 00:00:00 2001 From: crobibero Date: Sat, 2 May 2020 17:12:56 -0600 Subject: [PATCH 06/17] Update endpoint docs --- Jellyfin.Api/Controllers/AttachmentsController.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/AttachmentsController.cs index b0cdfb86e9..30fb951cf9 100644 --- a/Jellyfin.Api/Controllers/AttachmentsController.cs +++ b/Jellyfin.Api/Controllers/AttachmentsController.cs @@ -41,7 +41,9 @@ namespace Jellyfin.Api.Controllers /// Video ID. /// Media Source ID. /// Attachment Index. - /// Attachment. + /// Attachment retrieved. + /// Video or attachment not found. + /// An containing the attachment stream on success, or a if the attachment could not be found. [HttpGet("{VideoID}/{MediaSourceID}/Attachments/{Index}")] [Produces("application/octet-stream")] [ProducesResponseType(StatusCodes.Status200OK)] From c4f8ba55f2b3424be4a6ff1044d13327fe36b687 Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 19 May 2020 08:28:02 -0600 Subject: [PATCH 07/17] Rename to AttachmentsController -> VideoAttachmentsController --- ...tachmentsController.cs => VideoAttachmentsController.cs} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename Jellyfin.Api/Controllers/{AttachmentsController.cs => VideoAttachmentsController.cs} (94%) diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/VideoAttachmentsController.cs similarity index 94% rename from Jellyfin.Api/Controllers/AttachmentsController.cs rename to Jellyfin.Api/Controllers/VideoAttachmentsController.cs index 30fb951cf9..69e8473735 100644 --- a/Jellyfin.Api/Controllers/AttachmentsController.cs +++ b/Jellyfin.Api/Controllers/VideoAttachmentsController.cs @@ -17,17 +17,17 @@ namespace Jellyfin.Api.Controllers /// [Route("Videos")] [Authorize] - public class AttachmentsController : Controller + public class VideoAttachmentsController : Controller { private readonly ILibraryManager _libraryManager; private readonly IAttachmentExtractor _attachmentExtractor; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Instance of the interface. /// Instance of the interface. - public AttachmentsController( + public VideoAttachmentsController( ILibraryManager libraryManager, IAttachmentExtractor attachmentExtractor) { From 45d750f10657da8f7914999098ecffcdbfedbd2d Mon Sep 17 00:00:00 2001 From: crobibero Date: Sun, 19 Apr 2020 17:36:05 -0600 Subject: [PATCH 08/17] Move AttachmentsService to AttachmentsController --- .../Controllers/AttachmentsController.cs | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Jellyfin.Api/Controllers/AttachmentsController.cs diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/AttachmentsController.cs new file mode 100644 index 0000000000..5d48a79b9b --- /dev/null +++ b/Jellyfin.Api/Controllers/AttachmentsController.cs @@ -0,0 +1,86 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Common.Extensions; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.MediaEncoding; +using MediaBrowser.Controller.Net; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Jellyfin.Api.Controllers +{ + /// + /// Attachments controller. + /// + [Route("Videos")] + [Authenticated] + public class AttachmentsController : Controller + { + private readonly ILibraryManager _libraryManager; + private readonly IAttachmentExtractor _attachmentExtractor; + + /// + /// Initializes a new instance of the class. + /// + /// Instance of the interface. + /// Instance of the interface. + public AttachmentsController( + ILibraryManager libraryManager, + IAttachmentExtractor attachmentExtractor) + { + _libraryManager = libraryManager; + _attachmentExtractor = attachmentExtractor; + } + + /// + /// Get video attachment. + /// + /// Video ID. + /// Media Source ID. + /// Attachment Index. + /// Attachment. + [HttpGet("{VideoID}/{MediaSourceID}/Attachments/{Index}")] + [Produces("application/octet-stream")] + [ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)] + public async Task GetAttachment( + [FromRoute] Guid videoId, + [FromRoute] string mediaSourceId, + [FromRoute] 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 = "application/octet-stream"; + if (string.IsNullOrWhiteSpace(attachment.MimeType)) + { + contentType = attachment.MimeType; + } + + return new FileStreamResult(stream, contentType); + } + catch (ResourceNotFoundException e) + { + return StatusCode(StatusCodes.Status404NotFound, e.Message); + } + catch (Exception e) + { + return StatusCode(StatusCodes.Status500InternalServerError, e.Message); + } + } + } +} From 8eac528815bc7ab673b361f48b90b3b28ccbc070 Mon Sep 17 00:00:00 2001 From: crobibero Date: Sun, 19 Apr 2020 17:37:15 -0600 Subject: [PATCH 09/17] nullable --- Jellyfin.Api/Controllers/AttachmentsController.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/AttachmentsController.cs index 5d48a79b9b..f4c1a761fb 100644 --- a/Jellyfin.Api/Controllers/AttachmentsController.cs +++ b/Jellyfin.Api/Controllers/AttachmentsController.cs @@ -1,3 +1,5 @@ +#nullable enable + using System; using System.Threading; using System.Threading.Tasks; From 84fcb4926ccce968a920bed7324ef6f037c4f5e1 Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 21 Apr 2020 07:52:33 -0600 Subject: [PATCH 10/17] Remove exception handler --- Jellyfin.Api/Controllers/AttachmentsController.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/AttachmentsController.cs index f4c1a761fb..aeeaf5cbdc 100644 --- a/Jellyfin.Api/Controllers/AttachmentsController.cs +++ b/Jellyfin.Api/Controllers/AttachmentsController.cs @@ -79,10 +79,6 @@ namespace Jellyfin.Api.Controllers { return StatusCode(StatusCodes.Status404NotFound, e.Message); } - catch (Exception e) - { - return StatusCode(StatusCodes.Status500InternalServerError, e.Message); - } } } } From 15e9fbb923b8aa91692cd9c8c68ec7dde638c1e2 Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 21 Apr 2020 13:57:11 -0600 Subject: [PATCH 11/17] move to ActionResult --- Jellyfin.Api/Controllers/AttachmentsController.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/AttachmentsController.cs index aeeaf5cbdc..351401de18 100644 --- a/Jellyfin.Api/Controllers/AttachmentsController.cs +++ b/Jellyfin.Api/Controllers/AttachmentsController.cs @@ -44,10 +44,9 @@ namespace Jellyfin.Api.Controllers /// Attachment. [HttpGet("{VideoID}/{MediaSourceID}/Attachments/{Index}")] [Produces("application/octet-stream")] - [ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)] - public async Task GetAttachment( + public async Task> GetAttachment( [FromRoute] Guid videoId, [FromRoute] string mediaSourceId, [FromRoute] int index) From 177339e8d5f3ad9eea6a3d6cd068e58d637e443d Mon Sep 17 00:00:00 2001 From: crobibero Date: Thu, 23 Apr 2020 10:04:37 -0600 Subject: [PATCH 12/17] Fix Authorize attributes --- Jellyfin.Api/Controllers/AttachmentsController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/AttachmentsController.cs index 351401de18..b0cdfb86e9 100644 --- a/Jellyfin.Api/Controllers/AttachmentsController.cs +++ b/Jellyfin.Api/Controllers/AttachmentsController.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.MediaEncoding; -using MediaBrowser.Controller.Net; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -16,7 +16,7 @@ namespace Jellyfin.Api.Controllers /// Attachments controller. /// [Route("Videos")] - [Authenticated] + [Authorize] public class AttachmentsController : Controller { private readonly ILibraryManager _libraryManager; From 26a2bea179b8c2d8b772b714e6296c03b5c1e0d3 Mon Sep 17 00:00:00 2001 From: crobibero Date: Sat, 2 May 2020 17:12:56 -0600 Subject: [PATCH 13/17] Update endpoint docs --- Jellyfin.Api/Controllers/AttachmentsController.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/AttachmentsController.cs index b0cdfb86e9..30fb951cf9 100644 --- a/Jellyfin.Api/Controllers/AttachmentsController.cs +++ b/Jellyfin.Api/Controllers/AttachmentsController.cs @@ -41,7 +41,9 @@ namespace Jellyfin.Api.Controllers /// Video ID. /// Media Source ID. /// Attachment Index. - /// Attachment. + /// Attachment retrieved. + /// Video or attachment not found. + /// An containing the attachment stream on success, or a if the attachment could not be found. [HttpGet("{VideoID}/{MediaSourceID}/Attachments/{Index}")] [Produces("application/octet-stream")] [ProducesResponseType(StatusCodes.Status200OK)] From a7a725173da0be952e0a7407f9f42f1ea1123f84 Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 19 May 2020 08:28:02 -0600 Subject: [PATCH 14/17] Rename to AttachmentsController -> VideoAttachmentsController --- .../Controllers/AttachmentsController.cs | 85 ------------------- 1 file changed, 85 deletions(-) delete mode 100644 Jellyfin.Api/Controllers/AttachmentsController.cs diff --git a/Jellyfin.Api/Controllers/AttachmentsController.cs b/Jellyfin.Api/Controllers/AttachmentsController.cs deleted file mode 100644 index 30fb951cf9..0000000000 --- a/Jellyfin.Api/Controllers/AttachmentsController.cs +++ /dev/null @@ -1,85 +0,0 @@ -#nullable enable - -using System; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Common.Extensions; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.MediaEncoding; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; - -namespace Jellyfin.Api.Controllers -{ - /// - /// Attachments controller. - /// - [Route("Videos")] - [Authorize] - public class AttachmentsController : Controller - { - private readonly ILibraryManager _libraryManager; - private readonly IAttachmentExtractor _attachmentExtractor; - - /// - /// Initializes a new instance of the class. - /// - /// Instance of the interface. - /// Instance of the interface. - public AttachmentsController( - ILibraryManager libraryManager, - IAttachmentExtractor attachmentExtractor) - { - _libraryManager = libraryManager; - _attachmentExtractor = attachmentExtractor; - } - - /// - /// Get video attachment. - /// - /// Video ID. - /// Media Source ID. - /// Attachment Index. - /// Attachment retrieved. - /// Video or attachment not found. - /// An containing the attachment stream on success, or a if the attachment could not be found. - [HttpGet("{VideoID}/{MediaSourceID}/Attachments/{Index}")] - [Produces("application/octet-stream")] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task> GetAttachment( - [FromRoute] Guid videoId, - [FromRoute] string mediaSourceId, - [FromRoute] 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 = "application/octet-stream"; - if (string.IsNullOrWhiteSpace(attachment.MimeType)) - { - contentType = attachment.MimeType; - } - - return new FileStreamResult(stream, contentType); - } - catch (ResourceNotFoundException e) - { - return StatusCode(StatusCodes.Status404NotFound, e.Message); - } - } - } -} From b28dd47a0fc5b18111678acede335474f9007b8f Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 19 May 2020 12:58:09 -0600 Subject: [PATCH 15/17] implement review suggestions --- Jellyfin.Api/Controllers/VideoAttachmentsController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jellyfin.Api/Controllers/VideoAttachmentsController.cs b/Jellyfin.Api/Controllers/VideoAttachmentsController.cs index 69e8473735..a10dd40593 100644 --- a/Jellyfin.Api/Controllers/VideoAttachmentsController.cs +++ b/Jellyfin.Api/Controllers/VideoAttachmentsController.cs @@ -78,7 +78,7 @@ namespace Jellyfin.Api.Controllers } catch (ResourceNotFoundException e) { - return StatusCode(StatusCodes.Status404NotFound, e.Message); + return NotFound(e.Message); } } } From 51d54a8ca40f987bce877ad1d7dc78b1cb26b8a3 Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 19 May 2020 13:02:02 -0600 Subject: [PATCH 16/17] Fix return content type --- .../Controllers/VideoAttachmentsController.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Jellyfin.Api/Controllers/VideoAttachmentsController.cs b/Jellyfin.Api/Controllers/VideoAttachmentsController.cs index a10dd40593..596d211900 100644 --- a/Jellyfin.Api/Controllers/VideoAttachmentsController.cs +++ b/Jellyfin.Api/Controllers/VideoAttachmentsController.cs @@ -1,11 +1,13 @@ #nullable enable using System; +using System.Net.Mime; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.MediaEncoding; +using MediaBrowser.Model.Net; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -17,7 +19,7 @@ namespace Jellyfin.Api.Controllers /// [Route("Videos")] [Authorize] - public class VideoAttachmentsController : Controller + public class VideoAttachmentsController : BaseJellyfinApiController { private readonly ILibraryManager _libraryManager; private readonly IAttachmentExtractor _attachmentExtractor; @@ -45,7 +47,7 @@ namespace Jellyfin.Api.Controllers /// Video or attachment not found. /// An containing the attachment stream on success, or a if the attachment could not be found. [HttpGet("{VideoID}/{MediaSourceID}/Attachments/{Index}")] - [Produces("application/octet-stream")] + [Produces(MediaTypeNames.Application.Octet)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task> GetAttachment( @@ -68,11 +70,9 @@ namespace Jellyfin.Api.Controllers CancellationToken.None) .ConfigureAwait(false); - var contentType = "application/octet-stream"; - if (string.IsNullOrWhiteSpace(attachment.MimeType)) - { - contentType = attachment.MimeType; - } + var contentType = string.IsNullOrWhiteSpace(attachment.MimeType) + ? MediaTypeNames.Application.Octet + : attachment.MimeType; return new FileStreamResult(stream, contentType); } From 2689865858c779491c98066df3f1e7d894f7c3b8 Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 19 May 2020 13:02:35 -0600 Subject: [PATCH 17/17] Remove unused using --- Jellyfin.Api/Controllers/VideoAttachmentsController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Jellyfin.Api/Controllers/VideoAttachmentsController.cs b/Jellyfin.Api/Controllers/VideoAttachmentsController.cs index 596d211900..86d9322fe4 100644 --- a/Jellyfin.Api/Controllers/VideoAttachmentsController.cs +++ b/Jellyfin.Api/Controllers/VideoAttachmentsController.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.MediaEncoding; -using MediaBrowser.Model.Net; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc;