aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations
diff options
context:
space:
mode:
authorClaus Vium <clausvium@gmail.com>2019-07-02 12:21:54 +0200
committerClaus Vium <clausvium@gmail.com>2019-11-19 21:48:16 +0100
commite5d57bd82f9a089b7c19ea357efd2b8b34fd418b (patch)
treec6eb554c5e8a33af9cb170fbbbb1779d108cbae8 /Emby.Server.Implementations
parentc0d10800ab6c029b891af5caf5d0fccaf76816d3 (diff)
Move StartupWizard to ASP.NET Web Api
Diffstat (limited to 'Emby.Server.Implementations')
-rw-r--r--Emby.Server.Implementations/ApplicationHost.cs15
-rw-r--r--Emby.Server.Implementations/Emby.Server.Implementations.csproj2
-rw-r--r--Emby.Server.Implementations/MvcRoutePrefix.cs48
3 files changed, 63 insertions, 2 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index fef461b9a..a9c4e1fdc 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -108,6 +108,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
+using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -611,8 +612,6 @@ namespace Emby.Server.Implementations
await RegisterResources(serviceCollection).ConfigureAwait(false);
- FindParts();
-
string contentRoot = ServerConfigurationManager.Configuration.DashboardSourcePath;
if (string.IsNullOrEmpty(contentRoot))
{
@@ -657,6 +656,14 @@ namespace Emby.Server.Implementations
{
services.AddResponseCompression();
services.AddHttpContextAccessor();
+ services.AddMvc(opts =>
+ {
+ opts.UseGeneralRoutePrefix("emby", "emby/emby", "api/v{version:apiVersion}");
+ })
+ .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
+ .AddApplicationPart(Assembly.Load("Jellyfin.Api"));
+ services.AddApiVersioning(opt => opt.ReportApiVersions = true);
+ services.TryAdd(serviceCollection);
})
.Configure(app =>
{
@@ -666,10 +673,14 @@ namespace Emby.Server.Implementations
// TODO app.UseMiddleware<WebSocketMiddleware>();
app.Use(ExecuteWebsocketHandlerAsync);
+ app.UseMvc();
app.Use(ExecuteHttpHandlerAsync);
})
.Build();
+ _serviceProvider = host.Services;
+ FindParts();
+
try
{
await host.StartAsync().ConfigureAwait(false);
diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj
index 45607dc09..23e35f77e 100644
--- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj
+++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj
@@ -3,6 +3,7 @@
<ItemGroup>
<ProjectReference Include="..\Emby.Naming\Emby.Naming.csproj" />
<ProjectReference Include="..\Emby.Notifications\Emby.Notifications.csproj" />
+ <ProjectReference Include="..\Jellyfin.Api\Jellyfin.Api.csproj" />
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
<ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
@@ -25,6 +26,7 @@
<PackageReference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
+ <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.2.1" />
diff --git a/Emby.Server.Implementations/MvcRoutePrefix.cs b/Emby.Server.Implementations/MvcRoutePrefix.cs
new file mode 100644
index 000000000..fb26ae09d
--- /dev/null
+++ b/Emby.Server.Implementations/MvcRoutePrefix.cs
@@ -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));
+ }
+ }
+ }
+ }
+}