mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-02-21 20:12:48 +00:00
Move StartupWizard to ASP.NET Web Api
This commit is contained in:
48
Emby.Server.Implementations/MvcRoutePrefix.cs
Normal file
48
Emby.Server.Implementations/MvcRoutePrefix.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
||||
|
||||
namespace Emby.Server.Implementations
|
||||
{
|
||||
public static class MvcRoutePrefix
|
||||
{
|
||||
public static void UseGeneralRoutePrefix(this MvcOptions opts, params string[] prefixes)
|
||||
{
|
||||
opts.Conventions.Insert(0, new RoutePrefixConvention(prefixes));
|
||||
}
|
||||
|
||||
internal class RoutePrefixConvention : IApplicationModelConvention
|
||||
{
|
||||
private readonly AttributeRouteModel[] _routePrefixes;
|
||||
|
||||
public RoutePrefixConvention(IEnumerable<string> prefixes)
|
||||
{
|
||||
_routePrefixes = prefixes.Select(p => new AttributeRouteModel(new RouteAttribute(p))).ToArray();
|
||||
}
|
||||
|
||||
public void Apply(ApplicationModel application)
|
||||
{
|
||||
foreach (var controller in application.Controllers)
|
||||
{
|
||||
if (controller.Selectors == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var newSelectors = new List<SelectorModel>();
|
||||
foreach (var selector in controller.Selectors)
|
||||
{
|
||||
newSelectors.AddRange(_routePrefixes.Select(routePrefix => new SelectorModel(selector)
|
||||
{
|
||||
AttributeRouteModel = AttributeRouteModel.CombineAttributeRouteModel(routePrefix, selector.AttributeRouteModel)
|
||||
}));
|
||||
}
|
||||
|
||||
controller.Selectors.Clear();
|
||||
newSelectors.ForEach(selector => controller.Selectors.Add(selector));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user