jellyfin-server/Jellyfin.Server/Extensions/ApiApplicationBuilderExtensions.cs

102 lines
4.2 KiB
C#
Raw Normal View History

2020-09-03 09:32:22 +00:00
using Jellyfin.Server.Middleware;
using MediaBrowser.Controller.Configuration;
2019-11-23 18:43:30 +00:00
using Microsoft.AspNetCore.Builder;
namespace Jellyfin.Server.Extensions
2019-11-23 18:43:30 +00:00
{
2019-11-23 19:31:17 +00:00
/// <summary>
/// Extensions for adding API specific functionality to the application pipeline.
/// </summary>
2019-11-23 18:43:30 +00:00
public static class ApiApplicationBuilderExtensions
{
2019-11-23 19:31:17 +00:00
/// <summary>
/// Adds swagger and swagger UI to the application pipeline.
/// </summary>
/// <param name="applicationBuilder">The application builder.</param>
/// <param name="serverConfigurationManager">The server configuration.</param>
2019-11-23 19:31:17 +00:00
/// <returns>The updated application builder.</returns>
public static IApplicationBuilder UseJellyfinApiSwagger(
this IApplicationBuilder applicationBuilder,
IServerConfigurationManager serverConfigurationManager)
2019-11-23 18:43:30 +00:00
{
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
var baseUrl = serverConfigurationManager.Configuration.BaseUrl.Trim('/');
if (!string.IsNullOrEmpty(baseUrl))
{
baseUrl += '/';
}
2020-04-19 17:28:56 +00:00
return applicationBuilder
.UseSwagger(c =>
{
2020-04-29 14:04:05 +00:00
// Custom path requires {documentName}, SwaggerDoc documentName is 'api-docs'
c.RouteTemplate = $"/{baseUrl}{{documentName}}/openapi.json";
})
2020-04-19 16:51:51 +00:00
.UseSwaggerUI(c =>
{
2020-04-29 14:04:05 +00:00
c.DocumentTitle = "Jellyfin API";
c.SwaggerEndpoint($"/{baseUrl}api-docs/openapi.json", "Jellyfin API");
c.RoutePrefix = $"{baseUrl}api-docs/swagger";
2020-04-19 16:51:51 +00:00
})
.UseReDoc(c =>
{
2020-04-29 14:04:05 +00:00
c.DocumentTitle = "Jellyfin API";
c.SpecUrl($"/{baseUrl}api-docs/openapi.json");
c.RoutePrefix = $"{baseUrl}api-docs/redoc";
2020-04-19 16:51:51 +00:00
});
2019-11-23 18:43:30 +00:00
}
2020-09-03 09:32:22 +00:00
/// <summary>
/// Adds IP based access validation to the application pipeline.
/// </summary>
/// <param name="appBuilder">The application builder.</param>
/// <returns>The updated application builder.</returns>
public static IApplicationBuilder UseIpBasedAccessValidation(this IApplicationBuilder appBuilder)
{
return appBuilder.UseMiddleware<IpBasedAccessValidationMiddleware>();
}
/// <summary>
/// Adds LAN based access filtering to the application pipeline.
/// </summary>
/// <param name="appBuilder">The application builder.</param>
/// <returns>The updated application builder.</returns>
public static IApplicationBuilder UseLanFiltering(this IApplicationBuilder appBuilder)
{
return appBuilder.UseMiddleware<LanFilteringMiddleware>();
}
/// <summary>
/// Adds base url redirection to the application pipeline.
/// </summary>
/// <param name="appBuilder">The application builder.</param>
/// <returns>The updated application builder.</returns>
public static IApplicationBuilder UseBaseUrlRedirection(this IApplicationBuilder appBuilder)
{
return appBuilder.UseMiddleware<BaseUrlRedirectionMiddleware>();
}
/// <summary>
/// Adds a custom message during server startup to the application pipeline.
/// </summary>
/// <param name="appBuilder">The application builder.</param>
/// <returns>The updated application builder.</returns>
public static IApplicationBuilder UseServerStartupMessage(this IApplicationBuilder appBuilder)
{
return appBuilder.UseMiddleware<ServerStartupMessageMiddleware>();
}
/// <summary>
/// Adds a WebSocket request handler to the application pipeline.
/// </summary>
/// <param name="appBuilder">The application builder.</param>
/// <returns>The updated application builder.</returns>
public static IApplicationBuilder UseWebSocketHandler(this IApplicationBuilder appBuilder)
{
return appBuilder.UseMiddleware<WebSocketHandlerMiddleware>();
}
2019-11-23 18:43:30 +00:00
}
}