convert media library url's to rest

pull/702/head
LukePulverenti 12 years ago
parent 2d342c02ef
commit add43baffe

@ -1,10 +1,7 @@
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Connectivity;
using ServiceStack.Common.Web;
using System; using System;
using System.Net; using System.Net;
using System.Threading.Tasks;
namespace MediaBrowser.Api namespace MediaBrowser.Api
{ {
@ -43,36 +40,5 @@ namespace MediaBrowser.Api
return request.Url.LocalPath.EndsWith(url, StringComparison.OrdinalIgnoreCase); return request.Url.LocalPath.EndsWith(url, StringComparison.OrdinalIgnoreCase);
} }
///// <summary>
///// Gets the current user.
///// </summary>
///// <param name="request">The request.</param>
///// <returns>Task{User}.</returns>
//public static async Task<User> 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;
//}
} }
} }

@ -297,7 +297,7 @@ var ApiClient = {
*/ */
getVirtualFolders: function (userId) { getVirtualFolders: function (userId) {
var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/DefaultVirtualFolders"; var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders";
url = ApiClient.getUrl(url); url = ApiClient.getUrl(url);
@ -434,18 +434,16 @@ var ApiClient = {
throw new Error("null name"); throw new Error("null name");
} }
var params = { var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders";
name: name,
action: "RemoveVirtualFolder"
};
if (userId) {
params.userId = userId;
}
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"); throw new Error("null name");
} }
var params = { var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders";
name: name,
action: "addVirtualFolder"
};
if (userId) { url += "/" + name;
params.userId = userId; url = ApiClient.getUrl(url);
}
var url = ApiClient.getUrl("UpdateMediaLibrary", params);
return $.post(url); return $.post(url);
}, },
@ -482,21 +474,11 @@ var ApiClient = {
throw new Error("null name"); throw new Error("null name");
} }
if (!newName) { var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders";
throw new Error("null newName");
}
var params = {
name: name,
newName: newName,
action: "RenameVirtualFolder"
};
if (userId) { url += "/" + name + "/Name";
params.userId = userId;
}
var url = ApiClient.getUrl("UpdateMediaLibrary", params); url = ApiClient.getUrl(url, { newName: newName });
return $.post(url); return $.post(url);
}, },
@ -515,17 +497,11 @@ var ApiClient = {
throw new Error("null mediaPath"); throw new Error("null mediaPath");
} }
var params = { var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders";
virtualFolderName: virtualFolderName,
mediaPath: mediaPath,
action: "addMediaPath"
};
if (userId) { url += "/" + virtualFolderName + "/Paths";
params.userId = userId;
}
var url = ApiClient.getUrl("UpdateMediaLibrary", params); url = ApiClient.getUrl(url, { path: mediaPath });
return $.post(url); return $.post(url);
}, },
@ -544,19 +520,17 @@ var ApiClient = {
throw new Error("null mediaPath"); throw new Error("null mediaPath");
} }
var params = { var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders";
virtualFolderName: virtualFolderName,
mediaPath: mediaPath,
action: "RemoveMediaPath"
};
if (userId) { url += "/" + virtualFolderName + "/Paths";
params.userId = userId;
}
var url = ApiClient.getUrl("UpdateMediaLibrary", params); url = ApiClient.getUrl(url, { path: mediaPath });
return $.post(url); return $.ajax({
type: "DELETE",
url: url,
dataType: "json"
});
}, },
/** /**

@ -1,89 +1,113 @@
using MediaBrowser.Common.Net.Handlers; using MediaBrowser.Controller;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Controller.IO;
namespace MediaBrowser.Api.HttpHandlers namespace MediaBrowser.Api.Library
{ {
/// <summary> /// <summary>
/// Makes changes to the user's media library /// Class LibraryHelpers
/// </summary> /// </summary>
public class UpdateMediaLibraryHandler : BaseActionHandler<Kernel> public static class LibraryHelpers
{ {
/// <summary> /// <summary>
/// Executes the action. /// Adds the virtual folder.
/// </summary> /// </summary>
/// <returns>Task.</returns> /// <param name="name">The name.</param>
/// <exception cref="System.NotImplementedException"></exception> /// <param name="user">The user.</param>
protected override Task ExecuteAction() /// <param name="appPaths">The app paths.</param>
/// <exception cref="System.ArgumentException">There is already a media collection with the name + name + .</exception>
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"]; throw new ArgumentException("There is already a media collection with the name " + name + ".");
}
if (string.IsNullOrEmpty(action))
{ Directory.CreateDirectory(virtualFolderPath);
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();
});
} }
/// <summary> /// <summary>
/// Adds a virtual folder to either the default view or a user view /// Removes the virtual folder.
/// </summary> /// </summary>
/// <param name="name">The name.</param> /// <param name="name">The name.</param>
/// <param name="user">The user.</param> /// <param name="user">The user.</param>
private void AddVirtualFolder(string name, User user) /// <param name="appPaths">The app paths.</param>
/// <exception cref="System.IO.DirectoryNotFoundException">The media folder does not exist</exception>
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; if (!Directory.Exists(path))
var virtualFolderPath = Path.Combine(rootFolderPath, name); {
throw new DirectoryNotFoundException("The media folder does not exist");
}
if (Directory.Exists(virtualFolderPath)) Directory.Delete(path, true);
}
/// <summary>
/// Renames the virtual folder.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="newName">The new name.</param>
/// <param name="user">The user.</param>
/// <param name="appPaths">The app paths.</param>
/// <exception cref="System.IO.DirectoryNotFoundException">The media collection does not exist</exception>
/// <exception cref="System.ArgumentException">There is already a media collection with the name + newPath + .</exception>
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);
}
/// <summary>
/// Deletes a shortcut from within a virtual folder, within either the default view or a user view
/// </summary>
/// <param name="virtualFolderName">Name of the virtual folder.</param>
/// <param name="mediaPath">The media path.</param>
/// <param name="user">The user.</param>
/// <param name="appPaths">The app paths.</param>
/// <exception cref="System.IO.DirectoryNotFoundException">The media folder does not exist</exception>
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);
} }
/// <summary> /// <summary>
@ -92,7 +116,10 @@ namespace MediaBrowser.Api.HttpHandlers
/// <param name="virtualFolderName">Name of the virtual folder.</param> /// <param name="virtualFolderName">Name of the virtual folder.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <param name="user">The user.</param> /// <param name="user">The user.</param>
private void AddMediaPath(string virtualFolderName, string path, User user) /// <param name="appPaths">The app paths.</param>
/// <exception cref="System.ArgumentException">The path is not valid.</exception>
/// <exception cref="System.IO.DirectoryNotFoundException">The path does not exist.</exception>
public static void AddMediaPath(string virtualFolderName, string path, User user, IServerApplicationPaths appPaths)
{ {
if (!Path.IsPathRooted(path)) if (!Path.IsPathRooted(path))
{ {
@ -111,10 +138,10 @@ namespace MediaBrowser.Api.HttpHandlers
path += Path.DirectorySeparatorChar; 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); var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName);
ValidateNewMediaPath(rootFolderPath, path); ValidateNewMediaPath(rootFolderPath, path, appPaths);
var shortcutFilename = Path.GetFileNameWithoutExtension(path); var shortcutFilename = Path.GetFileNameWithoutExtension(path);
@ -134,9 +161,11 @@ namespace MediaBrowser.Api.HttpHandlers
/// </summary> /// </summary>
/// <param name="currentViewRootFolderPath">The current view root folder path.</param> /// <param name="currentViewRootFolderPath">The current view root folder path.</param>
/// <param name="mediaPath">The media path.</param> /// <param name="mediaPath">The media path.</param>
private void ValidateNewMediaPath(string currentViewRootFolderPath, string mediaPath) /// <param name="appPaths">The app paths.</param>
/// <exception cref="System.ArgumentException"></exception>
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) .Select(FileSystem.ResolveShortcut)
.FirstOrDefault(p => !IsNewPathValid(mediaPath, p)); .FirstOrDefault(p => !IsNewPathValid(mediaPath, p));
@ -162,7 +191,7 @@ namespace MediaBrowser.Api.HttpHandlers
/// <param name="newPath">The new path.</param> /// <param name="newPath">The new path.</param>
/// <param name="existingPath">The existing path.</param> /// <param name="existingPath">The existing path.</param>
/// <returns><c>true</c> if [is new path valid] [the specified new path]; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if [is new path valid] [the specified new path]; otherwise, <c>false</c>.</returns>
private bool IsNewPathValid(string newPath, string existingPath) private static bool IsNewPathValid(string newPath, string existingPath)
{ {
// Example: D:\Movies is the existing path // Example: D:\Movies is the existing path
// D:\ cannot be added // D:\ cannot be added
@ -188,74 +217,5 @@ namespace MediaBrowser.Api.HttpHandlers
return true; return true;
} }
/// <summary>
/// Renames a virtual folder within either the default view or a user view
/// </summary>
/// <param name="name">The name.</param>
/// <param name="newName">The new name.</param>
/// <param name="user">The user.</param>
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);
}
/// <summary>
/// Deletes a virtual folder from either the default view or a user view
/// </summary>
/// <param name="name">The name.</param>
/// <param name="user">The user.</param>
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);
}
/// <summary>
/// Deletes a shortcut from within a virtual folder, within either the default view or a user view
/// </summary>
/// <param name="virtualFolderName">Name of the virtual folder.</param>
/// <param name="mediaPath">The media path.</param>
/// <param name="user">The user.</param>
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);
}
} }
} }

@ -10,7 +10,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace MediaBrowser.Api namespace MediaBrowser.Api.Library
{ {
/// <summary> /// <summary>
/// Class GetPhyscialPaths /// Class GetPhyscialPaths
@ -85,14 +85,6 @@ namespace MediaBrowser.Api
public int Year { get; set; } public int Year { get; set; }
} }
/// <summary>
/// Class GetDefaultVirtualFolders
/// </summary>
[Route("/Library/DefaultVirtualFolders", "GET")]
public class GetDefaultVirtualFolders : IReturn<List<VirtualFolderInfo>>
{
}
/// <summary> /// <summary>
/// Class LibraryService /// Class LibraryService
/// </summary> /// </summary>
@ -118,20 +110,6 @@ namespace MediaBrowser.Api
_appHost = appHost; _appHost = appHost;
} }
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetDefaultVirtualFolders request)
{
var kernel = (Kernel)Kernel;
var result = kernel.LibraryManager.GetDefaultVirtualFolders().ToList();
return ToOptimizedResult(result);
}
/// <summary> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>

@ -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
{
/// <summary>
/// Class GetDefaultVirtualFolders
/// </summary>
[Route("/Library/VirtualFolders", "GET")]
[Route("/Users/{UserId}/VirtualFolders", "GET")]
public class GetVirtualFolders : IReturn<List<VirtualFolderInfo>>
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
public string UserId { get; set; }
}
[Route("/Library/VirtualFolders/{Name}", "POST")]
[Route("/Users/{UserId}/VirtualFolders/{Name}", "POST")]
public class AddVirtualFolder : IReturnVoid
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
public string UserId { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
}
[Route("/Library/VirtualFolders/{Name}", "DELETE")]
[Route("/Users/{UserId}/VirtualFolders/{Name}", "DELETE")]
public class RemoveVirtualFolder : IReturnVoid
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
public string UserId { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
}
[Route("/Library/VirtualFolders/{Name}/Name", "POST")]
[Route("/Users/{UserId}/VirtualFolders/{Name}/Name", "POST")]
public class RenameVirtualFolder : IReturnVoid
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
public string UserId { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string NewName { get; set; }
}
[Route("/Library/VirtualFolders/{Name}/Paths", "POST")]
[Route("/Users/{UserId}/VirtualFolders/{Name}/Paths", "POST")]
public class AddMediaPath : IReturnVoid
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
public string UserId { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Path { get; set; }
}
[Route("/Library/VirtualFolders/{Name}/Paths", "DELETE")]
[Route("/Users/{UserId}/VirtualFolders/{Name}/Paths", "DELETE")]
public class RemoveMediaPath : IReturnVoid
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
public string UserId { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Path { get; set; }
}
/// <summary>
/// Class LibraryStructureService
/// </summary>
public class LibraryStructureService : BaseRestService
{
/// <summary>
/// The _app paths
/// </summary>
private readonly IServerApplicationPaths _appPaths;
/// <summary>
/// Initializes a new instance of the <see cref="LibraryService" /> class.
/// </summary>
/// <param name="appPaths">The app paths.</param>
/// <exception cref="System.ArgumentNullException">appHost</exception>
public LibraryStructureService(IServerApplicationPaths appPaths)
{
if (appPaths == null)
{
throw new ArgumentNullException("appPaths");
}
_appPaths = appPaths;
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
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);
}
}
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
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);
}
}
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
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);
}
}
/// <summary>
/// Deletes the specified request.
/// </summary>
/// <param name="request">The request.</param>
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);
}
}
/// <summary>
/// Posts the specified request.
/// </summary>
/// <param name="request">The request.</param>
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);
}
}
/// <summary>
/// Deletes the specified request.
/// </summary>
/// <param name="request">The request.</param>
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);
}
}
}
}

@ -80,7 +80,9 @@
<Compile Include="Images\ImageWriter.cs" /> <Compile Include="Images\ImageWriter.cs" />
<Compile Include="Images\UploadImageHandler.cs" /> <Compile Include="Images\UploadImageHandler.cs" />
<Compile Include="Javascript\JavascriptApiClientService.cs" /> <Compile Include="Javascript\JavascriptApiClientService.cs" />
<Compile Include="LibraryService.cs" /> <Compile Include="Library\LibraryHelpers.cs" />
<Compile Include="Library\LibraryService.cs" />
<Compile Include="Library\LibraryStructureService.cs" />
<Compile Include="LocalizationService.cs" /> <Compile Include="LocalizationService.cs" />
<Compile Include="PackageService.cs" /> <Compile Include="PackageService.cs" />
<Compile Include="PluginService.cs" /> <Compile Include="PluginService.cs" />
@ -102,7 +104,6 @@
<Compile Include="Streaming\HlsAudioPlaylistHandler.cs" /> <Compile Include="Streaming\HlsAudioPlaylistHandler.cs" />
<Compile Include="Streaming\HlsSegmentHandler.cs" /> <Compile Include="Streaming\HlsSegmentHandler.cs" />
<Compile Include="Streaming\HlsVideoPlaylistHandler.cs" /> <Compile Include="Streaming\HlsVideoPlaylistHandler.cs" />
<Compile Include="HttpHandlers\UpdateMediaLibraryHandler.cs" />
<Compile Include="Streaming\VideoHandler.cs" /> <Compile Include="Streaming\VideoHandler.cs" />
<Compile Include="Plugin.cs" /> <Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

@ -83,19 +83,6 @@ namespace MediaBrowser.Api.UserLibrary
public Stream RequestStream { get; set; } public Stream RequestStream { get; set; }
} }
/// <summary>
/// Class GetVirtualFolders
/// </summary>
[Route("/Users/{UserId}/VirtualFolders", "GET")]
public class GetVirtualFolders : IReturn<List<VirtualFolderInfo>>
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
public Guid UserId { get; set; }
}
/// <summary> /// <summary>
/// Class MarkFavoriteItem /// Class MarkFavoriteItem
/// </summary> /// </summary>
@ -412,22 +399,6 @@ namespace MediaBrowser.Api.UserLibrary
return ToOptimizedResult(result); return ToOptimizedResult(result);
} }
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
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);
}
/// <summary> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>

@ -658,7 +658,7 @@ namespace MediaBrowser.ApiInteraction
/// <param name="userId">The user id.</param> /// <param name="userId">The user id.</param>
/// <returns>Task{UserItemDataDto}.</returns> /// <returns>Task{UserItemDataDto}.</returns>
/// <exception cref="System.ArgumentNullException">itemId</exception> /// <exception cref="System.ArgumentNullException">itemId</exception>
public Task<UserItemDataDto> ReportPlaybackStartAsync(string itemId, Guid userId) public Task ReportPlaybackStartAsync(string itemId, Guid userId)
{ {
if (string.IsNullOrEmpty(itemId)) if (string.IsNullOrEmpty(itemId))
{ {
@ -670,14 +670,9 @@ namespace MediaBrowser.ApiInteraction
throw new ArgumentNullException("userId"); throw new ArgumentNullException("userId");
} }
var dict = new QueryStringDictionary(); var url = GetApiUrl("Users/" + userId + "/PlayingItems/" + itemId);
dict.Add("id", itemId);
dict.Add("userId", userId);
dict.Add("type", "start");
var url = GetApiUrl("playbackcheckin", dict);
return PostAsync<UserItemDataDto>(url, new Dictionary<string, string>()); return PostAsync<EmptyRequestResult>(url, new Dictionary<string, string>());
} }
/// <summary> /// <summary>
@ -688,7 +683,7 @@ namespace MediaBrowser.ApiInteraction
/// <param name="positionTicks">The position ticks.</param> /// <param name="positionTicks">The position ticks.</param>
/// <returns>Task{UserItemDataDto}.</returns> /// <returns>Task{UserItemDataDto}.</returns>
/// <exception cref="System.ArgumentNullException">itemId</exception> /// <exception cref="System.ArgumentNullException">itemId</exception>
public Task<UserItemDataDto> ReportPlaybackProgressAsync(string itemId, Guid userId, long? positionTicks) public Task ReportPlaybackProgressAsync(string itemId, Guid userId, long? positionTicks)
{ {
if (string.IsNullOrEmpty(itemId)) if (string.IsNullOrEmpty(itemId))
{ {
@ -701,15 +696,11 @@ namespace MediaBrowser.ApiInteraction
} }
var dict = new QueryStringDictionary(); var dict = new QueryStringDictionary();
dict.Add("id", itemId);
dict.Add("userId", userId);
dict.Add("type", "progress");
dict.AddIfNotNull("positionTicks", positionTicks); dict.AddIfNotNull("positionTicks", positionTicks);
var url = GetApiUrl("playbackcheckin", dict); var url = GetApiUrl("Users/" + userId + "/PlayingItems/" + itemId + "/Progress", dict);
return PostAsync<UserItemDataDto>(url, new Dictionary<string, string>()); return PostAsync<EmptyRequestResult>(url, new Dictionary<string, string>());
} }
/// <summary> /// <summary>
@ -720,7 +711,7 @@ namespace MediaBrowser.ApiInteraction
/// <param name="positionTicks">The position ticks.</param> /// <param name="positionTicks">The position ticks.</param>
/// <returns>Task{UserItemDataDto}.</returns> /// <returns>Task{UserItemDataDto}.</returns>
/// <exception cref="System.ArgumentNullException">itemId</exception> /// <exception cref="System.ArgumentNullException">itemId</exception>
public Task<UserItemDataDto> ReportPlaybackStoppedAsync(string itemId, Guid userId, long? positionTicks) public Task ReportPlaybackStoppedAsync(string itemId, Guid userId, long? positionTicks)
{ {
if (string.IsNullOrEmpty(itemId)) if (string.IsNullOrEmpty(itemId))
{ {
@ -733,15 +724,11 @@ namespace MediaBrowser.ApiInteraction
} }
var dict = new QueryStringDictionary(); var dict = new QueryStringDictionary();
dict.Add("id", itemId);
dict.Add("userId", userId);
dict.Add("type", "stopped");
dict.AddIfNotNull("positionTicks", positionTicks); dict.AddIfNotNull("positionTicks", positionTicks);
var url = GetApiUrl("playbackcheckin", dict); var url = GetApiUrl("Users/" + userId + "/PlayingItems/" + itemId, dict);
return PostAsync<UserItemDataDto>(url, new Dictionary<string, string>()); return HttpClient.DeleteAsync(url, Logger, CancellationToken.None);
} }
/// <summary> /// <summary>
@ -878,153 +865,6 @@ namespace MediaBrowser.ApiInteraction
return PostAsync<TaskTriggerInfo[], EmptyRequestResult>(url, triggers); return PostAsync<TaskTriggerInfo[], EmptyRequestResult>(url, triggers);
} }
/// <summary>
/// Adds a virtual folder to either the default view or a user view
/// </summary>
/// <param name="name">The name.</param>
/// <param name="userId">The user id.</param>
/// <returns>Task{RequestResult}.</returns>
/// <exception cref="System.ArgumentNullException">name</exception>
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<EmptyRequestResult>(url, new Dictionary<string, string>());
}
/// <summary>
/// Removes a virtual folder, within either the default view or a user view
/// </summary>
/// <param name="name">The name.</param>
/// <param name="userId">The user id.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">name</exception>
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<EmptyRequestResult>(url, new Dictionary<string, string>());
}
/// <summary>
/// Renames a virtual folder, within either the default view or a user view
/// </summary>
/// <param name="name">The name.</param>
/// <param name="newName">The new name.</param>
/// <param name="userId">The user id.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">name</exception>
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<EmptyRequestResult>(url, new Dictionary<string, string>());
}
/// <summary>
/// Adds a media path to a virtual folder, within either the default view or a user view
/// </summary>
/// <param name="virtualFolderName">Name of the virtual folder.</param>
/// <param name="mediaPath">The media path.</param>
/// <param name="userId">The user id.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">virtualFolderName</exception>
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<EmptyRequestResult>(url, new Dictionary<string, string>());
}
/// <summary>
/// Removes a media path from a virtual folder, within either the default view or a user view
/// </summary>
/// <param name="virtualFolderName">Name of the virtual folder.</param>
/// <param name="mediaPath">The media path.</param>
/// <param name="userId">The user id.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">virtualFolderName</exception>
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<EmptyRequestResult>(url, new Dictionary<string, string>());
}
/// <summary> /// <summary>
/// Updates display preferences for a user /// Updates display preferences for a user
/// </summary> /// </summary>

Loading…
Cancel
Save