From f823281059df873de6bd1ac8c90060935a7062dc Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 8 Sep 2020 16:17:03 -0600 Subject: [PATCH] actually save config --- Jellyfin.Plugin.Simkl/API/GetPinStatus.cs | 3 +- .../API/Objects/SimklEpisode.cs | 3 +- Jellyfin.Plugin.Simkl/API/Objects/User.cs | 3 +- .../API/Responses/CodeResponse.cs | 9 ++-- .../API/Responses/CodeStatusResponse.cs | 3 +- .../API/Responses/SyncHistoryResponse.cs | 3 +- Jellyfin.Plugin.Simkl/API/ServerEndpoint.cs | 17 ++++---- .../Configuration/configPage.html | 43 ++++++++++--------- 8 files changed, 46 insertions(+), 38 deletions(-) diff --git a/Jellyfin.Plugin.Simkl/API/GetPinStatus.cs b/Jellyfin.Plugin.Simkl/API/GetPinStatus.cs index 56e0199..bbeba31 100644 --- a/Jellyfin.Plugin.Simkl/API/GetPinStatus.cs +++ b/Jellyfin.Plugin.Simkl/API/GetPinStatus.cs @@ -1,5 +1,6 @@ using Jellyfin.Plugin.Simkl.API.Responses; using MediaBrowser.Model.Services; +#pragma warning disable SA1300 namespace Jellyfin.Plugin.Simkl.API { @@ -13,6 +14,6 @@ namespace Jellyfin.Plugin.Simkl.API /// Gets or sets user code. /// [ApiMember(Name = "user_code", Description = "pin to be introduced by the user", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] - public string UserCode { get; set; } + public string user_code { get; set; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Objects/SimklEpisode.cs b/Jellyfin.Plugin.Simkl/API/Objects/SimklEpisode.cs index 2653551..b4a44b4 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/SimklEpisode.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/SimklEpisode.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +#pragma warning disable SA1300 namespace Jellyfin.Plugin.Simkl.API.Objects { @@ -11,7 +12,7 @@ namespace Jellyfin.Plugin.Simkl.API.Objects /// Gets or sets watched at. /// [JsonPropertyName("watched_at")] - public string WatchedAt { get; set; } + public string watched_at { get; set; } /// /// Gets or sets ids. diff --git a/Jellyfin.Plugin.Simkl/API/Objects/User.cs b/Jellyfin.Plugin.Simkl/API/Objects/User.cs index 2c9e24e..1094b14 100644 --- a/Jellyfin.Plugin.Simkl/API/Objects/User.cs +++ b/Jellyfin.Plugin.Simkl/API/Objects/User.cs @@ -1,5 +1,6 @@ using System; using System.Text.Json.Serialization; +#pragma warning disable SA1300 namespace Jellyfin.Plugin.Simkl.API.Objects { @@ -17,7 +18,7 @@ namespace Jellyfin.Plugin.Simkl.API.Objects /// Gets or sets joined at. /// [JsonPropertyName("joined_at")] - public DateTime JoinedAt { get; set; } + public DateTime joined_at { get; set; } /// /// Gets or sets gender. diff --git a/Jellyfin.Plugin.Simkl/API/Responses/CodeResponse.cs b/Jellyfin.Plugin.Simkl/API/Responses/CodeResponse.cs index 9bdc94a..ba5b4fc 100644 --- a/Jellyfin.Plugin.Simkl/API/Responses/CodeResponse.cs +++ b/Jellyfin.Plugin.Simkl/API/Responses/CodeResponse.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +#pragma warning disable SA1300 namespace Jellyfin.Plugin.Simkl.API.Responses { @@ -16,25 +17,25 @@ namespace Jellyfin.Plugin.Simkl.API.Responses /// Gets or sets device code. /// [JsonPropertyName("device_code")] - public string DeviceCode { get; set; } + public string device_code { get; set; } /// /// Gets or sets user code. /// [JsonPropertyName("user_code")] - public string UserCode { get; set; } + public string user_code { get; set; } /// /// Gets or sets verification url. /// [JsonPropertyName("verification_url")] - public string VerificationUrl { get; set; } + public string verification_url { get; set; } /// /// Gets or sets expires in. /// [JsonPropertyName("expires_in")] - public int ExpiresIn { get; set; } + public int expires_in { get; set; } /// /// Gets or sets interval. diff --git a/Jellyfin.Plugin.Simkl/API/Responses/CodeStatusResponse.cs b/Jellyfin.Plugin.Simkl/API/Responses/CodeStatusResponse.cs index 0b2ffc6..97390b9 100644 --- a/Jellyfin.Plugin.Simkl/API/Responses/CodeStatusResponse.cs +++ b/Jellyfin.Plugin.Simkl/API/Responses/CodeStatusResponse.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +#pragma warning disable SA1300 namespace Jellyfin.Plugin.Simkl.API.Responses { @@ -21,6 +22,6 @@ namespace Jellyfin.Plugin.Simkl.API.Responses /// Gets or sets access token. /// [JsonPropertyName("access_token")] - public string AccessToken { get; set; } + public string access_token { get; set; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/Responses/SyncHistoryResponse.cs b/Jellyfin.Plugin.Simkl/API/Responses/SyncHistoryResponse.cs index 3a6ced2..a8758bc 100644 --- a/Jellyfin.Plugin.Simkl/API/Responses/SyncHistoryResponse.cs +++ b/Jellyfin.Plugin.Simkl/API/Responses/SyncHistoryResponse.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +#pragma warning disable SA1300 namespace Jellyfin.Plugin.Simkl.API.Responses { @@ -16,6 +17,6 @@ namespace Jellyfin.Plugin.Simkl.API.Responses /// Gets or sets not found. /// [JsonPropertyName("not_found")] - public SyncHistoryNotFound NotFound { get; set; } + public SyncHistoryNotFound not_found { get; set; } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/API/ServerEndpoint.cs b/Jellyfin.Plugin.Simkl/API/ServerEndpoint.cs index 1b4fef9..dfcbba7 100644 --- a/Jellyfin.Plugin.Simkl/API/ServerEndpoint.cs +++ b/Jellyfin.Plugin.Simkl/API/ServerEndpoint.cs @@ -1,5 +1,6 @@ using Jellyfin.Plugin.Simkl.API.Objects; using Jellyfin.Plugin.Simkl.API.Responses; +using MediaBrowser.Common.Net; using MediaBrowser.Controller.Net; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Services; @@ -14,20 +15,20 @@ namespace Jellyfin.Plugin.Simkl.API public class ServerEndpoint : IService, IHasResultFactory { private readonly SimklApi _api; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IJsonSerializer _json; /// /// Initializes a new instance of the class. /// - /// The simkl api. - /// Instance of the interface. + /// Instance of the interface. /// Instance of the interface. - public ServerEndpoint(SimklApi api, ILogger logger, IJsonSerializer json) + /// Instance of the interface. + public ServerEndpoint(ILoggerFactory loggerFactory, IJsonSerializer json, IHttpClient httpClient) { - _api = api; - _logger = logger; + _logger = loggerFactory.CreateLogger(); _json = json; + _api = new SimklApi(json, loggerFactory.CreateLogger(), httpClient); } /// @@ -57,7 +58,7 @@ namespace Jellyfin.Plugin.Simkl.API /// Code status response. public CodeStatusResponse Get(GetPinStatus request) { - return _api.GetCodeStatus(request.UserCode).GetAwaiter().GetResult(); + return _api.GetCodeStatus(request.user_code).GetAwaiter().GetResult(); } /// @@ -68,7 +69,7 @@ namespace Jellyfin.Plugin.Simkl.API public UserSettings Get(GetUserSettings request) { _logger.LogDebug(_json.SerializeToString(request)); - return _api.GetUserSettings(SimklPlugin.Instance.Configuration.GetByGuid(request.UserId).UserToken).Result; + return _api.GetUserSettings(SimklPlugin.Instance.Configuration.GetByGuid(request.UserId).UserToken).GetAwaiter().GetResult(); } } } \ No newline at end of file diff --git a/Jellyfin.Plugin.Simkl/Configuration/configPage.html b/Jellyfin.Plugin.Simkl/Configuration/configPage.html index de8e2e9..c4df61f 100644 --- a/Jellyfin.Plugin.Simkl/Configuration/configPage.html +++ b/Jellyfin.Plugin.Simkl/Configuration/configPage.html @@ -32,18 +32,18 @@

