2013-12-04 14:52:38 +00:00
|
|
|
|
using MediaBrowser.Common.Configuration;
|
|
|
|
|
using MediaBrowser.Common.Net;
|
2013-03-24 02:45:00 +00:00
|
|
|
|
using ServiceStack.ServiceHost;
|
2013-03-05 03:34:02 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
2013-03-07 05:34:00 +00:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.HttpServer
|
2013-03-05 03:34:02 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetDashboardResource
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/swagger-ui/{ResourceName*}", "GET")]
|
|
|
|
|
public class GetSwaggerResource
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the name.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The name.</value>
|
|
|
|
|
public string ResourceName { get; set; }
|
|
|
|
|
}
|
2013-03-24 02:45:00 +00:00
|
|
|
|
|
2013-04-14 18:09:40 +00:00
|
|
|
|
public class SwaggerService : IHasResultFactory, IRestfulService
|
2013-03-05 03:34:02 +00:00
|
|
|
|
{
|
2013-12-04 14:52:38 +00:00
|
|
|
|
private readonly IApplicationPaths _appPaths;
|
|
|
|
|
|
|
|
|
|
public SwaggerService(IApplicationPaths appPaths)
|
|
|
|
|
{
|
|
|
|
|
_appPaths = appPaths;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 03:34:02 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetSwaggerResource request)
|
|
|
|
|
{
|
2013-12-04 14:52:38 +00:00
|
|
|
|
var runningDirectory = Path.GetDirectoryName(_appPaths.ApplicationPath);
|
2013-03-05 03:34:02 +00:00
|
|
|
|
|
|
|
|
|
var swaggerDirectory = Path.Combine(runningDirectory, "swagger-ui");
|
|
|
|
|
|
|
|
|
|
var requestedFile = Path.Combine(swaggerDirectory, request.ResourceName.Replace('/', '\\'));
|
|
|
|
|
|
2013-04-14 18:09:40 +00:00
|
|
|
|
return ResultFactory.GetStaticFileResult(RequestContext, requestedFile);
|
2013-03-05 03:34:02 +00:00
|
|
|
|
}
|
2013-03-24 02:45:00 +00:00
|
|
|
|
|
2013-04-14 18:09:40 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the result factory.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The result factory.</value>
|
|
|
|
|
public IHttpResultFactory ResultFactory { get; set; }
|
|
|
|
|
|
2013-03-24 02:45:00 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the request context.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The request context.</value>
|
|
|
|
|
public IRequestContext RequestContext { get; set; }
|
2013-03-05 03:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|