actually save config
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using Jellyfin.Plugin.Simkl.API.Responses;
|
using Jellyfin.Plugin.Simkl.API.Responses;
|
||||||
using MediaBrowser.Model.Services;
|
using MediaBrowser.Model.Services;
|
||||||
|
#pragma warning disable SA1300
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.Simkl.API
|
namespace Jellyfin.Plugin.Simkl.API
|
||||||
{
|
{
|
||||||
@@ -13,6 +14,6 @@ namespace Jellyfin.Plugin.Simkl.API
|
|||||||
/// Gets or sets user code.
|
/// Gets or sets user code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ApiMember(Name = "user_code", Description = "pin to be introduced by the user", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
[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;
|
using System.Text.Json.Serialization;
|
||||||
|
#pragma warning disable SA1300
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.Simkl.API.Objects
|
namespace Jellyfin.Plugin.Simkl.API.Objects
|
||||||
{
|
{
|
||||||
@@ -11,7 +12,7 @@ namespace Jellyfin.Plugin.Simkl.API.Objects
|
|||||||
/// Gets or sets watched at.
|
/// Gets or sets watched at.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("watched_at")]
|
[JsonPropertyName("watched_at")]
|
||||||
public string WatchedAt { get; set; }
|
public string watched_at { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets ids.
|
/// Gets or sets ids.
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
#pragma warning disable SA1300
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.Simkl.API.Objects
|
namespace Jellyfin.Plugin.Simkl.API.Objects
|
||||||
{
|
{
|
||||||
@@ -17,7 +18,7 @@ namespace Jellyfin.Plugin.Simkl.API.Objects
|
|||||||
/// Gets or sets joined at.
|
/// Gets or sets joined at.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("joined_at")]
|
[JsonPropertyName("joined_at")]
|
||||||
public DateTime JoinedAt { get; set; }
|
public DateTime joined_at { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets gender.
|
/// Gets or sets gender.
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
#pragma warning disable SA1300
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.Simkl.API.Responses
|
namespace Jellyfin.Plugin.Simkl.API.Responses
|
||||||
{
|
{
|
||||||
@@ -16,25 +17,25 @@ namespace Jellyfin.Plugin.Simkl.API.Responses
|
|||||||
/// Gets or sets device code.
|
/// Gets or sets device code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("device_code")]
|
[JsonPropertyName("device_code")]
|
||||||
public string DeviceCode { get; set; }
|
public string device_code { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets user code.
|
/// Gets or sets user code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("user_code")]
|
[JsonPropertyName("user_code")]
|
||||||
public string UserCode { get; set; }
|
public string user_code { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets verification url.
|
/// Gets or sets verification url.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("verification_url")]
|
[JsonPropertyName("verification_url")]
|
||||||
public string VerificationUrl { get; set; }
|
public string verification_url { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets expires in.
|
/// Gets or sets expires in.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("expires_in")]
|
[JsonPropertyName("expires_in")]
|
||||||
public int ExpiresIn { get; set; }
|
public int expires_in { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets interval.
|
/// Gets or sets interval.
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
#pragma warning disable SA1300
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.Simkl.API.Responses
|
namespace Jellyfin.Plugin.Simkl.API.Responses
|
||||||
{
|
{
|
||||||
@@ -21,6 +22,6 @@ namespace Jellyfin.Plugin.Simkl.API.Responses
|
|||||||
/// Gets or sets access token.
|
/// Gets or sets access token.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("access_token")]
|
[JsonPropertyName("access_token")]
|
||||||
public string AccessToken { get; set; }
|
public string access_token { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
#pragma warning disable SA1300
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.Simkl.API.Responses
|
namespace Jellyfin.Plugin.Simkl.API.Responses
|
||||||
{
|
{
|
||||||
@@ -16,6 +17,6 @@ namespace Jellyfin.Plugin.Simkl.API.Responses
|
|||||||
/// Gets or sets not found.
|
/// Gets or sets not found.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("not_found")]
|
[JsonPropertyName("not_found")]
|
||||||
public SyncHistoryNotFound NotFound { get; set; }
|
public SyncHistoryNotFound not_found { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Jellyfin.Plugin.Simkl.API.Objects;
|
using Jellyfin.Plugin.Simkl.API.Objects;
|
||||||
using Jellyfin.Plugin.Simkl.API.Responses;
|
using Jellyfin.Plugin.Simkl.API.Responses;
|
||||||
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Controller.Net;
|
using MediaBrowser.Controller.Net;
|
||||||
using MediaBrowser.Model.Serialization;
|
using MediaBrowser.Model.Serialization;
|
||||||
using MediaBrowser.Model.Services;
|
using MediaBrowser.Model.Services;
|
||||||
@@ -14,20 +15,20 @@ namespace Jellyfin.Plugin.Simkl.API
|
|||||||
public class ServerEndpoint : IService, IHasResultFactory
|
public class ServerEndpoint : IService, IHasResultFactory
|
||||||
{
|
{
|
||||||
private readonly SimklApi _api;
|
private readonly SimklApi _api;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger<ServerEndpoint> _logger;
|
||||||
private readonly IJsonSerializer _json;
|
private readonly IJsonSerializer _json;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ServerEndpoint"/> class.
|
/// Initializes a new instance of the <see cref="ServerEndpoint"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="api">The simkl api.</param>
|
/// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/> interface.</param>
|
||||||
/// <param name="logger">Instance of the <see cref="ILogger{ServerEndpoint}"/> interface.</param>
|
|
||||||
/// <param name="json">Instance of the <see cref="IJsonSerializer"/> 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 = loggerFactory.CreateLogger<ServerEndpoint>();
|
||||||
_logger = logger;
|
|
||||||
_json = json;
|
_json = json;
|
||||||
|
_api = new SimklApi(json, loggerFactory.CreateLogger<SimklApi>(), httpClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -57,7 +58,7 @@ namespace Jellyfin.Plugin.Simkl.API
|
|||||||
/// <returns>Code status response.</returns>
|
/// <returns>Code status response.</returns>
|
||||||
public CodeStatusResponse Get(GetPinStatus request)
|
public CodeStatusResponse Get(GetPinStatus request)
|
||||||
{
|
{
|
||||||
return _api.GetCodeStatus(request.UserCode).GetAwaiter().GetResult();
|
return _api.GetCodeStatus(request.user_code).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -68,7 +69,7 @@ namespace Jellyfin.Plugin.Simkl.API
|
|||||||
public UserSettings Get(GetUserSettings request)
|
public UserSettings Get(GetUserSettings request)
|
||||||
{
|
{
|
||||||
_logger.LogDebug(_json.SerializeToString(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>
|
<h2>Scrobbling options:</h2>
|
||||||
<div class="checkboxcontainer">
|
<div class="checkboxcontainer">
|
||||||
<label>
|
<label>
|
||||||
<input is="emby-checkbox" type="checkbox" id="scrobbleMovies" />
|
<input is="emby-checkbox" type="checkbox" id="ScrobbleMovies" />
|
||||||
<span>Autoscrobbling Movies</span>
|
<span>Autoscrobbling Movies</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="checkboxcontainer">
|
<div class="checkboxcontainer">
|
||||||
<label>
|
<label>
|
||||||
<input is="emby-checkbox" type="checkbox" id="scrobbleShows" />
|
<input is="emby-checkbox" type="checkbox" id="ScrobbleShows" />
|
||||||
<span>Autoscrobbling TV Shows</span>
|
<span>Autoscrobbling TV Shows</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="inputContainer">
|
<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">
|
<div class="fieldDescription">
|
||||||
Percentage watched needed to scrobble
|
Percentage watched needed to scrobble
|
||||||
</div>
|
</div>
|
||||||
@@ -77,20 +77,20 @@
|
|||||||
$("#loginButtonContainer").hide();
|
$("#loginButtonContainer").hide();
|
||||||
$("#configOptionsContainer").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();
|
$("#configOptionsContainer").show();
|
||||||
this.populateOptionsContainer(config.userConfigs.filter(e => e.guid === user)[0]);
|
this.populateOptionsContainer(config.UserConfigs.filter(e => e.Id === user)[0]);
|
||||||
} else {
|
} else {
|
||||||
$("#loginButtonContainer").show();
|
$("#loginButtonContainer").show();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
saveConfig : async function(guid) {
|
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) {
|
for (var key in uconfig) {
|
||||||
var element = $("#configOptionsContainer #"+key);
|
var element = $("#configOptionsContainer #"+key);
|
||||||
if (element.is(":checkbox")) {
|
if (element.is(":checkbox")) {
|
||||||
uconfig[key] = element.attr("checked");
|
uconfig[key] = element.is(':checked');
|
||||||
} else {
|
} else {
|
||||||
if (element.val() != null) uconfig[key] = element.val();
|
if (element.val() != null) uconfig[key] = element.val();
|
||||||
}
|
}
|
||||||
@@ -101,9 +101,10 @@
|
|||||||
ApiClient.updatePluginConfiguration(this.guid, this.configCache).then(Dashboard.processPluginConfigurationUpdateResult);
|
ApiClient.updatePluginConfiguration(this.guid, this.configCache).then(Dashboard.processPluginConfigurationUpdateResult);
|
||||||
},
|
},
|
||||||
populateOptionsContainer : async function(userConfig) {
|
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) {
|
for (var key in userConfig) {
|
||||||
|
console.log(key, userConfig[key]);
|
||||||
$("#configOptionsContainer input[type=checkbox]#"+key).attr("checked", userConfig[key]);
|
$("#configOptionsContainer input[type=checkbox]#"+key).attr("checked", userConfig[key]);
|
||||||
$("#configOptionsContainer input[type=number]#"+key).val(userConfig[key]);
|
$("#configOptionsContainer input[type=number]#"+key).val(userConfig[key]);
|
||||||
}
|
}
|
||||||
@@ -116,7 +117,7 @@
|
|||||||
this.finish.setSeconds(this.finish.getSeconds() + code.expires_in);
|
this.finish.setSeconds(this.finish.getSeconds() + code.expires_in);
|
||||||
this.nextInterval = new Date();
|
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() {
|
this.remainingTimer = window.setInterval(function() {
|
||||||
$("#loginSecondsRemaining").html(Math.round((SimklConfig.finish.getTime() - (new Date().getTime()))/1000));
|
$("#loginSecondsRemaining").html(Math.round((SimklConfig.finish.getTime() - (new Date().getTime()))/1000));
|
||||||
} ,1000);
|
} ,1000);
|
||||||
@@ -136,22 +137,22 @@
|
|||||||
if (new Date() > this.finish) {
|
if (new Date() > this.finish) {
|
||||||
Dashboard.alert("Timed out!");
|
Dashboard.alert("Timed out!");
|
||||||
this.stopLoginProcess();
|
this.stopLoginProcess();
|
||||||
} else if (response.result === "KO") {
|
} else if (response.Result === "KO") {
|
||||||
this.loginTimer = window.setTimeout(this.checkLoginProcess.bind(this,code), code.interval*1000);
|
this.loginTimer = window.setTimeout(this.checkLoginProcess.bind(this,code), code.Interval*1000);
|
||||||
} else if (response.result === "OK") {
|
} else if (response.Result === "OK") {
|
||||||
this.stopLoginProcess();
|
this.stopLoginProcess();
|
||||||
|
|
||||||
// Save key on settings
|
// Save key on settings
|
||||||
var uguid = $("#user-selector").val();
|
var uguid = $("#user-selector").val();
|
||||||
var filter = this.configCache.userConfigs.filter(function(c) {
|
var filter = this.configCache.UserConfigs.filter(function(c) {
|
||||||
return c.guid === uguid;
|
return c.Id === uguid;
|
||||||
});
|
});
|
||||||
if (filter.length > 0) {
|
if (filter.length > 0) {
|
||||||
filter[0].userToken = response.access_token;
|
filter[0].UserToken = response.access_token;
|
||||||
} else {
|
} else {
|
||||||
this.configCache.userConfigs.push({
|
this.configCache.UserConfigs.push({
|
||||||
guid: uguid,
|
Id: uguid,
|
||||||
userToken: response.access_token
|
UserToken: response.access_token
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,13 +179,13 @@
|
|||||||
if (uguid == null) uguid = $("#user-selector").val();
|
if (uguid == null) uguid = $("#user-selector").val();
|
||||||
|
|
||||||
// e1f34a57cb3c4767ab6f29cc5c7c0566
|
// e1f34a57cb3c4767ab6f29cc5c7c0566
|
||||||
var filter = this.configCache.userConfigs.filter(function (c) {
|
var filter = this.configCache.UserConfigs.filter(function (c) {
|
||||||
return c.guid === uguid;
|
return c.Id === uguid;
|
||||||
});
|
});
|
||||||
console.log(filter);
|
console.log(filter);
|
||||||
|
|
||||||
if (filter.length > 0) {
|
if (filter.length > 0) {
|
||||||
filter[0].userToken = "";
|
filter[0].UserToken = "";
|
||||||
} else {
|
} else {
|
||||||
console.log("User not found " + uguid);
|
console.log("User not found " + uguid);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user