2014-11-26 21:57:16 +01:00
|
|
|
|
using MediaBrowser.Controller;
|
2013-12-07 16:52:38 +01:00
|
|
|
|
using MediaBrowser.Controller.Net;
|
2013-03-05 04:34:02 +01:00
|
|
|
|
using System.IO;
|
2016-11-05 03:17:18 +01:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-10-25 21:02:04 +02:00
|
|
|
|
using MediaBrowser.Model.Services;
|
2013-03-05 04:34:02 +01:00
|
|
|
|
|
2016-11-05 03:17:18 +01:00
|
|
|
|
namespace Emby.Server.Implementations.HttpServer
|
2013-03-05 04:34:02 +01:00
|
|
|
|
{
|
2016-11-10 15:41:24 +01:00
|
|
|
|
public class SwaggerService : IService, IRequiresRequest
|
2013-03-05 04:34:02 +01:00
|
|
|
|
{
|
2014-11-26 21:57:16 +01:00
|
|
|
|
private readonly IServerApplicationPaths _appPaths;
|
2016-11-05 03:17:18 +01:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2013-12-04 15:52:38 +01:00
|
|
|
|
|
2016-11-10 15:41:24 +01:00
|
|
|
|
public SwaggerService(IServerApplicationPaths appPaths, IFileSystem fileSystem, IHttpResultFactory resultFactory)
|
2013-12-04 15:52:38 +01:00
|
|
|
|
{
|
|
|
|
|
_appPaths = appPaths;
|
2016-11-05 03:17:18 +01:00
|
|
|
|
_fileSystem = fileSystem;
|
2016-11-10 15:41:24 +01:00
|
|
|
|
_resultFactory = resultFactory;
|
2013-12-04 15:52:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 04:34:02 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetSwaggerResource request)
|
|
|
|
|
{
|
2014-11-26 21:57:16 +01:00
|
|
|
|
var swaggerDirectory = Path.Combine(_appPaths.ApplicationResourcesPath, "swagger-ui");
|
2013-03-05 04:34:02 +01:00
|
|
|
|
|
2016-11-05 03:17:18 +01:00
|
|
|
|
var requestedFile = Path.Combine(swaggerDirectory, request.ResourceName.Replace('/', _fileSystem.DirectorySeparatorChar));
|
2013-03-05 04:34:02 +01:00
|
|
|
|
|
2016-11-10 15:41:24 +01:00
|
|
|
|
return _resultFactory.GetStaticFileResult(Request, requestedFile).Result;
|
2013-03-05 04:34:02 +01:00
|
|
|
|
}
|
2013-03-24 03:45:00 +01:00
|
|
|
|
|
2013-04-14 20:09:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the result factory.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The result factory.</value>
|
2016-11-10 15:41:24 +01:00
|
|
|
|
private readonly IHttpResultFactory _resultFactory;
|
2013-04-14 20:09:40 +02:00
|
|
|
|
|
2013-03-24 03:45:00 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the request context.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The request context.</value>
|
2013-12-07 16:52:38 +01:00
|
|
|
|
public IRequest Request { get; set; }
|
2013-03-05 04:34:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|