From 4915da4cdd9bd7de3f67fa681e06585dbbcfafdb Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 17 Mar 2015 01:58:29 -0400 Subject: [PATCH] sync updates --- MediaBrowser.Api/ConnectService.cs | 13 ++++++++ .../Connect/ConnectSupporterSummary.cs | 16 +++++++++ .../Connect/IConnectManager.cs | 6 ++++ .../MediaBrowser.Controller.csproj | 1 + .../Connect/ConnectManager.cs | 33 ++++++++++++++++++- .../Localization/JavaScript/javascript.json | 2 ++ .../Localization/Server/server.json | 2 ++ .../Sync/ServerSyncScheduledTask.cs | 2 +- .../Sync/SyncManager.cs | 1 - .../ApplicationHost.cs | 2 +- .../MediaBrowser.WebDashboard.csproj | 1 + 11 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 MediaBrowser.Controller/Connect/ConnectSupporterSummary.cs diff --git a/MediaBrowser.Api/ConnectService.cs b/MediaBrowser.Api/ConnectService.cs index 4bcd33d9e..09cbafca6 100644 --- a/MediaBrowser.Api/ConnectService.cs +++ b/MediaBrowser.Api/ConnectService.cs @@ -73,6 +73,12 @@ namespace MediaBrowser.Api public string ConnectUserId { get; set; } } + [Route("/Connect/Supporters", "GET")] + [Authenticated(Roles = "Admin")] + public class GetConnectSupporterSummary : IReturn + { + } + public class ConnectService : BaseApiService { private readonly IConnectManager _connectManager; @@ -84,6 +90,13 @@ namespace MediaBrowser.Api _userManager = userManager; } + public async Task Get(GetConnectSupporterSummary request) + { + var result = await _connectManager.GetConnectSupporterSummary().ConfigureAwait(false); + + return ToOptimizedResult(result); + } + public object Post(CreateConnectLink request) { return _connectManager.LinkUser(request.Id, request.ConnectUsername); diff --git a/MediaBrowser.Controller/Connect/ConnectSupporterSummary.cs b/MediaBrowser.Controller/Connect/ConnectSupporterSummary.cs new file mode 100644 index 000000000..47ff90e70 --- /dev/null +++ b/MediaBrowser.Controller/Connect/ConnectSupporterSummary.cs @@ -0,0 +1,16 @@ +using MediaBrowser.Model.Connect; +using System.Collections.Generic; + +namespace MediaBrowser.Controller.Connect +{ + public class ConnectSupporterSummary + { + public int MaxUsers { get; set; } + public List Users { get; set; } + + public ConnectSupporterSummary() + { + Users = new List(); + } + } +} diff --git a/MediaBrowser.Controller/Connect/IConnectManager.cs b/MediaBrowser.Controller/Connect/IConnectManager.cs index a0ab1f9b6..4003d1bf2 100644 --- a/MediaBrowser.Controller/Connect/IConnectManager.cs +++ b/MediaBrowser.Controller/Connect/IConnectManager.cs @@ -69,5 +69,11 @@ namespace MediaBrowser.Controller.Connect /// The token. /// true if [is authorization token valid] [the specified token]; otherwise, false. bool IsAuthorizationTokenValid(string token); + + /// + /// Gets the connect supporter summary. + /// + /// Task<ConnectSupporterSummary>. + Task GetConnectSupporterSummary(); } } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 2a3e23d46..5b8c8d414 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -99,6 +99,7 @@ + diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index 52c21af68..c9b690086 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Net; +using MediaBrowser.Common.Security; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Connect; @@ -38,6 +39,7 @@ namespace MediaBrowser.Server.Implementations.Connect private readonly IServerConfigurationManager _config; private readonly IUserManager _userManager; private readonly IProviderManager _providerManager; + private readonly ISecurityManager _securityManager; private ConnectData _data = new ConnectData(); @@ -102,7 +104,7 @@ namespace MediaBrowser.Server.Implementations.Connect IEncryptionManager encryption, IHttpClient httpClient, IServerApplicationHost appHost, - IServerConfigurationManager config, IUserManager userManager, IProviderManager providerManager) + IServerConfigurationManager config, IUserManager userManager, IProviderManager providerManager, ISecurityManager securityManager) { _logger = logger; _appPaths = appPaths; @@ -113,6 +115,7 @@ namespace MediaBrowser.Server.Implementations.Connect _config = config; _userManager = userManager; _providerManager = providerManager; + _securityManager = securityManager; _userManager.UserConfigurationUpdated += _userManager_UserConfigurationUpdated; _config.ConfigurationUpdated += _config_ConfigurationUpdated; @@ -1054,6 +1057,34 @@ namespace MediaBrowser.Server.Implementations.Connect } } + public async Task GetConnectSupporterSummary() + { + if (!_securityManager.IsMBSupporter) + { + return new ConnectSupporterSummary(); + } + + var url = GetConnectUrl("keyAssociation"); + + url += "?serverId=" + ConnectServerId; + url += "&supporterKey=" + _securityManager.SupporterKey; + + var options = new HttpRequestOptions + { + Url = url, + CancellationToken = CancellationToken.None + }; + + SetServerAccessToken(options); + SetApplicationHeader(options); + + // No need to examine the response + using (var stream = (await _httpClient.SendAsync(options, "GET").ConfigureAwait(false)).Content) + { + return _json.DeserializeFromStream(stream); + } + } + public async Task Authenticate(string username, string passwordMd5) { if (string.IsNullOrWhiteSpace(username)) diff --git a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json index d3693840a..9e0260f3c 100644 --- a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json +++ b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json @@ -36,6 +36,8 @@ "MessageKeyUpdated": "Thank you. Your supporter key has been updated.", "MessageKeyRemoved": "Thank you. Your supporter key has been removed.", "ErrorLaunchingChromecast": "There was an error launching chromecast. Please ensure your device is connected to your wireless network.", + "MessageErrorLoadingSupporterInfo": "There was an error loading supporter information. Please try again later.", + "MessageLinkYourSupporterKey": "Link your supporter key with up to {0} Media Browser Connect members to enjoy free access to the following apps:", "ValueTimeLimitSingleHour": "Time limit: 1 hour", "ValueTimeLimitMultiHour": "Time limit: {0} hours", "PluginCategoryGeneral": "General", diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index 54ade1332..2f4470c96 100644 --- a/MediaBrowser.Server.Implementations/Localization/Server/server.json +++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json @@ -48,6 +48,8 @@ "LabelDashboardSourcePathHelp": "If running the server from source, specify the path to the dashboard-ui folder. All web client files will be served from this location.", "ButtonConvertMedia": "Convert media", "ButtonOrganize": "Organize", + "LinkedToMediaBrowserConnect": "Linked to Media Browser Connect", + "HeaderSupporterBenefits": "Supporter Benefits", "LabelPinCode": "Pin code:", "ButtonOk": "Ok", "ButtonCancel": "Cancel", diff --git a/MediaBrowser.Server.Implementations/Sync/ServerSyncScheduledTask.cs b/MediaBrowser.Server.Implementations/Sync/ServerSyncScheduledTask.cs index 33b1e13bd..148602bd4 100644 --- a/MediaBrowser.Server.Implementations/Sync/ServerSyncScheduledTask.cs +++ b/MediaBrowser.Server.Implementations/Sync/ServerSyncScheduledTask.cs @@ -59,7 +59,7 @@ namespace MediaBrowser.Server.Implementations.Sync { return new ITaskTrigger[] { - new IntervalTrigger { Interval = TimeSpan.FromHours(6) } + new IntervalTrigger { Interval = TimeSpan.FromHours(3) } }; } diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index 5540c3d59..6e55688a8 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -15,7 +15,6 @@ using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.Playlists; using MediaBrowser.Controller.Sync; using MediaBrowser.Controller.TV; -using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Events; diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 0173000cf..f35317cd2 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -457,7 +457,7 @@ namespace MediaBrowser.Server.Startup.Common var encryptionManager = new EncryptionManager(); RegisterSingleInstance(encryptionManager); - ConnectManager = new ConnectManager(LogManager.GetLogger("Connect"), ApplicationPaths, JsonSerializer, encryptionManager, HttpClient, this, ServerConfigurationManager, UserManager, ProviderManager); + ConnectManager = new ConnectManager(LogManager.GetLogger("Connect"), ApplicationPaths, JsonSerializer, encryptionManager, HttpClient, this, ServerConfigurationManager, UserManager, ProviderManager, SecurityManager); RegisterSingleInstance(ConnectManager); DeviceManager = new DeviceManager(new DeviceRepository(ApplicationPaths, JsonSerializer, LogManager.GetLogger("DeviceManager"), FileSystemManager), UserManager, FileSystemManager, LibraryMonitor, ConfigurationManager, LogManager.GetLogger("DeviceManager")); diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index d7c354da3..6f34f6d15 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -87,6 +87,7 @@ + PreserveNewest