SwaggerService.cs 1.8 KB

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