jellyfin-server/MediaBrowser.Api/StartupWizardService.cs

166 lines
5.5 KiB
C#
Raw Normal View History

2017-03-13 18:57:45 +00:00
using MediaBrowser.Controller;
2014-11-15 02:31:03 +00:00
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Connect;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Configuration;
using System;
using System.Linq;
using System.Threading.Tasks;
2016-06-23 17:04:18 +00:00
using MediaBrowser.Controller.MediaEncoding;
2016-10-25 19:02:04 +00:00
using MediaBrowser.Model.Services;
2014-11-15 02:31:03 +00:00
namespace MediaBrowser.Api
{
[Route("/Startup/Complete", "POST", Summary = "Reports that the startup wizard has been completed")]
public class ReportStartupWizardComplete : IReturnVoid
{
}
[Route("/Startup/Info", "GET", Summary = "Gets initial server info")]
public class GetStartupInfo : IReturn<StartupInfo>
{
}
[Route("/Startup/Configuration", "GET", Summary = "Gets initial server configuration")]
public class GetStartupConfiguration : IReturn<StartupConfiguration>
{
}
[Route("/Startup/Configuration", "POST", Summary = "Updates initial server configuration")]
public class UpdateStartupConfiguration : StartupConfiguration, IReturnVoid
{
}
[Route("/Startup/User", "GET", Summary = "Gets initial user info")]
public class GetStartupUser : IReturn<StartupUser>
{
}
[Route("/Startup/User", "POST", Summary = "Updates initial user info")]
public class UpdateStartupUser : StartupUser, IReturn<UpdateStartupUserResult>
{
}
[Authenticated(AllowBeforeStartupWizard = true, Roles = "Admin")]
public class StartupWizardService : BaseApiService
{
private readonly IServerConfigurationManager _config;
private readonly IServerApplicationHost _appHost;
private readonly IUserManager _userManager;
private readonly IConnectManager _connectManager;
2016-06-23 17:04:18 +00:00
private readonly IMediaEncoder _mediaEncoder;
2014-11-15 02:31:03 +00:00
2017-03-13 18:57:45 +00:00
public StartupWizardService(IServerConfigurationManager config, IServerApplicationHost appHost, IUserManager userManager, IConnectManager connectManager, IMediaEncoder mediaEncoder)
2014-11-15 02:31:03 +00:00
{
_config = config;
_appHost = appHost;
_userManager = userManager;
_connectManager = connectManager;
2016-06-23 17:04:18 +00:00
_mediaEncoder = mediaEncoder;
2014-11-15 02:31:03 +00:00
}
public void Post(ReportStartupWizardComplete request)
{
_config.Configuration.IsStartupWizardCompleted = true;
2016-05-20 20:21:34 +00:00
SetWizardFinishValues(_config.Configuration);
2014-11-15 02:31:03 +00:00
_config.SaveConfiguration();
}
2017-09-10 21:32:45 +00:00
public object Get(GetStartupInfo request)
2014-11-15 02:31:03 +00:00
{
return new StartupInfo
{
2016-06-23 17:04:18 +00:00
HasMediaEncoder = !string.IsNullOrWhiteSpace(_mediaEncoder.EncoderPath)
2014-11-15 02:31:03 +00:00
};
}
public object Get(GetStartupConfiguration request)
{
2015-08-20 20:57:29 +00:00
var result = new StartupConfiguration
2014-11-15 02:31:03 +00:00
{
UICulture = _config.Configuration.UICulture,
MetadataCountryCode = _config.Configuration.MetadataCountryCode,
PreferredMetadataLanguage = _config.Configuration.PreferredMetadataLanguage
};
2015-08-20 20:57:29 +00:00
return result;
2014-11-15 02:31:03 +00:00
}
2016-05-20 20:21:34 +00:00
private void SetWizardFinishValues(ServerConfiguration config)
{
config.EnableCaseSensitiveItemIds = true;
2016-10-08 05:57:38 +00:00
config.SkipDeserializationForBasicTypes = true;
2017-01-29 20:00:29 +00:00
config.EnableLocalizedGuids = true;
2017-02-08 19:52:21 +00:00
config.EnableSimpleArtistDetection = true;
2017-03-13 04:08:23 +00:00
config.EnableNormalizedItemByNameIds = true;
2017-04-22 19:32:24 +00:00
config.DisableLiveTvChannelUserDataName = true;
2017-10-05 18:10:07 +00:00
config.EnableNewOmdbSupport = true;
2016-05-20 20:21:34 +00:00
}
2014-11-15 02:31:03 +00:00
public void Post(UpdateStartupConfiguration request)
{
_config.Configuration.UICulture = request.UICulture;
_config.Configuration.MetadataCountryCode = request.MetadataCountryCode;
_config.Configuration.PreferredMetadataLanguage = request.PreferredMetadataLanguage;
_config.SaveConfiguration();
}
public object Get(GetStartupUser request)
{
var user = _userManager.Users.First();
return new StartupUser
{
Name = user.Name,
ConnectUserName = user.ConnectUserName
};
}
public async Task<object> Post(UpdateStartupUser request)
{
var user = _userManager.Users.First();
user.Name = request.Name;
_userManager.UpdateUser(user);
2014-11-15 02:31:03 +00:00
var result = new UpdateStartupUserResult();
if (!string.IsNullOrWhiteSpace(user.ConnectUserName) &&
string.IsNullOrWhiteSpace(request.ConnectUserName))
{
await _connectManager.RemoveConnect(user.Id.ToString("N")).ConfigureAwait(false);
}
else if (!string.Equals(user.ConnectUserName, request.ConnectUserName, StringComparison.OrdinalIgnoreCase))
{
result.UserLinkResult = await _connectManager.LinkUser(user.Id.ToString("N"), request.ConnectUserName).ConfigureAwait(false);
}
return result;
}
}
public class StartupConfiguration
{
public string UICulture { get; set; }
public string MetadataCountryCode { get; set; }
public string PreferredMetadataLanguage { get; set; }
}
public class StartupInfo
{
2016-06-23 17:04:18 +00:00
public bool HasMediaEncoder { get; set; }
2014-11-15 02:31:03 +00:00
}
public class StartupUser
{
public string Name { get; set; }
public string ConnectUserName { get; set; }
}
public class UpdateStartupUserResult
{
public UserLinkResult UserLinkResult { get; set; }
}
}