SwaggerService.cs 1.4 KB

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