This commit is contained in:
Eric Reed 2013-03-08 14:21:38 -05:00
commit 810d6d5dc4
16 changed files with 82 additions and 66 deletions

View File

@ -13,12 +13,12 @@ namespace MediaBrowser.Api
/// <summary>
/// Class ServerEntryPoint
/// </summary>
public class ServerEntryPoint : IServerEntryPoint
public class ApiEntryPoint : IServerEntryPoint
{
/// <summary>
/// The instance
/// </summary>
public static ServerEntryPoint Instance;
public static ApiEntryPoint Instance;
/// <summary>
/// Gets or sets the logger.
@ -27,10 +27,10 @@ namespace MediaBrowser.Api
private ILogger Logger { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ServerEntryPoint" /> class.
/// Initializes a new instance of the <see cref="ApiEntryPoint" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
public ServerEntryPoint(ILogger logger)
public ApiEntryPoint(ILogger logger)
{
Logger = logger;

View File

@ -1,24 +0,0 @@
using System;
using System.Net;
namespace MediaBrowser.Api
{
/// <summary>
/// Contains some helpers for the api
/// </summary>
public static class ApiService
{
/// <summary>
/// Determines whether [is API URL match] [the specified URL].
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="request">The request.</param>
/// <returns><c>true</c> if [is API URL match] [the specified URL]; otherwise, <c>false</c>.</returns>
public static bool IsApiUrlMatch(string url, HttpListenerRequest request)
{
url = "/api/" + url;
return request.Url.LocalPath.EndsWith(url, StringComparison.OrdinalIgnoreCase);
}
}
}

View File

@ -16,34 +16,49 @@ namespace MediaBrowser.Api
/// Class GetDirectoryContents
/// </summary>
[Route("/Environment/DirectoryContents", "GET")]
[ServiceStack.ServiceHost.Api(Description = "Gets the contents of a given directory in the file system")]
public class GetDirectoryContents : IReturn<List<FileSystemEntryInfo>>
{
/// <summary>
/// Gets or sets the path.
/// </summary>
/// <value>The path.</value>
[ApiMember(Name = "Path", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string Path { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [include files].
/// </summary>
/// <value><c>true</c> if [include files]; otherwise, <c>false</c>.</value>
[ApiMember(Name = "IncludeFiles", Description = "An optional filter to include or exclude files from the results.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public bool IncludeFiles { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [include directories].
/// </summary>
/// <value><c>true</c> if [include directories]; otherwise, <c>false</c>.</value>
[ApiMember(Name = "IncludeDirectories", Description = "An optional filter to include or exclude folders from the results.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public bool IncludeDirectories { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [include hidden].
/// </summary>
/// <value><c>true</c> if [include hidden]; otherwise, <c>false</c>.</value>
[ApiMember(Name = "IncludeHidden", Description = "An optional filter to include or exclude hidden files and folders.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public bool IncludeHidden { get; set; }
public GetDirectoryContents()
{
IncludeDirectories = true;
IncludeFiles = true;
}
}
/// <summary>
/// Class GetDrives
/// </summary>
[Route("/Environment/Drives", "GET")]
[ServiceStack.ServiceHost.Api(Description = "Gets available drives from the server's file system")]
public class GetDrives : IReturn<List<FileSystemEntryInfo>>
{
}
@ -51,8 +66,9 @@ namespace MediaBrowser.Api
/// <summary>
/// Class GetNetworkComputers
/// </summary>
[Route("/Environment/NetworkComputers", "GET")]
public class GetNetworkComputers : IReturn<List<FileSystemEntryInfo>>
[Route("/Environment/NetworkDevices", "GET")]
[ServiceStack.ServiceHost.Api(Description = "Gets a list of devices on the network")]
public class GetNetworkDevices : IReturn<List<FileSystemEntryInfo>>
{
}
@ -128,9 +144,9 @@ namespace MediaBrowser.Api
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetNetworkComputers request)
public object Get(GetNetworkDevices request)
{
var result = GetNetworkComputers().ToList();
var result = GetNetworkDevices().ToList();
return ToOptimizedResult(result);
}
@ -155,7 +171,7 @@ namespace MediaBrowser.Api
/// Gets the network computers.
/// </summary>
/// <returns>IEnumerable{FileSystemEntryInfo}.</returns>
private IEnumerable<FileSystemEntryInfo> GetNetworkComputers()
private IEnumerable<FileSystemEntryInfo> GetNetworkDevices()
{
return _networkManager.GetNetworkDevices().Select(c => new FileSystemEntryInfo
{

View File

@ -194,11 +194,11 @@ var ApiClient = {
},
/**
* Gets a list of network computers from the server
* Gets a list of network devices from the server
*/
getNetworkComputers: function () {
getNetworkDevices: function () {
var url = ApiClient.getUrl("Environment/NetworkComputers");
var url = ApiClient.getUrl("Environment/NetworkDevices");
return $.getJSON(url);
},

View File

@ -14,6 +14,7 @@ namespace MediaBrowser.Api
/// Class GetCultures
/// </summary>
[Route("/Localization/Cultures", "GET")]
[ServiceStack.ServiceHost.Api(Description = "Gets known cultures")]
public class GetCultures : IReturn<List<CultureDto>>
{
}
@ -22,6 +23,7 @@ namespace MediaBrowser.Api
/// Class GetCountries
/// </summary>
[Route("/Localization/Countries", "GET")]
[ServiceStack.ServiceHost.Api(Description = "Gets known countries")]
public class GetCountries : IReturn<List<CountryInfo>>
{
}
@ -30,6 +32,7 @@ namespace MediaBrowser.Api
/// Class ParentalRatings
/// </summary>
[Route("/Localization/ParentalRatings", "GET")]
[ServiceStack.ServiceHost.Api(Description = "Gets known parental ratings")]
public class GetParentalRatings : IReturn<List<ParentalRating>>
{
}

View File

@ -81,7 +81,6 @@
<Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link>
</Compile>
<Compile Include="ApiService.cs" />
<Compile Include="EnvironmentService.cs" />
<Compile Include="Images\ImageRequest.cs" />
<Compile Include="Images\ImageService.cs" />
@ -105,7 +104,7 @@
<Compile Include="PluginService.cs" />
<Compile Include="ScheduledTasks\ScheduledTaskService.cs" />
<Compile Include="ScheduledTasks\ScheduledTasksWebSocketListener.cs" />
<Compile Include="ServerEntryPoint.cs" />
<Compile Include="ApiEntryPoint.cs" />
<Compile Include="SystemService.cs" />
<Compile Include="UserLibrary\BaseItemsByNameService.cs" />
<Compile Include="UserLibrary\GenresService.cs" />

View File

@ -16,12 +16,14 @@ namespace MediaBrowser.Api
/// Class GetPackage
/// </summary>
[Route("/Packages/{Name}", "GET")]
[ServiceStack.ServiceHost.Api(("Gets a package, by name"))]
public class GetPackage : IReturn<PackageInfo>
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[ApiMember(Name = "Name", Description = "The name of the package", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Name { get; set; }
}
@ -29,12 +31,14 @@ namespace MediaBrowser.Api
/// Class GetPackages
/// </summary>
[Route("/Packages", "GET")]
[ServiceStack.ServiceHost.Api(("Gets available packages"))]
public class GetPackages : IReturn<List<PackageInfo>>
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[ApiMember(Name = "PackageType", Description = "Optional package type filter (System/UserInstalled)", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public PackageType? PackageType { get; set; }
}
@ -42,12 +46,14 @@ namespace MediaBrowser.Api
/// Class GetPackageVersionUpdates
/// </summary>
[Route("/Packages/Updates", "GET")]
[ServiceStack.ServiceHost.Api(("Gets available package updates for currently installed packages"))]
public class GetPackageVersionUpdates : IReturn<List<PackageVersionInfo>>
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[ApiMember(Name = "PackageType", Description = "Package type filter (System/UserInstalled)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public PackageType PackageType { get; set; }
}
@ -55,24 +61,28 @@ namespace MediaBrowser.Api
/// Class InstallPackage
/// </summary>
[Route("/Packages/Installed/{Name}", "POST")]
[ServiceStack.ServiceHost.Api(("Installs a package"))]
public class InstallPackage : IReturnVoid
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[ApiMember(Name = "Name", Description = "Package name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string Name { get; set; }
/// <summary>
/// Gets or sets the version.
/// </summary>
/// <value>The version.</value>
[ApiMember(Name = "Version", Description = "Optional version. Defaults to latest version.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string Version { get; set; }
/// <summary>
/// Gets or sets the update class.
/// </summary>
/// <value>The update class.</value>
[ApiMember(Name = "UpdateClass", Description = "Optional update class (Dev, Beta, Release). Defaults to Release.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public PackageVersionClass UpdateClass { get; set; }
}
@ -80,12 +90,14 @@ namespace MediaBrowser.Api
/// Class CancelPackageInstallation
/// </summary>
[Route("/Packages/Installing/{Id}", "DELETE")]
[ServiceStack.ServiceHost.Api(("Cancels a package installation"))]
public class CancelPackageInstallation : IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Installation Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
public Guid Id { get; set; }
}

View File

@ -516,7 +516,7 @@ namespace MediaBrowser.Api.Playback
EnableRaisingEvents = true
};
ServerEntryPoint.Instance.OnTranscodeBeginning(outputPath, TranscodingJobType, process);
ApiEntryPoint.Instance.OnTranscodeBeginning(outputPath, TranscodingJobType, process);
Logger.Info(process.StartInfo.FileName + " " + process.StartInfo.Arguments);
@ -535,7 +535,7 @@ namespace MediaBrowser.Api.Playback
{
Logger.ErrorException("Error starting ffmpeg", ex);
ServerEntryPoint.Instance.OnTranscodeFailedToStart(outputPath, TranscodingJobType);
ApiEntryPoint.Instance.OnTranscodeFailedToStart(outputPath, TranscodingJobType);
state.LogFileStream.Dispose();
@ -586,7 +586,7 @@ namespace MediaBrowser.Api.Playback
process.Dispose();
ServerEntryPoint.Instance.OnTranscodingFinished(outputFilePath, TranscodingJobType);
ApiEntryPoint.Instance.OnTranscodingFinished(outputFilePath, TranscodingJobType);
if (!exitCode.HasValue || exitCode.Value != 0)
{

View File

@ -77,7 +77,7 @@ namespace MediaBrowser.Api.Playback.Hls
}
else
{
ServerEntryPoint.Instance.OnTranscodeBeginRequest(playlist, TranscodingJobType.Hls);
ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlist, TranscodingJobType.Hls);
}
// Get the current playlist text and convert to bytes
@ -94,7 +94,7 @@ namespace MediaBrowser.Api.Playback.Hls
}
finally
{
ServerEntryPoint.Instance.OnTranscodeEndRequest(playlist, TranscodingJobType.Hls);
ApiEntryPoint.Instance.OnTranscodeEndRequest(playlist, TranscodingJobType.Hls);
}
}

View File

@ -104,7 +104,7 @@ namespace MediaBrowser.Api.Playback.Progressive
var outputPath = GetOutputFilePath(state);
if (File.Exists(outputPath) && !ServerEntryPoint.Instance.HasActiveTranscodingJob(outputPath, TranscodingJobType.Progressive))
if (File.Exists(outputPath) && !ApiEntryPoint.Instance.HasActiveTranscodingJob(outputPath, TranscodingJobType.Progressive))
{
return ToStaticFileResult(outputPath);
}
@ -130,7 +130,7 @@ namespace MediaBrowser.Api.Playback.Progressive
}
else
{
ServerEntryPoint.Instance.OnTranscodeBeginRequest(outputPath, TranscodingJobType.Progressive);
ApiEntryPoint.Instance.OnTranscodeBeginRequest(outputPath, TranscodingJobType.Progressive);
}
return new ProgressiveStreamWriter

View File

@ -41,7 +41,7 @@ namespace MediaBrowser.Api.Playback.Progressive
}
finally
{
ServerEntryPoint.Instance.OnTranscodeEndRequest(Path, TranscodingJobType.Progressive);
ApiEntryPoint.Instance.OnTranscodeEndRequest(Path, TranscodingJobType.Progressive);
}
}

View File

@ -19,6 +19,7 @@ namespace MediaBrowser.Api
/// Class Plugins
/// </summary>
[Route("/Plugins", "GET")]
[ServiceStack.ServiceHost.Api(("Gets a list of currently installed plugins"))]
public class GetPlugins : IReturn<List<PluginInfo>>
{
}
@ -27,12 +28,14 @@ namespace MediaBrowser.Api
/// Class GetPluginAssembly
/// </summary>
[Route("/Plugins/{Id}/Assembly", "GET")]
[ServiceStack.ServiceHost.Api(("Gets a plugin assembly file"))]
public class GetPluginAssembly
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public Guid Id { get; set; }
}
@ -40,12 +43,14 @@ namespace MediaBrowser.Api
/// Class UninstallPlugin
/// </summary>
[Route("/Plugins/{Id}", "DELETE")]
[ServiceStack.ServiceHost.Api(("Uninstalls a plugin"))]
public class UninstallPlugin : IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
public Guid Id { get; set; }
}
@ -53,12 +58,14 @@ namespace MediaBrowser.Api
/// Class GetPluginConfiguration
/// </summary>
[Route("/Plugins/{Id}/Configuration", "GET")]
[ServiceStack.ServiceHost.Api(("Gets a plugin's configuration"))]
public class GetPluginConfiguration
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public Guid Id { get; set; }
}
@ -66,12 +73,14 @@ namespace MediaBrowser.Api
/// Class UpdatePluginConfiguration
/// </summary>
[Route("/Plugins/{Id}/Configuration", "POST")]
[ServiceStack.ServiceHost.Api(("Updates a plugin's configuration"))]
public class UpdatePluginConfiguration : IRequiresRequestStream, IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public Guid Id { get; set; }
/// <summary>
@ -85,12 +94,14 @@ namespace MediaBrowser.Api
/// Class GetPluginConfigurationFile
/// </summary>
[Route("/Plugins/{Id}/ConfigurationFile", "GET")]
[ServiceStack.ServiceHost.Api(("Gets a plugin's configuration file, in plain text"))]
public class GetPluginConfigurationFile
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public Guid Id { get; set; }
}
@ -98,6 +109,7 @@ namespace MediaBrowser.Api
/// Class GetPluginSecurityInfo
/// </summary>
[Route("/Plugins/SecurityInfo", "GET")]
[ServiceStack.ServiceHost.Api(("Gets plugin registration information"))]
public class GetPluginSecurityInfo : IReturn<PluginSecurityInfo>
{
}
@ -106,6 +118,7 @@ namespace MediaBrowser.Api
/// Class UpdatePluginSecurityInfo
/// </summary>
[Route("/Plugins/SecurityInfo", "POST")]
[ServiceStack.ServiceHost.Api(("Updates plugin registration information"))]
public class UpdatePluginSecurityInfo : PluginSecurityInfo, IReturnVoid
{
}

View File

@ -1,5 +1,4 @@
using MediaBrowser.Common;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Model.Configuration;
@ -17,6 +16,7 @@ namespace MediaBrowser.Api
/// Class GetSystemInfo
/// </summary>
[Route("/System/Info", "GET")]
[ServiceStack.ServiceHost.Api(Description = "Gets information about the server")]
public class GetSystemInfo : IReturn<SystemInfo>
{
@ -32,6 +32,7 @@ namespace MediaBrowser.Api
}
[Route("/System/Shutdown", "POST")]
[ServiceStack.ServiceHost.Api(("Shuts down the application"))]
public class ShutdownApplication
{
}
@ -40,6 +41,7 @@ namespace MediaBrowser.Api
/// Class GetConfiguration
/// </summary>
[Route("/System/Configuration", "GET")]
[ServiceStack.ServiceHost.Api(("Gets application configuration"))]
public class GetConfiguration : IReturn<ServerConfiguration>
{
@ -49,6 +51,7 @@ namespace MediaBrowser.Api
/// Class UpdateConfiguration
/// </summary>
[Route("/System/Configuration", "POST")]
[ServiceStack.ServiceHost.Api(("Updates application configuration"))]
public class UpdateConfiguration : ServerConfiguration, IReturnVoid
{
}

View File

@ -24,6 +24,7 @@ namespace MediaBrowser.Api
/// Class GetUser
/// </summary>
[Route("/Users/{Id}", "GET")]
[ServiceStack.ServiceHost.Api(Description = "Gets a user by Id")]
public class GetUser : IReturn<UserDto>
{
/// <summary>
@ -38,13 +39,14 @@ namespace MediaBrowser.Api
/// Class DeleteUser
/// </summary>
[Route("/Users/{Id}", "DELETE")]
[ServiceStack.ServiceHost.Api(Description = "Deletes a user")]
public class DeleteUser : IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
[ApiMember(Name = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
public Guid Id { get; set; }
}
@ -52,20 +54,21 @@ namespace MediaBrowser.Api
/// Class AuthenticateUser
/// </summary>
[Route("/Users/{Id}/Authenticate", "POST")]
[ServiceStack.ServiceHost.Api(Description = "Authenticates a user")]
public class AuthenticateUser : IReturnVoid
{
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
[ApiMember(Name = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
[ApiMember(Name = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public Guid Id { get; set; }
/// <summary>
/// Gets or sets the password.
/// </summary>
/// <value>The password.</value>
[ApiMember(Name = "Password", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "GET")]
[ApiMember(Name = "Password", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "POST")]
public string Password { get; set; }
}
@ -73,6 +76,7 @@ namespace MediaBrowser.Api
/// Class UpdateUserPassword
/// </summary>
[Route("/Users/{Id}/Password", "POST")]
[ServiceStack.ServiceHost.Api(Description = "Updates a user's password")]
public class UpdateUserPassword : IReturnVoid
{
/// <summary>
@ -104,6 +108,7 @@ namespace MediaBrowser.Api
/// Class UpdateUser
/// </summary>
[Route("/Users/{Id}", "POST")]
[ServiceStack.ServiceHost.Api(Description = "Updates a user")]
public class UpdateUser : UserDto, IReturnVoid
{
}
@ -112,6 +117,7 @@ namespace MediaBrowser.Api
/// Class CreateUser
/// </summary>
[Route("/Users", "POST")]
[ServiceStack.ServiceHost.Api(Description = "Creates a user")]
public class CreateUser : UserDto, IReturn<UserDto>
{
}
@ -126,11 +132,6 @@ namespace MediaBrowser.Api
/// </summary>
private readonly IXmlSerializer _xmlSerializer;
/// <summary>
/// The _json serializer
/// </summary>
private readonly IJsonSerializer _jsonSerializer;
/// <summary>
/// The _user manager
/// </summary>
@ -140,22 +141,15 @@ namespace MediaBrowser.Api
/// Initializes a new instance of the <see cref="UserService" /> class.
/// </summary>
/// <param name="xmlSerializer">The XML serializer.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <exception cref="System.ArgumentNullException">xmlSerializer</exception>
public UserService(IXmlSerializer xmlSerializer, IJsonSerializer jsonSerializer, IUserManager userManager)
public UserService(IXmlSerializer xmlSerializer, IUserManager userManager)
: base()
{
if (jsonSerializer == null)
{
throw new ArgumentNullException("jsonSerializer");
}
if (xmlSerializer == null)
{
throw new ArgumentNullException("xmlSerializer");
}
_jsonSerializer = jsonSerializer;
_xmlSerializer = xmlSerializer;
_userManager = userManager;
}

View File

@ -295,7 +295,7 @@ namespace MediaBrowser.ServerApplication
}
// Include composable parts in the Api assembly
yield return typeof(ApiService).Assembly;
yield return typeof(ApiEntryPoint).Assembly;
// Include composable parts in the Dashboard assembly
yield return typeof(DashboardInfo).Assembly;

View File

@ -574,7 +574,7 @@ var Dashboard = {
var promise;
if (path === "Network") {
promise = ApiClient.getNetworkComputers();
promise = ApiClient.getNetworkDevices();
}
else if (path) {
promise = ApiClient.getDirectoryContents(path, { includeDirectories: true });