diff options
| author | Cody Robibero <cody@robibe.ro> | 2024-02-28 17:09:23 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-28 17:09:23 -0700 |
| commit | f3c333f4d5bb272b5ffcff29af337ca31e8c374b (patch) | |
| tree | 008525e157be39a25e013fd3b039d4680760eb68 /Jellyfin.Api/Controllers/SubtitleController.cs | |
| parent | 54eb81395ef8d3d4cb064b56361ce94fc72b38b5 (diff) | |
| parent | 4f0f364ac941dc4a856512c9bf0e6b93fdf7b3ab (diff) | |
Merge branch 'master' into bhowe34/fix-replace-missing-metadata-for-music
Diffstat (limited to 'Jellyfin.Api/Controllers/SubtitleController.cs')
| -rw-r--r-- | Jellyfin.Api/Controllers/SubtitleController.cs | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/Jellyfin.Api/Controllers/SubtitleController.cs b/Jellyfin.Api/Controllers/SubtitleController.cs index 49ca058bd..cc2a630e1 100644 --- a/Jellyfin.Api/Controllers/SubtitleController.cs +++ b/Jellyfin.Api/Controllers/SubtitleController.cs @@ -11,7 +11,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Jellyfin.Api.Attributes; -using Jellyfin.Api.Constants; using Jellyfin.Api.Extensions; using Jellyfin.Api.Models.SubtitleDtos; using MediaBrowser.Common.Api; @@ -162,17 +161,17 @@ public class SubtitleController : BaseJellyfinApiController /// <summary> /// Gets the remote subtitles. /// </summary> - /// <param name="id">The item id.</param> + /// <param name="subtitleId">The item id.</param> /// <response code="200">File returned.</response> /// <returns>A <see cref="FileStreamResult"/> with the subtitle file.</returns> - [HttpGet("Providers/Subtitles/Subtitles/{id}")] + [HttpGet("Providers/Subtitles/Subtitles/{subtitleId}")] [Authorize] [ProducesResponseType(StatusCodes.Status200OK)] [Produces(MediaTypeNames.Application.Octet)] [ProducesFile("text/*")] - public async Task<ActionResult> GetRemoteSubtitles([FromRoute, Required] string id) + public async Task<ActionResult> GetRemoteSubtitles([FromRoute, Required] string subtitleId) { - var result = await _subtitleManager.GetRemoteSubtitles(id, CancellationToken.None).ConfigureAwait(false); + var result = await _subtitleManager.GetRemoteSubtitles(subtitleId, CancellationToken.None).ConfigureAwait(false); return File(result.Stream, MimeTypes.GetMimeType("file." + result.Format)); } @@ -407,22 +406,29 @@ public class SubtitleController : BaseJellyfinApiController [FromBody, Required] UploadSubtitleDto body) { var video = (Video)_libraryManager.GetItemById(itemId); - var stream = new CryptoStream(Request.Body, new FromBase64Transform(), CryptoStreamMode.Read); - await using (stream.ConfigureAwait(false)) - { - await _subtitleManager.UploadSubtitle( - video, - new SubtitleResponse - { - Format = body.Format, - Language = body.Language, - IsForced = body.IsForced, - IsHearingImpaired = body.IsHearingImpaired, - Stream = stream - }).ConfigureAwait(false); - _providerManager.QueueRefresh(video.Id, new MetadataRefreshOptions(new DirectoryService(_fileSystem)), RefreshPriority.High); - return NoContent(); + var bytes = Encoding.UTF8.GetBytes(body.Data); + var memoryStream = new MemoryStream(bytes, 0, bytes.Length, false, true); + await using (memoryStream.ConfigureAwait(false)) + { + using var transform = new FromBase64Transform(); + var stream = new CryptoStream(memoryStream, transform, CryptoStreamMode.Read); + await using (stream.ConfigureAwait(false)) + { + await _subtitleManager.UploadSubtitle( + video, + new SubtitleResponse + { + Format = body.Format, + Language = body.Language, + IsForced = body.IsForced, + IsHearingImpaired = body.IsHearingImpaired, + Stream = stream + }).ConfigureAwait(false); + _providerManager.QueueRefresh(video.Id, new MetadataRefreshOptions(new DirectoryService(_fileSystem)), RefreshPriority.High); + + return NoContent(); + } } } |
