SwaggerService.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using MediaBrowser.Common.Configuration;
  2. using MediaBrowser.Common.Net;
  3. using ServiceStack.ServiceHost;
  4. using System.IO;
  5. namespace MediaBrowser.Server.Implementations.HttpServer
  6. {
  7. /// <summary>
  8. /// Class GetDashboardResource
  9. /// </summary>
  10. [Route("/swagger-ui/{ResourceName*}", "GET")]
  11. public class GetSwaggerResource
  12. {
  13. /// <summary>
  14. /// Gets or sets the name.
  15. /// </summary>
  16. /// <value>The name.</value>
  17. public string ResourceName { get; set; }
  18. }
  19. public class SwaggerService : IHasResultFactory, IRestfulService
  20. {
  21. private readonly IApplicationPaths _appPaths;
  22. public SwaggerService(IApplicationPaths appPaths)
  23. {
  24. _appPaths = appPaths;
  25. }
  26. /// <summary>
  27. /// Gets the specified request.
  28. /// </summary>
  29. /// <param name="request">The request.</param>
  30. /// <returns>System.Object.</returns>
  31. public object Get(GetSwaggerResource request)
  32. {
  33. var runningDirectory = Path.GetDirectoryName(_appPaths.ApplicationPath);
  34. var swaggerDirectory = Path.Combine(runningDirectory, "swagger-ui");
  35. var requestedFile = Path.Combine(swaggerDirectory, request.ResourceName.Replace('/', Path.DirectorySeparatorChar));
  36. return ResultFactory.GetStaticFileResult(RequestContext, requestedFile);
  37. }
  38. /// <summary>
  39. /// Gets or sets the result factory.
  40. /// </summary>
  41. /// <value>The result factory.</value>
  42. public IHttpResultFactory ResultFactory { get; set; }
  43. /// <summary>
  44. /// Gets or sets the request context.
  45. /// </summary>
  46. /// <value>The request context.</value>
  47. public IRequestContext RequestContext { get; set; }
  48. }
  49. }