diff options
| author | Joshua M. Boniface <joshua@boniface.me> | 2020-11-21 17:20:31 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-21 17:20:31 -0500 |
| commit | bf54b5579c15bdf8bb6e3dd6934ea23c45a62573 (patch) | |
| tree | 1b2df4bdf89a70f578b72240969416034afc33db /Jellyfin.Api/Controllers/ItemLookupController.cs | |
| parent | 4a81ee43dc7aed94012c312a8262a1426be9b6d9 (diff) | |
| parent | b707d8e09d776a1dd1f0cdd6cf13cd1f3e638028 (diff) | |
Merge branch 'master' into defer_image_fetching
Diffstat (limited to 'Jellyfin.Api/Controllers/ItemLookupController.cs')
| -rw-r--r-- | Jellyfin.Api/Controllers/ItemLookupController.cs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Jellyfin.Api/Controllers/ItemLookupController.cs b/Jellyfin.Api/Controllers/ItemLookupController.cs index ab73aa428..6c38f77ce 100644 --- a/Jellyfin.Api/Controllers/ItemLookupController.cs +++ b/Jellyfin.Api/Controllers/ItemLookupController.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.IO; @@ -334,10 +334,16 @@ namespace Jellyfin.Api.Controllers private async Task DownloadImage(string providerName, string url, Guid urlHash, string pointerCachePath) { using var result = await _providerManager.GetSearchImage(providerName, url, CancellationToken.None).ConfigureAwait(false); + if (result.Content.Headers.ContentType?.MediaType == null) + { + throw new ResourceNotFoundException(nameof(result.Content.Headers.ContentType)); + } + var ext = result.Content.Headers.ContentType.MediaType.Split('/')[^1]; var fullCachePath = GetFullCachePath(urlHash + "." + ext); - Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath)); + var directory = Path.GetDirectoryName(fullCachePath) ?? throw new ResourceNotFoundException($"Provided path ({fullCachePath}) is not valid."); + Directory.CreateDirectory(directory); using (var stream = result.Content) { await using var fileStream = new FileStream( @@ -351,7 +357,9 @@ namespace Jellyfin.Api.Controllers await stream.CopyToAsync(fileStream).ConfigureAwait(false); } - Directory.CreateDirectory(Path.GetDirectoryName(pointerCachePath)); + var pointerCacheDirectory = Path.GetDirectoryName(pointerCachePath) ?? throw new ArgumentException($"Provided path ({pointerCachePath}) is not valid.", nameof(pointerCachePath)); + + Directory.CreateDirectory(pointerCacheDirectory); await System.IO.File.WriteAllTextAsync(pointerCachePath, fullCachePath).ConfigureAwait(false); } |
