From add43baffef74fcd34cfc6ef02d36777be05b274 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Sun, 24 Feb 2013 22:56:00 -0500 Subject: [PATCH] convert media library url's to rest --- MediaBrowser.Api/ApiService.cs | 34 --- MediaBrowser.Api/Javascript/ApiClient.js | 78 ++--- .../LibraryHelpers.cs} | 232 ++++++--------- .../{ => Library}/LibraryService.cs | 24 +- .../Library/LibraryStructureService.cs | 278 ++++++++++++++++++ MediaBrowser.Api/MediaBrowser.Api.csproj | 5 +- .../UserLibrary/UserLibraryService.cs | 29 -- MediaBrowser.ApiInteraction/ApiClient.cs | 178 +---------- 8 files changed, 413 insertions(+), 445 deletions(-) rename MediaBrowser.Api/{HttpHandlers/UpdateMediaLibraryHandler.cs => Library/LibraryHelpers.cs} (67%) rename MediaBrowser.Api/{ => Library}/LibraryService.cs (91%) create mode 100644 MediaBrowser.Api/Library/LibraryStructureService.cs diff --git a/MediaBrowser.Api/ApiService.cs b/MediaBrowser.Api/ApiService.cs index 68ba6d5225..e6e4594c16 100644 --- a/MediaBrowser.Api/ApiService.cs +++ b/MediaBrowser.Api/ApiService.cs @@ -1,10 +1,7 @@ using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; -using MediaBrowser.Model.Connectivity; -using ServiceStack.Common.Web; using System; using System.Net; -using System.Threading.Tasks; namespace MediaBrowser.Api { @@ -43,36 +40,5 @@ namespace MediaBrowser.Api return request.Url.LocalPath.EndsWith(url, StringComparison.OrdinalIgnoreCase); } - - ///// - ///// Gets the current user. - ///// - ///// The request. - ///// Task{User}. - //public static async Task GetCurrentUser(AuthenticatedRequest request) - //{ - // var user = GetUserById(request.UserId); - - // if (user == null) - // { - // throw HttpError.Unauthorized("Invalid user or password entered."); - // } - - // var clientType = ClientType.Other; - - // if (!string.IsNullOrEmpty(request.Client)) - // { - // ClientType type; - - // if (Enum.TryParse(request.Client, true, out type)) - // { - // clientType = type; - // } - // } - - // await Kernel.Instance.UserManager.LogUserActivity(user, clientType, request.Device).ConfigureAwait(false); - - // return user; - //} } } diff --git a/MediaBrowser.Api/Javascript/ApiClient.js b/MediaBrowser.Api/Javascript/ApiClient.js index df1c8f2c01..e82238d24c 100644 --- a/MediaBrowser.Api/Javascript/ApiClient.js +++ b/MediaBrowser.Api/Javascript/ApiClient.js @@ -297,7 +297,7 @@ var ApiClient = { */ getVirtualFolders: function (userId) { - var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/DefaultVirtualFolders"; + var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders"; url = ApiClient.getUrl(url); @@ -434,18 +434,16 @@ var ApiClient = { throw new Error("null name"); } - var params = { - name: name, - action: "RemoveVirtualFolder" - }; - - if (userId) { - params.userId = userId; - } + var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders"; - var url = ApiClient.getUrl("UpdateMediaLibrary", params); + url += "/" + name; + url = ApiClient.getUrl(url); - return $.post(url); + return $.ajax({ + type: "DELETE", + url: url, + dataType: "json" + }); }, /** @@ -458,16 +456,10 @@ var ApiClient = { throw new Error("null name"); } - var params = { - name: name, - action: "addVirtualFolder" - }; + var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders"; - if (userId) { - params.userId = userId; - } - - var url = ApiClient.getUrl("UpdateMediaLibrary", params); + url += "/" + name; + url = ApiClient.getUrl(url); return $.post(url); }, @@ -482,21 +474,11 @@ var ApiClient = { throw new Error("null name"); } - if (!newName) { - throw new Error("null newName"); - } - - var params = { - name: name, - newName: newName, - action: "RenameVirtualFolder" - }; + var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders"; - if (userId) { - params.userId = userId; - } + url += "/" + name + "/Name"; - var url = ApiClient.getUrl("UpdateMediaLibrary", params); + url = ApiClient.getUrl(url, { newName: newName }); return $.post(url); }, @@ -515,17 +497,11 @@ var ApiClient = { throw new Error("null mediaPath"); } - var params = { - virtualFolderName: virtualFolderName, - mediaPath: mediaPath, - action: "addMediaPath" - }; + var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders"; - if (userId) { - params.userId = userId; - } + url += "/" + virtualFolderName + "/Paths"; - var url = ApiClient.getUrl("UpdateMediaLibrary", params); + url = ApiClient.getUrl(url, { path: mediaPath }); return $.post(url); }, @@ -544,19 +520,17 @@ var ApiClient = { throw new Error("null mediaPath"); } - var params = { - virtualFolderName: virtualFolderName, - mediaPath: mediaPath, - action: "RemoveMediaPath" - }; + var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders"; - if (userId) { - params.userId = userId; - } + url += "/" + virtualFolderName + "/Paths"; - var url = ApiClient.getUrl("UpdateMediaLibrary", params); + url = ApiClient.getUrl(url, { path: mediaPath }); - return $.post(url); + return $.ajax({ + type: "DELETE", + url: url, + dataType: "json" + }); }, /** diff --git a/MediaBrowser.Api/HttpHandlers/UpdateMediaLibraryHandler.cs b/MediaBrowser.Api/Library/LibraryHelpers.cs similarity index 67% rename from MediaBrowser.Api/HttpHandlers/UpdateMediaLibraryHandler.cs rename to MediaBrowser.Api/Library/LibraryHelpers.cs index df6edd6f99..2a3a04537e 100644 --- a/MediaBrowser.Api/HttpHandlers/UpdateMediaLibraryHandler.cs +++ b/MediaBrowser.Api/Library/LibraryHelpers.cs @@ -1,89 +1,113 @@ -using MediaBrowser.Common.Net.Handlers; -using MediaBrowser.Controller; +using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.IO; using System; using System.IO; using System.Linq; -using System.Threading.Tasks; -using MediaBrowser.Controller.IO; -namespace MediaBrowser.Api.HttpHandlers +namespace MediaBrowser.Api.Library { /// - /// Makes changes to the user's media library + /// Class LibraryHelpers /// - public class UpdateMediaLibraryHandler : BaseActionHandler + public static class LibraryHelpers { /// - /// Executes the action. + /// Adds the virtual folder. /// - /// Task. - /// - protected override Task ExecuteAction() + /// The name. + /// The user. + /// The app paths. + /// There is already a media collection with the name + name + . + public static void AddVirtualFolder(string name, User user, IServerApplicationPaths appPaths) { - return Task.Run(() => + name = FileSystem.GetValidFilename(name); + + var rootFolderPath = user != null ? user.RootFolderPath : appPaths.DefaultUserViewsPath; + var virtualFolderPath = Path.Combine(rootFolderPath, name); + + if (Directory.Exists(virtualFolderPath)) { - var action = QueryString["action"]; - - if (string.IsNullOrEmpty(action)) - { - throw new ArgumentNullException(); - } - - User user = null; - - if (!string.IsNullOrEmpty(QueryString["userId"])) - { - user = ApiService.GetUserById(QueryString["userId"]); - } - - if (action.Equals("AddVirtualFolder", StringComparison.OrdinalIgnoreCase)) - { - AddVirtualFolder(Uri.UnescapeDataString(QueryString["name"]), user); - } - - if (action.Equals("RemoveVirtualFolder", StringComparison.OrdinalIgnoreCase)) - { - RemoveVirtualFolder(QueryString["name"], user); - } - - if (action.Equals("RenameVirtualFolder", StringComparison.OrdinalIgnoreCase)) - { - RenameVirtualFolder(QueryString["name"], QueryString["newName"], user); - } - - if (action.Equals("RemoveMediaPath", StringComparison.OrdinalIgnoreCase)) - { - RemoveMediaPath(QueryString["virtualFolderName"], QueryString["mediaPath"], user); - } - - if (action.Equals("AddMediaPath", StringComparison.OrdinalIgnoreCase)) - { - AddMediaPath(QueryString["virtualFolderName"], QueryString["mediaPath"], user); - } - - throw new ArgumentOutOfRangeException(); - }); + throw new ArgumentException("There is already a media collection with the name " + name + "."); + } + + Directory.CreateDirectory(virtualFolderPath); } /// - /// Adds a virtual folder to either the default view or a user view + /// Removes the virtual folder. /// /// The name. /// The user. - private void AddVirtualFolder(string name, User user) + /// The app paths. + /// The media folder does not exist + public static void RemoveVirtualFolder(string name, User user, IServerApplicationPaths appPaths) { - name = FileSystem.GetValidFilename(name); + var rootFolderPath = user != null ? user.RootFolderPath : appPaths.DefaultUserViewsPath; + var path = Path.Combine(rootFolderPath, name); - var rootFolderPath = user != null ? user.RootFolderPath : Kernel.ApplicationPaths.DefaultUserViewsPath; - var virtualFolderPath = Path.Combine(rootFolderPath, name); + if (!Directory.Exists(path)) + { + throw new DirectoryNotFoundException("The media folder does not exist"); + } - if (Directory.Exists(virtualFolderPath)) + Directory.Delete(path, true); + } + + /// + /// Renames the virtual folder. + /// + /// The name. + /// The new name. + /// The user. + /// The app paths. + /// The media collection does not exist + /// There is already a media collection with the name + newPath + . + public static void RenameVirtualFolder(string name, string newName, User user, IServerApplicationPaths appPaths) + { + var rootFolderPath = user != null ? user.RootFolderPath : appPaths.DefaultUserViewsPath; + + var currentPath = Path.Combine(rootFolderPath, name); + var newPath = Path.Combine(rootFolderPath, newName); + + if (!Directory.Exists(currentPath)) { - throw new ArgumentException("There is already a media collection with the name " + name + "."); + throw new DirectoryNotFoundException("The media collection does not exist"); } - Directory.CreateDirectory(virtualFolderPath); + if (Directory.Exists(newPath)) + { + throw new ArgumentException("There is already a media collection with the name " + newPath + "."); + } + + Directory.Move(currentPath, newPath); + } + + /// + /// Deletes a shortcut from within a virtual folder, within either the default view or a user view + /// + /// Name of the virtual folder. + /// The media path. + /// The user. + /// The app paths. + /// The media folder does not exist + public static void RemoveMediaPath(string virtualFolderName, string mediaPath, User user, IServerApplicationPaths appPaths) + { + var rootFolderPath = user != null ? user.RootFolderPath : appPaths.DefaultUserViewsPath; + var path = Path.Combine(rootFolderPath, virtualFolderName); + + if (!Directory.Exists(path)) + { + throw new DirectoryNotFoundException("The media folder does not exist"); + } + + var shortcut = Directory.EnumerateFiles(path, "*.lnk", SearchOption.AllDirectories).FirstOrDefault(f => FileSystem.ResolveShortcut(f).Equals(mediaPath, StringComparison.OrdinalIgnoreCase)); + + if (string.IsNullOrEmpty(shortcut)) + { + throw new DirectoryNotFoundException("The media folder does not exist"); + } + File.Delete(shortcut); } /// @@ -92,7 +116,10 @@ namespace MediaBrowser.Api.HttpHandlers /// Name of the virtual folder. /// The path. /// The user. - private void AddMediaPath(string virtualFolderName, string path, User user) + /// The app paths. + /// The path is not valid. + /// The path does not exist. + public static void AddMediaPath(string virtualFolderName, string path, User user, IServerApplicationPaths appPaths) { if (!Path.IsPathRooted(path)) { @@ -111,10 +138,10 @@ namespace MediaBrowser.Api.HttpHandlers path += Path.DirectorySeparatorChar; } - var rootFolderPath = user != null ? user.RootFolderPath : Kernel.ApplicationPaths.DefaultUserViewsPath; + var rootFolderPath = user != null ? user.RootFolderPath : appPaths.DefaultUserViewsPath; var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName); - ValidateNewMediaPath(rootFolderPath, path); + ValidateNewMediaPath(rootFolderPath, path, appPaths); var shortcutFilename = Path.GetFileNameWithoutExtension(path); @@ -134,9 +161,11 @@ namespace MediaBrowser.Api.HttpHandlers /// /// The current view root folder path. /// The media path. - private void ValidateNewMediaPath(string currentViewRootFolderPath, string mediaPath) + /// The app paths. + /// + private static void ValidateNewMediaPath(string currentViewRootFolderPath, string mediaPath, IServerApplicationPaths appPaths) { - var duplicate = Directory.EnumerateFiles(Kernel.ApplicationPaths.RootFolderPath, "*.lnk", SearchOption.AllDirectories) + var duplicate = Directory.EnumerateFiles(appPaths.RootFolderPath, "*.lnk", SearchOption.AllDirectories) .Select(FileSystem.ResolveShortcut) .FirstOrDefault(p => !IsNewPathValid(mediaPath, p)); @@ -162,7 +191,7 @@ namespace MediaBrowser.Api.HttpHandlers /// The new path. /// The existing path. /// true if [is new path valid] [the specified new path]; otherwise, false. - private bool IsNewPathValid(string newPath, string existingPath) + private static bool IsNewPathValid(string newPath, string existingPath) { // Example: D:\Movies is the existing path // D:\ cannot be added @@ -188,74 +217,5 @@ namespace MediaBrowser.Api.HttpHandlers return true; } - - /// - /// Renames a virtual folder within either the default view or a user view - /// - /// The name. - /// The new name. - /// The user. - private void RenameVirtualFolder(string name, string newName, User user) - { - var rootFolderPath = user != null ? user.RootFolderPath : Kernel.ApplicationPaths.DefaultUserViewsPath; - - var currentPath = Path.Combine(rootFolderPath, name); - var newPath = Path.Combine(rootFolderPath, newName); - - if (!Directory.Exists(currentPath)) - { - throw new DirectoryNotFoundException("The media collection does not exist"); - } - - if (Directory.Exists(newPath)) - { - throw new ArgumentException("There is already a media collection with the name " + newPath + "."); - } - - Directory.Move(currentPath, newPath); - } - - /// - /// Deletes a virtual folder from either the default view or a user view - /// - /// The name. - /// The user. - private void RemoveVirtualFolder(string name, User user) - { - var rootFolderPath = user != null ? user.RootFolderPath : Kernel.ApplicationPaths.DefaultUserViewsPath; - var path = Path.Combine(rootFolderPath, name); - - if (!Directory.Exists(path)) - { - throw new DirectoryNotFoundException("The media folder does not exist"); - } - - Directory.Delete(path, true); - } - - /// - /// Deletes a shortcut from within a virtual folder, within either the default view or a user view - /// - /// Name of the virtual folder. - /// The media path. - /// The user. - private void RemoveMediaPath(string virtualFolderName, string mediaPath, User user) - { - var rootFolderPath = user != null ? user.RootFolderPath : Kernel.ApplicationPaths.DefaultUserViewsPath; - var path = Path.Combine(rootFolderPath, virtualFolderName); - - if (!Directory.Exists(path)) - { - throw new DirectoryNotFoundException("The media folder does not exist"); - } - - var shortcut = Directory.EnumerateFiles(path, "*.lnk", SearchOption.AllDirectories).FirstOrDefault(f => FileSystem.ResolveShortcut(f).Equals(mediaPath, StringComparison.OrdinalIgnoreCase)); - - if (string.IsNullOrEmpty(shortcut)) - { - throw new DirectoryNotFoundException("The media folder does not exist"); - } - File.Delete(shortcut); - } } } diff --git a/MediaBrowser.Api/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs similarity index 91% rename from MediaBrowser.Api/LibraryService.cs rename to MediaBrowser.Api/Library/LibraryService.cs index 434b04eff9..0729987d9e 100644 --- a/MediaBrowser.Api/LibraryService.cs +++ b/MediaBrowser.Api/Library/LibraryService.cs @@ -10,7 +10,7 @@ using System; using System.Collections.Generic; using System.Linq; -namespace MediaBrowser.Api +namespace MediaBrowser.Api.Library { /// /// Class GetPhyscialPaths @@ -85,14 +85,6 @@ namespace MediaBrowser.Api public int Year { get; set; } } - /// - /// Class GetDefaultVirtualFolders - /// - [Route("/Library/DefaultVirtualFolders", "GET")] - public class GetDefaultVirtualFolders : IReturn> - { - } - /// /// Class LibraryService /// @@ -118,20 +110,6 @@ namespace MediaBrowser.Api _appHost = appHost; } - /// - /// Gets the specified request. - /// - /// The request. - /// System.Object. - public object Get(GetDefaultVirtualFolders request) - { - var kernel = (Kernel)Kernel; - - var result = kernel.LibraryManager.GetDefaultVirtualFolders().ToList(); - - return ToOptimizedResult(result); - } - /// /// Gets the specified request. /// diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs new file mode 100644 index 0000000000..35c658f912 --- /dev/null +++ b/MediaBrowser.Api/Library/LibraryStructureService.cs @@ -0,0 +1,278 @@ +using MediaBrowser.Common.Net; +using MediaBrowser.Controller; +using MediaBrowser.Model.Entities; +using ServiceStack.ServiceHost; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MediaBrowser.Api.Library +{ + /// + /// Class GetDefaultVirtualFolders + /// + [Route("/Library/VirtualFolders", "GET")] + [Route("/Users/{UserId}/VirtualFolders", "GET")] + public class GetVirtualFolders : IReturn> + { + /// + /// Gets or sets the user id. + /// + /// The user id. + public string UserId { get; set; } + } + + [Route("/Library/VirtualFolders/{Name}", "POST")] + [Route("/Users/{UserId}/VirtualFolders/{Name}", "POST")] + public class AddVirtualFolder : IReturnVoid + { + /// + /// Gets or sets the user id. + /// + /// The user id. + public string UserId { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + } + + [Route("/Library/VirtualFolders/{Name}", "DELETE")] + [Route("/Users/{UserId}/VirtualFolders/{Name}", "DELETE")] + public class RemoveVirtualFolder : IReturnVoid + { + /// + /// Gets or sets the user id. + /// + /// The user id. + public string UserId { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + } + + [Route("/Library/VirtualFolders/{Name}/Name", "POST")] + [Route("/Users/{UserId}/VirtualFolders/{Name}/Name", "POST")] + public class RenameVirtualFolder : IReturnVoid + { + /// + /// Gets or sets the user id. + /// + /// The user id. + public string UserId { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + public string NewName { get; set; } + } + + [Route("/Library/VirtualFolders/{Name}/Paths", "POST")] + [Route("/Users/{UserId}/VirtualFolders/{Name}/Paths", "POST")] + public class AddMediaPath : IReturnVoid + { + /// + /// Gets or sets the user id. + /// + /// The user id. + public string UserId { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + public string Path { get; set; } + } + + [Route("/Library/VirtualFolders/{Name}/Paths", "DELETE")] + [Route("/Users/{UserId}/VirtualFolders/{Name}/Paths", "DELETE")] + public class RemoveMediaPath : IReturnVoid + { + /// + /// Gets or sets the user id. + /// + /// The user id. + public string UserId { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + public string Path { get; set; } + } + + /// + /// Class LibraryStructureService + /// + public class LibraryStructureService : BaseRestService + { + /// + /// The _app paths + /// + private readonly IServerApplicationPaths _appPaths; + + /// + /// Initializes a new instance of the class. + /// + /// The app paths. + /// appHost + public LibraryStructureService(IServerApplicationPaths appPaths) + { + if (appPaths == null) + { + throw new ArgumentNullException("appPaths"); + } + + _appPaths = appPaths; + } + + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetVirtualFolders request) + { + var kernel = (Kernel)Kernel; + + if (string.IsNullOrEmpty(request.UserId)) + { + var result = kernel.LibraryManager.GetDefaultVirtualFolders().ToList(); + + return ToOptimizedResult(result); + } + else + { + var user = kernel.GetUserById(new Guid(request.UserId)); + + var result = kernel.LibraryManager.GetVirtualFolders(user).ToList(); + + return ToOptimizedResult(result); + } + } + + /// + /// Posts the specified request. + /// + /// The request. + public void Post(AddVirtualFolder request) + { + var kernel = (Kernel)Kernel; + + if (string.IsNullOrEmpty(request.UserId)) + { + LibraryHelpers.AddVirtualFolder(request.Name, null, _appPaths); + } + else + { + var user = kernel.GetUserById(new Guid(request.UserId)); + + LibraryHelpers.AddVirtualFolder(request.Name, user, _appPaths); + } + } + + /// + /// Posts the specified request. + /// + /// The request. + public void Post(RenameVirtualFolder request) + { + var kernel = (Kernel)Kernel; + + if (string.IsNullOrEmpty(request.UserId)) + { + LibraryHelpers.RenameVirtualFolder(request.Name, request.NewName, null, _appPaths); + } + else + { + var user = kernel.GetUserById(new Guid(request.UserId)); + + LibraryHelpers.RenameVirtualFolder(request.Name, request.NewName, user, _appPaths); + } + } + + /// + /// Deletes the specified request. + /// + /// The request. + public void Delete(RemoveVirtualFolder request) + { + var kernel = (Kernel)Kernel; + + if (string.IsNullOrEmpty(request.UserId)) + { + LibraryHelpers.RemoveVirtualFolder(request.Name, null, _appPaths); + } + else + { + var user = kernel.GetUserById(new Guid(request.UserId)); + + LibraryHelpers.RemoveVirtualFolder(request.Name, user, _appPaths); + } + } + + /// + /// Posts the specified request. + /// + /// The request. + public void Post(AddMediaPath request) + { + var kernel = (Kernel)Kernel; + + if (string.IsNullOrEmpty(request.UserId)) + { + LibraryHelpers.AddMediaPath(request.Name, request.Path, null, _appPaths); + } + else + { + var user = kernel.GetUserById(new Guid(request.UserId)); + + LibraryHelpers.AddMediaPath(request.Name, request.Path, user, _appPaths); + } + } + + /// + /// Deletes the specified request. + /// + /// The request. + public void Delete(RemoveMediaPath request) + { + var kernel = (Kernel)Kernel; + + if (string.IsNullOrEmpty(request.UserId)) + { + LibraryHelpers.RemoveMediaPath(request.Name, request.Path, null, _appPaths); + } + else + { + var user = kernel.GetUserById(new Guid(request.UserId)); + + LibraryHelpers.RemoveMediaPath(request.Name, request.Path, user, _appPaths); + } + } + } +} diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index fb7fe0b295..81ff1001be 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -80,7 +80,9 @@ - + + + @@ -102,7 +104,6 @@ - diff --git a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs index 4ec2aca492..51197affb8 100644 --- a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs +++ b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs @@ -83,19 +83,6 @@ namespace MediaBrowser.Api.UserLibrary public Stream RequestStream { get; set; } } - /// - /// Class GetVirtualFolders - /// - [Route("/Users/{UserId}/VirtualFolders", "GET")] - public class GetVirtualFolders : IReturn> - { - /// - /// Gets or sets the user id. - /// - /// The user id. - public Guid UserId { get; set; } - } - /// /// Class MarkFavoriteItem /// @@ -412,22 +399,6 @@ namespace MediaBrowser.Api.UserLibrary return ToOptimizedResult(result); } - /// - /// Gets the specified request. - /// - /// The request. - /// System.Object. - public object Get(GetVirtualFolders request) - { - var kernel = (Kernel)Kernel; - - var user = kernel.GetUserById(request.UserId); - - var result = kernel.LibraryManager.GetVirtualFolders(user).ToList(); - - return ToOptimizedResult(result); - } - /// /// Gets the specified request. /// diff --git a/MediaBrowser.ApiInteraction/ApiClient.cs b/MediaBrowser.ApiInteraction/ApiClient.cs index 4f701532b5..e7d4e6eff1 100644 --- a/MediaBrowser.ApiInteraction/ApiClient.cs +++ b/MediaBrowser.ApiInteraction/ApiClient.cs @@ -658,7 +658,7 @@ namespace MediaBrowser.ApiInteraction /// The user id. /// Task{UserItemDataDto}. /// itemId - public Task ReportPlaybackStartAsync(string itemId, Guid userId) + public Task ReportPlaybackStartAsync(string itemId, Guid userId) { if (string.IsNullOrEmpty(itemId)) { @@ -670,14 +670,9 @@ namespace MediaBrowser.ApiInteraction throw new ArgumentNullException("userId"); } - var dict = new QueryStringDictionary(); - dict.Add("id", itemId); - dict.Add("userId", userId); - dict.Add("type", "start"); - - var url = GetApiUrl("playbackcheckin", dict); + var url = GetApiUrl("Users/" + userId + "/PlayingItems/" + itemId); - return PostAsync(url, new Dictionary()); + return PostAsync(url, new Dictionary()); } /// @@ -688,7 +683,7 @@ namespace MediaBrowser.ApiInteraction /// The position ticks. /// Task{UserItemDataDto}. /// itemId - public Task ReportPlaybackProgressAsync(string itemId, Guid userId, long? positionTicks) + public Task ReportPlaybackProgressAsync(string itemId, Guid userId, long? positionTicks) { if (string.IsNullOrEmpty(itemId)) { @@ -701,15 +696,11 @@ namespace MediaBrowser.ApiInteraction } var dict = new QueryStringDictionary(); - dict.Add("id", itemId); - dict.Add("userId", userId); - dict.Add("type", "progress"); - dict.AddIfNotNull("positionTicks", positionTicks); - var url = GetApiUrl("playbackcheckin", dict); + var url = GetApiUrl("Users/" + userId + "/PlayingItems/" + itemId + "/Progress", dict); - return PostAsync(url, new Dictionary()); + return PostAsync(url, new Dictionary()); } /// @@ -720,7 +711,7 @@ namespace MediaBrowser.ApiInteraction /// The position ticks. /// Task{UserItemDataDto}. /// itemId - public Task ReportPlaybackStoppedAsync(string itemId, Guid userId, long? positionTicks) + public Task ReportPlaybackStoppedAsync(string itemId, Guid userId, long? positionTicks) { if (string.IsNullOrEmpty(itemId)) { @@ -733,15 +724,11 @@ namespace MediaBrowser.ApiInteraction } var dict = new QueryStringDictionary(); - dict.Add("id", itemId); - dict.Add("userId", userId); - dict.Add("type", "stopped"); - dict.AddIfNotNull("positionTicks", positionTicks); - var url = GetApiUrl("playbackcheckin", dict); + var url = GetApiUrl("Users/" + userId + "/PlayingItems/" + itemId, dict); - return PostAsync(url, new Dictionary()); + return HttpClient.DeleteAsync(url, Logger, CancellationToken.None); } /// @@ -878,153 +865,6 @@ namespace MediaBrowser.ApiInteraction return PostAsync(url, triggers); } - /// - /// Adds a virtual folder to either the default view or a user view - /// - /// The name. - /// The user id. - /// Task{RequestResult}. - /// name - public Task AddVirtualFolderAsync(string name, Guid? userId = null) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException("name"); - } - - var dict = new QueryStringDictionary(); - dict.Add("name", name); - dict.Add("action", "AddVirtualFolder"); - - dict.AddIfNotNull("userId", userId); - - var url = GetApiUrl("UpdateMediaLibrary", dict); - - return PostAsync(url, new Dictionary()); - } - - /// - /// Removes a virtual folder, within either the default view or a user view - /// - /// The name. - /// The user id. - /// Task. - /// name - public Task RemoveVirtualFolderAsync(string name, Guid? userId = null) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException("name"); - } - - var dict = new QueryStringDictionary(); - dict.Add("name", name); - dict.Add("action", "RemoveVirtualFolder"); - - dict.AddIfNotNull("userId", userId); - - var url = GetApiUrl("UpdateMediaLibrary", dict); - - return PostAsync(url, new Dictionary()); - } - - /// - /// Renames a virtual folder, within either the default view or a user view - /// - /// The name. - /// The new name. - /// The user id. - /// Task. - /// name - public Task RenameVirtualFolderAsync(string name, string newName, Guid? userId = null) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException("name"); - } - - if (string.IsNullOrEmpty(newName)) - { - throw new ArgumentNullException("newName"); - } - - var dict = new QueryStringDictionary(); - dict.Add("name", name); - dict.Add("newName", newName); - dict.Add("action", "RenameVirtualFolder"); - - dict.AddIfNotNull("userId", userId); - - var url = GetApiUrl("UpdateMediaLibrary", dict); - - return PostAsync(url, new Dictionary()); - } - - /// - /// Adds a media path to a virtual folder, within either the default view or a user view - /// - /// Name of the virtual folder. - /// The media path. - /// The user id. - /// Task. - /// virtualFolderName - public Task AddMediaPathAsync(string virtualFolderName, string mediaPath, Guid? userId = null) - { - if (string.IsNullOrEmpty(virtualFolderName)) - { - throw new ArgumentNullException("virtualFolderName"); - } - - if (string.IsNullOrEmpty(mediaPath)) - { - throw new ArgumentNullException("mediaPath"); - } - - var dict = new QueryStringDictionary(); - dict.Add("virtualFolderName", virtualFolderName); - dict.Add("mediaPath", mediaPath); - dict.Add("action", "AddMediaPath"); - - dict.AddIfNotNull("userId", userId); - - var url = GetApiUrl("UpdateMediaLibrary", dict); - - return PostAsync(url, new Dictionary()); - } - - /// - /// Removes a media path from a virtual folder, within either the default view or a user view - /// - /// Name of the virtual folder. - /// The media path. - /// The user id. - /// Task. - /// virtualFolderName - public Task RemoveMediaPathAsync(string virtualFolderName, string mediaPath, Guid? userId = null) - { - if (string.IsNullOrEmpty(virtualFolderName)) - { - throw new ArgumentNullException("virtualFolderName"); - } - - if (string.IsNullOrEmpty(mediaPath)) - { - throw new ArgumentNullException("mediaPath"); - } - - var dict = new QueryStringDictionary(); - - dict.Add("virtualFolderName", virtualFolderName); - dict.Add("mediaPath", mediaPath); - dict.Add("action", "RemoveMediaPath"); - - dict.AddIfNotNull("userId", userId); - - var url = GetApiUrl("UpdateMediaLibrary", dict); - - return PostAsync(url, new Dictionary()); - } - /// /// Updates display preferences for a user ///