parent
c0d10800ab
commit
e5d57bd82f
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Api.Models.Startup;
|
||||||
|
using MediaBrowser.Controller.Configuration;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Jellyfin.Api.Controllers
|
||||||
|
{
|
||||||
|
[ApiVersion("1")]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class StartupController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IServerConfigurationManager _config;
|
||||||
|
private readonly IUserManager _userManager;
|
||||||
|
|
||||||
|
public StartupController(IServerConfigurationManager config, IUserManager userManager)
|
||||||
|
{
|
||||||
|
_config = config;
|
||||||
|
_userManager = userManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("Complete")]
|
||||||
|
public void Post()
|
||||||
|
{
|
||||||
|
_config.Configuration.IsStartupWizardCompleted = true;
|
||||||
|
_config.SetOptimalValues();
|
||||||
|
_config.SaveConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("Configuration")]
|
||||||
|
public StartupConfiguration Get()
|
||||||
|
{
|
||||||
|
var result = new StartupConfiguration
|
||||||
|
{
|
||||||
|
UICulture = _config.Configuration.UICulture,
|
||||||
|
MetadataCountryCode = _config.Configuration.MetadataCountryCode,
|
||||||
|
PreferredMetadataLanguage = _config.Configuration.PreferredMetadataLanguage
|
||||||
|
};
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("Configuration")]
|
||||||
|
public void UpdateInitial([FromForm] string uiCulture, [FromForm] string metadataCountryCode, [FromForm] string preferredMetadataLanguage)
|
||||||
|
{
|
||||||
|
_config.Configuration.UICulture = uiCulture;
|
||||||
|
_config.Configuration.MetadataCountryCode = metadataCountryCode;
|
||||||
|
_config.Configuration.PreferredMetadataLanguage = preferredMetadataLanguage;
|
||||||
|
_config.SaveConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("RemoteAccess")]
|
||||||
|
public void Post([FromForm] bool enableRemoteAccess, [FromForm] bool enableAutomaticPortMapping)
|
||||||
|
{
|
||||||
|
_config.Configuration.EnableRemoteAccess = enableRemoteAccess;
|
||||||
|
_config.Configuration.EnableUPnP = enableAutomaticPortMapping;
|
||||||
|
_config.SaveConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("User")]
|
||||||
|
public StartupUser GetUser()
|
||||||
|
{
|
||||||
|
var user = _userManager.Users.First();
|
||||||
|
|
||||||
|
return new StartupUser
|
||||||
|
{
|
||||||
|
Name = user.Name,
|
||||||
|
Password = user.Password
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("User")]
|
||||||
|
public async Task Post([FromForm] StartupUser startupUser)
|
||||||
|
{
|
||||||
|
var user = _userManager.Users.First();
|
||||||
|
|
||||||
|
user.Name = startupUser.Name;
|
||||||
|
|
||||||
|
_userManager.UpdateUser(user);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(startupUser.Password))
|
||||||
|
{
|
||||||
|
await _userManager.ChangePassword(user, startupUser.Password).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.3" />
|
||||||
|
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace Jellyfin.Api.Models.Startup
|
||||||
|
{
|
||||||
|
public class StartupConfiguration
|
||||||
|
{
|
||||||
|
public string UICulture { get; set; }
|
||||||
|
public string MetadataCountryCode { get; set; }
|
||||||
|
public string PreferredMetadataLanguage { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
namespace Jellyfin.Api.Models.Startup
|
||||||
|
{
|
||||||
|
public class StartupUser
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,135 +0,0 @@
|
|||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Common.Net;
|
|
||||||
using MediaBrowser.Controller;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
|
||||||
using MediaBrowser.Controller.Library;
|
|
||||||
using MediaBrowser.Controller.MediaEncoding;
|
|
||||||
using MediaBrowser.Controller.Net;
|
|
||||||
using MediaBrowser.Model.Services;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Api
|
|
||||||
{
|
|
||||||
[Route("/Startup/Complete", "POST", Summary = "Reports that the startup wizard has been completed", IsHidden = true)]
|
|
||||||
public class ReportStartupWizardComplete : IReturnVoid
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/Startup/Configuration", "GET", Summary = "Gets initial server configuration", IsHidden = true)]
|
|
||||||
public class GetStartupConfiguration : IReturn<StartupConfiguration>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/Startup/Configuration", "POST", Summary = "Updates initial server configuration", IsHidden = true)]
|
|
||||||
public class UpdateStartupConfiguration : StartupConfiguration, IReturnVoid
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/Startup/RemoteAccess", "POST", Summary = "Updates initial server configuration", IsHidden = true)]
|
|
||||||
public class UpdateRemoteAccessConfiguration : IReturnVoid
|
|
||||||
{
|
|
||||||
public bool EnableRemoteAccess { get; set; }
|
|
||||||
public bool EnableAutomaticPortMapping { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/Startup/User", "GET", Summary = "Gets initial user info", IsHidden = true)]
|
|
||||||
public class GetStartupUser : IReturn<StartupUser>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Route("/Startup/User", "POST", Summary = "Updates initial user info", IsHidden = true)]
|
|
||||||
public class UpdateStartupUser : StartupUser
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Authenticated(AllowBeforeStartupWizard = true, Roles = "Admin")]
|
|
||||||
public class StartupWizardService : BaseApiService
|
|
||||||
{
|
|
||||||
private readonly IServerConfigurationManager _config;
|
|
||||||
private readonly IServerApplicationHost _appHost;
|
|
||||||
private readonly IUserManager _userManager;
|
|
||||||
private readonly IMediaEncoder _mediaEncoder;
|
|
||||||
private readonly IHttpClient _httpClient;
|
|
||||||
|
|
||||||
public StartupWizardService(IServerConfigurationManager config, IHttpClient httpClient, IServerApplicationHost appHost, IUserManager userManager, IMediaEncoder mediaEncoder)
|
|
||||||
{
|
|
||||||
_config = config;
|
|
||||||
_appHost = appHost;
|
|
||||||
_userManager = userManager;
|
|
||||||
_mediaEncoder = mediaEncoder;
|
|
||||||
_httpClient = httpClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Post(ReportStartupWizardComplete request)
|
|
||||||
{
|
|
||||||
_config.Configuration.IsStartupWizardCompleted = true;
|
|
||||||
_config.SetOptimalValues();
|
|
||||||
_config.SaveConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Get(GetStartupConfiguration request)
|
|
||||||
{
|
|
||||||
var result = new StartupConfiguration
|
|
||||||
{
|
|
||||||
UICulture = _config.Configuration.UICulture,
|
|
||||||
MetadataCountryCode = _config.Configuration.MetadataCountryCode,
|
|
||||||
PreferredMetadataLanguage = _config.Configuration.PreferredMetadataLanguage
|
|
||||||
};
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Post(UpdateStartupConfiguration request)
|
|
||||||
{
|
|
||||||
_config.Configuration.UICulture = request.UICulture;
|
|
||||||
_config.Configuration.MetadataCountryCode = request.MetadataCountryCode;
|
|
||||||
_config.Configuration.PreferredMetadataLanguage = request.PreferredMetadataLanguage;
|
|
||||||
_config.SaveConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Post(UpdateRemoteAccessConfiguration request)
|
|
||||||
{
|
|
||||||
_config.Configuration.EnableRemoteAccess = request.EnableRemoteAccess;
|
|
||||||
_config.Configuration.EnableUPnP = request.EnableAutomaticPortMapping;
|
|
||||||
_config.SaveConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Get(GetStartupUser request)
|
|
||||||
{
|
|
||||||
var user = _userManager.Users.First();
|
|
||||||
|
|
||||||
return new StartupUser
|
|
||||||
{
|
|
||||||
Name = user.Name,
|
|
||||||
Password = user.Password
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Post(UpdateStartupUser request)
|
|
||||||
{
|
|
||||||
var user = _userManager.Users.First();
|
|
||||||
|
|
||||||
user.Name = request.Name;
|
|
||||||
|
|
||||||
_userManager.UpdateUser(user);
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(request.Password))
|
|
||||||
{
|
|
||||||
await _userManager.ChangePassword(user, request.Password).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class StartupConfiguration
|
|
||||||
{
|
|
||||||
public string UICulture { get; set; }
|
|
||||||
public string MetadataCountryCode { get; set; }
|
|
||||||
public string PreferredMetadataLanguage { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class StartupUser
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
public string Password { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue