2019-07-02 10:21:54 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Jellyfin.Api.Models.Startup;
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
using MediaBrowser.Controller.Library;
|
2019-11-23 15:31:02 +00:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2019-07-02 10:21:54 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Controllers
|
|
|
|
{
|
2019-11-23 15:31:02 +00:00
|
|
|
[Authorize(Policy = "FirstTimeSetupOrElevated")]
|
|
|
|
public class StartupController : BaseJellyfinApiController
|
2019-07-02 10:21:54 +00:00
|
|
|
{
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
|
|
|
|
public StartupController(IServerConfigurationManager config, IUserManager userManager)
|
|
|
|
{
|
|
|
|
_config = config;
|
|
|
|
_userManager = userManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost("Complete")]
|
2019-07-02 18:17:00 +00:00
|
|
|
public void CompleteWizard()
|
2019-07-02 10:21:54 +00:00
|
|
|
{
|
|
|
|
_config.Configuration.IsStartupWizardCompleted = true;
|
|
|
|
_config.SetOptimalValues();
|
|
|
|
_config.SaveConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("Configuration")]
|
2019-11-23 15:31:02 +00:00
|
|
|
public StartupConfigurationDto GetStartupConfiguration()
|
2019-07-02 10:21:54 +00:00
|
|
|
{
|
2019-11-23 15:31:02 +00:00
|
|
|
var result = new StartupConfigurationDto
|
2019-07-02 10:21:54 +00:00
|
|
|
{
|
|
|
|
UICulture = _config.Configuration.UICulture,
|
|
|
|
MetadataCountryCode = _config.Configuration.MetadataCountryCode,
|
|
|
|
PreferredMetadataLanguage = _config.Configuration.PreferredMetadataLanguage
|
|
|
|
};
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost("Configuration")]
|
2019-11-23 18:59:45 +00:00
|
|
|
public void UpdateInitialConfiguration(
|
|
|
|
[FromForm] string uiCulture,
|
|
|
|
[FromForm] string metadataCountryCode,
|
|
|
|
[FromForm] string preferredMetadataLanguage)
|
2019-07-02 10:21:54 +00:00
|
|
|
{
|
|
|
|
_config.Configuration.UICulture = uiCulture;
|
|
|
|
_config.Configuration.MetadataCountryCode = metadataCountryCode;
|
|
|
|
_config.Configuration.PreferredMetadataLanguage = preferredMetadataLanguage;
|
|
|
|
_config.SaveConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost("RemoteAccess")]
|
2019-11-23 15:31:02 +00:00
|
|
|
public void SetRemoteAccess([FromForm] bool enableRemoteAccess, [FromForm] bool enableAutomaticPortMapping)
|
2019-07-02 10:21:54 +00:00
|
|
|
{
|
|
|
|
_config.Configuration.EnableRemoteAccess = enableRemoteAccess;
|
|
|
|
_config.Configuration.EnableUPnP = enableAutomaticPortMapping;
|
|
|
|
_config.SaveConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("User")]
|
2019-11-23 15:31:02 +00:00
|
|
|
public StartupUserDto GetUser()
|
2019-07-02 10:21:54 +00:00
|
|
|
{
|
|
|
|
var user = _userManager.Users.First();
|
|
|
|
|
2019-11-23 15:31:02 +00:00
|
|
|
return new StartupUserDto
|
2019-07-02 10:21:54 +00:00
|
|
|
{
|
|
|
|
Name = user.Name,
|
|
|
|
Password = user.Password
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost("User")]
|
2019-11-23 15:31:02 +00:00
|
|
|
public async Task UpdateUser([FromForm] StartupUserDto startupUserDto)
|
2019-07-02 10:21:54 +00:00
|
|
|
{
|
|
|
|
var user = _userManager.Users.First();
|
|
|
|
|
2019-11-23 15:31:02 +00:00
|
|
|
user.Name = startupUserDto.Name;
|
2019-07-02 10:21:54 +00:00
|
|
|
|
|
|
|
_userManager.UpdateUser(user);
|
|
|
|
|
2019-11-23 15:31:02 +00:00
|
|
|
if (!string.IsNullOrEmpty(startupUserDto.Password))
|
2019-07-02 10:21:54 +00:00
|
|
|
{
|
2019-11-23 15:31:02 +00:00
|
|
|
await _userManager.ChangePassword(user, startupUserDto.Password).ConfigureAwait(false);
|
2019-07-02 10:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|