using MediaBrowser.Controller; using MediaBrowser.Model.Entities; using MediaBrowser.Networking.HttpServer; 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); } } } }