SwaggerService.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using MediaBrowser.Controller;
  2. using MediaBrowser.Controller.Net;
  3. using System.IO;
  4. using MediaBrowser.Model.IO;
  5. using MediaBrowser.Model.Services;
  6. namespace Emby.Server.Implementations.HttpServer
  7. {
  8. public class SwaggerService : IService, IRequiresRequest
  9. {
  10. private readonly IServerApplicationPaths _appPaths;
  11. private readonly IFileSystem _fileSystem;
  12. public SwaggerService(IServerApplicationPaths appPaths, IFileSystem fileSystem, IHttpResultFactory resultFactory)
  13. {
  14. _appPaths = appPaths;
  15. _fileSystem = fileSystem;
  16. _resultFactory = resultFactory;
  17. }
  18. /// <summary>
  19. /// Gets the specified request.
  20. /// </summary>
  21. /// <param name="request">The request.</param>
  22. /// <returns>System.Object.</returns>
  23. public object Get(GetSwaggerResource request)
  24. {
  25. var swaggerDirectory = Path.Combine(_appPaths.ApplicationResourcesPath, "swagger-ui");
  26. var requestedFile = Path.Combine(swaggerDirectory, request.ResourceName.Replace('/', _fileSystem.DirectorySeparatorChar));
  27. return _resultFactory.GetStaticFileResult(Request, requestedFile).Result;
  28. }
  29. /// <summary>
  30. /// Gets or sets the result factory.
  31. /// </summary>
  32. /// <value>The result factory.</value>
  33. private readonly IHttpResultFactory _resultFactory;
  34. /// <summary>
  35. /// Gets or sets the request context.
  36. /// </summary>
  37. /// <value>The request context.</value>
  38. public IRequest Request { get; set; }
  39. }
  40. }