From 30b29f63c470eb0e92c53ad7df67d6bcf8a25914 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 29 Dec 2013 09:54:11 -0500 Subject: [PATCH] be more tolerant of media folder names with invalid url chars --- .../Library/LibraryStructureService.cs | 50 +++++++++++++++---- MediaBrowser.Controller/Entities/User.cs | 1 - .../MediaBrowser.Providers.csproj | 2 +- .../Studios/StudioImageProvider.cs | 19 +++++-- .../Studios/StudiosManualImageProvider.cs | 2 +- .../Studios/{backdrops.txt => thumbs.txt} | 0 MediaBrowser.WebDashboard/ApiClient.js | 22 ++++---- MediaBrowser.WebDashboard/packages.config | 2 +- 8 files changed, 69 insertions(+), 29 deletions(-) rename MediaBrowser.Providers/Studios/{backdrops.txt => thumbs.txt} (100%) diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs index c964b55171..7759073798 100644 --- a/MediaBrowser.Api/Library/LibraryStructureService.cs +++ b/MediaBrowser.Api/Library/LibraryStructureService.cs @@ -28,8 +28,8 @@ namespace MediaBrowser.Api.Library public string UserId { get; set; } } - [Route("/Library/VirtualFolders/{Name}", "POST")] - [Route("/Users/{UserId}/VirtualFolders/{Name}", "POST")] + [Route("/Library/VirtualFolders", "POST")] + [Route("/Users/{UserId}/VirtualFolders", "POST")] public class AddVirtualFolder : IReturnVoid { /// @@ -57,8 +57,8 @@ namespace MediaBrowser.Api.Library public bool RefreshLibrary { get; set; } } - [Route("/Library/VirtualFolders/{Name}", "DELETE")] - [Route("/Users/{UserId}/VirtualFolders/{Name}", "DELETE")] + [Route("/Library/VirtualFolders", "DELETE")] + [Route("/Users/{UserId}/VirtualFolders", "DELETE")] public class RemoveVirtualFolder : IReturnVoid { /// @@ -80,8 +80,8 @@ namespace MediaBrowser.Api.Library public bool RefreshLibrary { get; set; } } - [Route("/Library/VirtualFolders/{Name}/Name", "POST")] - [Route("/Users/{UserId}/VirtualFolders/{Name}/Name", "POST")] + [Route("/Library/VirtualFolders/Name", "POST")] + [Route("/Users/{UserId}/VirtualFolders/Name", "POST")] public class RenameVirtualFolder : IReturnVoid { /// @@ -109,8 +109,8 @@ namespace MediaBrowser.Api.Library public bool RefreshLibrary { get; set; } } - [Route("/Library/VirtualFolders/{Name}/Paths", "POST")] - [Route("/Users/{UserId}/VirtualFolders/{Name}/Paths", "POST")] + [Route("/Library/VirtualFolders/Paths", "POST")] + [Route("/Users/{UserId}/VirtualFolders/Paths", "POST")] public class AddMediaPath : IReturnVoid { /// @@ -138,8 +138,8 @@ namespace MediaBrowser.Api.Library public bool RefreshLibrary { get; set; } } - [Route("/Library/VirtualFolders/{Name}/Paths", "DELETE")] - [Route("/Users/{UserId}/VirtualFolders/{Name}/Paths", "DELETE")] + [Route("/Library/VirtualFolders/Paths", "DELETE")] + [Route("/Users/{UserId}/VirtualFolders/Paths", "DELETE")] public class RemoveMediaPath : IReturnVoid { /// @@ -243,6 +243,11 @@ namespace MediaBrowser.Api.Library /// The request. public void Post(AddVirtualFolder request) { + if (string.IsNullOrWhiteSpace(request.Name)) + { + throw new ArgumentNullException("request"); + } + var name = _fileSystem.GetValidFilename(request.Name); string rootFolderPath; @@ -307,6 +312,16 @@ namespace MediaBrowser.Api.Library /// The request. public void Post(RenameVirtualFolder request) { + if (string.IsNullOrWhiteSpace(request.Name)) + { + throw new ArgumentNullException("request"); + } + + if (string.IsNullOrWhiteSpace(request.NewName)) + { + throw new ArgumentNullException("request"); + } + string rootFolderPath; if (string.IsNullOrEmpty(request.UserId)) @@ -380,6 +395,11 @@ namespace MediaBrowser.Api.Library /// The request. public void Delete(RemoveVirtualFolder request) { + if (string.IsNullOrWhiteSpace(request.Name)) + { + throw new ArgumentNullException("request"); + } + string rootFolderPath; if (string.IsNullOrEmpty(request.UserId)) @@ -435,6 +455,11 @@ namespace MediaBrowser.Api.Library /// The request. public void Post(AddMediaPath request) { + if (string.IsNullOrWhiteSpace(request.Name)) + { + throw new ArgumentNullException("request"); + } + _directoryWatchers.Stop(); try @@ -476,6 +501,11 @@ namespace MediaBrowser.Api.Library /// The request. public void Delete(RemoveMediaPath request) { + if (string.IsNullOrWhiteSpace(request.Name)) + { + throw new ArgumentNullException("request"); + } + _directoryWatchers.Stop(); try diff --git a/MediaBrowser.Controller/Entities/User.cs b/MediaBrowser.Controller/Entities/User.cs index a2c7bcb576..0a935cd0de 100644 --- a/MediaBrowser.Controller/Entities/User.cs +++ b/MediaBrowser.Controller/Entities/User.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.Configuration; -using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Serialization; diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj index 60a3ec1634..94d171ce14 100644 --- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj +++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj @@ -168,7 +168,7 @@ - + diff --git a/MediaBrowser.Providers/Studios/StudioImageProvider.cs b/MediaBrowser.Providers/Studios/StudioImageProvider.cs index 7bb98a87c3..6a351b6886 100644 --- a/MediaBrowser.Providers/Studios/StudioImageProvider.cs +++ b/MediaBrowser.Providers/Studios/StudioImageProvider.cs @@ -49,7 +49,7 @@ namespace MediaBrowser.Providers.Studios protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo) { - if (!string.IsNullOrEmpty(item.PrimaryImagePath) && item.BackdropImagePaths.Count == 0) + if (item.HasImage(ImageType.Primary) && item.HasImage(ImageType.Thumb)) { return false; } @@ -75,13 +75,16 @@ namespace MediaBrowser.Providers.Studios public override async Task FetchAsync(BaseItem item, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken) { - if (string.IsNullOrEmpty(item.PrimaryImagePath) || item.BackdropImagePaths.Count == 0) + if (item.HasImage(ImageType.Primary) && item.HasImage(ImageType.Thumb)) { - var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, StudiosManualImageProvider.ProviderName).ConfigureAwait(false); - - await DownloadImages(item, images.ToList(), cancellationToken).ConfigureAwait(false); + SetLastRefreshed(item, DateTime.UtcNow, providerInfo); + return true; } + var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, StudiosManualImageProvider.ProviderName).ConfigureAwait(false); + + await DownloadImages(item, images.ToList(), cancellationToken).ConfigureAwait(false); + SetLastRefreshed(item, DateTime.UtcNow, providerInfo); return true; } @@ -96,6 +99,12 @@ namespace MediaBrowser.Providers.Studios { await SaveImage(item, images, ImageType.Primary, cancellationToken).ConfigureAwait(false); } + cancellationToken.ThrowIfCancellationRequested(); + + if (!item.HasImage(ImageType.Thumb)) + { + await SaveImage(item, images, ImageType.Thumb, cancellationToken).ConfigureAwait(false); + } } if (!item.LockedFields.Contains(MetadataFields.Backdrops)) diff --git a/MediaBrowser.Providers/Studios/StudiosManualImageProvider.cs b/MediaBrowser.Providers/Studios/StudiosManualImageProvider.cs index 8255c6d560..49f5520933 100644 --- a/MediaBrowser.Providers/Studios/StudiosManualImageProvider.cs +++ b/MediaBrowser.Providers/Studios/StudiosManualImageProvider.cs @@ -51,7 +51,7 @@ namespace MediaBrowser.Providers.Studios if (backdrops) { - //list.Add(GetImage(item, "backdrops.txt", ImageType.Backdrop, "backdrop")); + list.Add(GetImage(item, "thumbs.txt", ImageType.Thumb, "thumb")); } return Task.FromResult(list.Where(i => i != null)); diff --git a/MediaBrowser.Providers/Studios/backdrops.txt b/MediaBrowser.Providers/Studios/thumbs.txt similarity index 100% rename from MediaBrowser.Providers/Studios/backdrops.txt rename to MediaBrowser.Providers/Studios/thumbs.txt diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.js index 18c0079626..274be16b9f 100644 --- a/MediaBrowser.WebDashboard/ApiClient.js +++ b/MediaBrowser.WebDashboard/ApiClient.js @@ -1328,10 +1328,9 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders"; - url += "/" + name; - url = self.getUrl(url, { - refreshLibrary: refreshLibrary ? true : false + refreshLibrary: refreshLibrary ? true : false, + name: name }); return self.ajax({ @@ -1357,10 +1356,10 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi } options.refreshLibrary = refreshLibrary ? true : false; + options.name = name; var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders"; - url += "/" + name; url = self.getUrl(url, options); return self.ajax({ @@ -1381,11 +1380,12 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders"; - url += "/" + name + "/Name"; + url += "/Name"; url = self.getUrl(url, { refreshLibrary: refreshLibrary ? true : false, - newName: newName + newName: newName, + name: name }); return self.ajax({ @@ -1410,11 +1410,12 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders"; - url += "/" + virtualFolderName + "/Paths"; + url += "/Paths"; url = self.getUrl(url, { refreshLibrary: refreshLibrary ? true : false, - path: mediaPath + path: mediaPath, + name: virtualFolderName }); return self.ajax({ @@ -1439,11 +1440,12 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders"; - url += "/" + virtualFolderName + "/Paths"; + url += "/Paths"; url = self.getUrl(url, { refreshLibrary: refreshLibrary ? true : false, - path: mediaPath + path: mediaPath, + name: virtualFolderName }); return self.ajax({ diff --git a/MediaBrowser.WebDashboard/packages.config b/MediaBrowser.WebDashboard/packages.config index e36a72adfa..4cc0c4d551 100644 --- a/MediaBrowser.WebDashboard/packages.config +++ b/MediaBrowser.WebDashboard/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file