Scrobbling options:

- +
Percentage watched needed to scrobble
@@ -77,20 +77,20 @@ $("#loginButtonContainer").hide(); $("#configOptionsContainer").hide(); - if (config.userConfigs.some(e => e.guid === user && e.userToken != null && e.userToken !== "")) { + if (config.UserConfigs.some(e => e.Id === user && e.UserToken != null && e.UserToken !== "")) { $("#configOptionsContainer").show(); - this.populateOptionsContainer(config.userConfigs.filter(e => e.guid === user)[0]); + this.populateOptionsContainer(config.UserConfigs.filter(e => e.Id === user)[0]); } else { $("#loginButtonContainer").show(); } }, saveConfig : async function(guid) { - var uconfig = this.configCache.userConfigs.filter(e => e.guid === guid)[0]; + var uconfig = this.configCache.UserConfigs.filter(e => e.Id === guid)[0]; for (var key in uconfig) { var element = $("#configOptionsContainer #"+key); if (element.is(":checkbox")) { - uconfig[key] = element.attr("checked"); + uconfig[key] = element.is(':checked'); } else { if (element.val() != null) uconfig[key] = element.val(); } @@ -101,9 +101,10 @@ ApiClient.updatePluginConfiguration(this.guid, this.configCache).then(Dashboard.processPluginConfigurationUpdateResult); }, populateOptionsContainer : async function(userConfig) { - $("#simklName").html(SimklAPI.getUserSettings(userConfig.guid).user.name); + $("#simklName").html(SimklAPI.getUserSettings(userConfig.Id).User.Name); for (var key in userConfig) { + console.log(key, userConfig[key]); $("#configOptionsContainer input[type=checkbox]#"+key).attr("checked", userConfig[key]); $("#configOptionsContainer input[type=number]#"+key).val(userConfig[key]); } @@ -116,7 +117,7 @@ this.finish.setSeconds(this.finish.getSeconds() + code.expires_in); this.nextInterval = new Date(); - this.loginTimer = window.setTimeout(this.checkLoginProcess.bind(this,code), code.interval*1000); + this.loginTimer = window.setTimeout(this.checkLoginProcess.bind(this,code), code.Interval*1000); this.remainingTimer = window.setInterval(function() { $("#loginSecondsRemaining").html(Math.round((SimklConfig.finish.getTime() - (new Date().getTime()))/1000)); } ,1000); @@ -136,22 +137,22 @@ if (new Date() > this.finish) { Dashboard.alert("Timed out!"); this.stopLoginProcess(); - } else if (response.result === "KO") { - this.loginTimer = window.setTimeout(this.checkLoginProcess.bind(this,code), code.interval*1000); - } else if (response.result === "OK") { + } else if (response.Result === "KO") { + this.loginTimer = window.setTimeout(this.checkLoginProcess.bind(this,code), code.Interval*1000); + } else if (response.Result === "OK") { this.stopLoginProcess(); // Save key on settings var uguid = $("#user-selector").val(); - var filter = this.configCache.userConfigs.filter(function(c) { - return c.guid === uguid; + var filter = this.configCache.UserConfigs.filter(function(c) { + return c.Id === uguid; }); if (filter.length > 0) { - filter[0].userToken = response.access_token; + filter[0].UserToken = response.access_token; } else { - this.configCache.userConfigs.push({ - guid: uguid, - userToken: response.access_token + this.configCache.UserConfigs.push({ + Id: uguid, + UserToken: response.access_token }); } @@ -178,13 +179,13 @@ if (uguid == null) uguid = $("#user-selector").val(); // e1f34a57cb3c4767ab6f29cc5c7c0566 - var filter = this.configCache.userConfigs.filter(function (c) { - return c.guid === uguid; + var filter = this.configCache.UserConfigs.filter(function (c) { + return c.Id === uguid; }); console.log(filter); if (filter.length > 0) { - filter[0].userToken = ""; + filter[0].UserToken = ""; } else { console.log("User not found " + uguid); }