SwaggerService.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using ServiceStack.ServiceHost;
  2. using System.Diagnostics;
  3. using System.IO;
  4. namespace MediaBrowser.Server.Implementations.HttpServer
  5. {
  6. /// <summary>
  7. /// Class GetDashboardResource
  8. /// </summary>
  9. [Route("/swagger-ui/{ResourceName*}", "GET")]
  10. public class GetSwaggerResource
  11. {
  12. /// <summary>
  13. /// Gets or sets the name.
  14. /// </summary>
  15. /// <value>The name.</value>
  16. public string ResourceName { get; set; }
  17. }
  18. public class SwaggerService : BaseRestService
  19. {
  20. /// <summary>
  21. /// Gets the specified request.
  22. /// </summary>
  23. /// <param name="request">The request.</param>
  24. /// <returns>System.Object.</returns>
  25. public object Get(GetSwaggerResource request)
  26. {
  27. var runningDirectory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
  28. var swaggerDirectory = Path.Combine(runningDirectory, "swagger-ui");
  29. var requestedFile = Path.Combine(swaggerDirectory, request.ResourceName.Replace('/', '\\'));
  30. return ToStaticFileResult(requestedFile);
  31. }
  32. }
  33. }