actually save config

This commit is contained in:
crobibero
2020-09-08 16:17:03 -06:00
parent df84682be4
commit f823281059
8 changed files with 46 additions and 38 deletions
+2 -1
View File
@@ -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.
/// </summary>
[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; }
}
}
@@ -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.
/// </summary>
[JsonPropertyName("watched_at")]
public string WatchedAt { get; set; }
public string watched_at { get; set; }
/// <summary>
/// Gets or sets ids.
+2 -1
View File
@@ -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.
/// </summary>
[JsonPropertyName("joined_at")]
public DateTime JoinedAt { get; set; }
public DateTime joined_at { get; set; }
/// <summary>
/// Gets or sets gender.
@@ -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.
/// </summary>
[JsonPropertyName("device_code")]
public string DeviceCode { get; set; }
public string device_code { get; set; }
/// <summary>
/// Gets or sets user code.
/// </summary>
[JsonPropertyName("user_code")]
public string UserCode { get; set; }
public string user_code { get; set; }
/// <summary>
/// Gets or sets verification url.
/// </summary>
[JsonPropertyName("verification_url")]
public string VerificationUrl { get; set; }
public string verification_url { get; set; }
/// <summary>
/// Gets or sets expires in.
/// </summary>
[JsonPropertyName("expires_in")]
public int ExpiresIn { get; set; }
public int expires_in { get; set; }
/// <summary>
/// Gets or sets interval.
@@ -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.
/// </summary>
[JsonPropertyName("access_token")]
public string AccessToken { get; set; }
public string access_token { get; set; }
}
}
@@ -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.
/// </summary>
[JsonPropertyName("not_found")]
public SyncHistoryNotFound NotFound { get; set; }
public SyncHistoryNotFound not_found { get; set; }
}
}
+9 -8
View File
@@ -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<ServerEndpoint> _logger;
private readonly IJsonSerializer _json;
/// <summary>
/// Initializes a new instance of the <see cref="ServerEndpoint"/> class.
/// </summary>
/// <param name="api">The simkl api.</param>
/// <param name="logger">Instance of the <see cref="ILogger{ServerEndpoint}"/> interface.</param>
/// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/> interface.</param>
/// <param name="json">Instance of the <see cref="IJsonSerializer"/> interface.</param>
public ServerEndpoint(SimklApi api, ILogger logger, IJsonSerializer json)
/// <param name="httpClient">Instance of the <see cref="IHttpClient"/> interface.</param>
public ServerEndpoint(ILoggerFactory loggerFactory, IJsonSerializer json, IHttpClient httpClient)
{
_api = api;
_logger = logger;
_logger = loggerFactory.CreateLogger<ServerEndpoint>();
_json = json;
_api = new SimklApi(json, loggerFactory.CreateLogger<SimklApi>(), httpClient);
}
/// <summary>
@@ -57,7 +58,7 @@ namespace Jellyfin.Plugin.Simkl.API
/// <returns>Code status response.</returns>
public CodeStatusResponse Get(GetPinStatus request)
{
return _api.GetCodeStatus(request.UserCode).GetAwaiter().GetResult();
return _api.GetCodeStatus(request.user_code).GetAwaiter().GetResult();
}
/// <summary>
@@ -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();
}
}
}
@@ -32,18 +32,18 @@
<h2>Scrobbling options:</h2>
<div class="checkboxcontainer">
<label>
<input is="emby-checkbox" type="checkbox" id="scrobbleMovies" />
<input is="emby-checkbox" type="checkbox" id="ScrobbleMovies" />
<span>Autoscrobbling Movies</span>
</label>
</div>
<div class="checkboxcontainer">
<label>
<input is="emby-checkbox" type="checkbox" id="scrobbleShows" />
<input is="emby-checkbox" type="checkbox" id="ScrobbleShows" />
<span>Autoscrobbling TV Shows</span>
</label>
</div>
<div class="inputContainer">
<input is="emby-input" id="scr_pct" type="number" min="0" max="100" pattern="[0-9]*" label="Scrobbling percentage:" />
<input is="emby-input" id="ScrobblePercentage" type="number" min="0" max="100" pattern="[0-9]*" label="Scrobbling percentage:" />
<div class="fieldDescription">
Percentage watched needed to scrobble
</div>
@@ -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);
}