From c6698f0769a3b3fbb2838286f1adb7b983449954 Mon Sep 17 00:00:00 2001 From: "hexx.one" <5312542+hexxone@users.noreply.github.com> Date: Sat, 4 May 2024 13:57:53 +0200 Subject: [PATCH] fix: broken logging --- TeleJelly/Assets/Config/config.html | 2 +- TeleJelly/Controller/TelegramController.cs | 17 +++++---- TeleJelly/ILRepack.targets | 2 +- TeleJelly/TeleJelly.csproj | 7 ++-- TeleJelly/TeleJellyPlugin.cs | 2 +- TeleJelly/Telegram/TelegramHelper.cs | 41 +++++++++++----------- 6 files changed, 34 insertions(+), 37 deletions(-) diff --git a/TeleJelly/Assets/Config/config.html b/TeleJelly/Assets/Config/config.html index e5f7561..2393378 100644 --- a/TeleJelly/Assets/Config/config.html +++ b/TeleJelly/Assets/Config/config.html @@ -16,7 +16,7 @@

TeleJelly Configuration

-

Version: 1.0.5.0

+

Version: 1.0.6.0

Instance of the interface. /// if plugin was not properly initialized before usage. public TelegramController( - ILogger logger, + //ILogger logger, ISessionManager sessionManager, IUserManager userManager, ICryptoProvider cryptoProvider, IConfigurationManager configurationManager) { - _logger = logger; + //_logger = logger; if (TeleJellyPlugin.Instance == null) { @@ -62,12 +61,12 @@ public TelegramController( _instance = TeleJellyPlugin.Instance; - _telegramHelper = new TelegramHelper(_instance, sessionManager, userManager, cryptoProvider, logger); + _telegramHelper = new TelegramHelper(_instance, sessionManager, userManager, cryptoProvider); // stolen from https://github.com/jellyfin/jellyfin/blob/master/Jellyfin.Api/Controllers/BrandingController.cs _brandingOptions = configurationManager.GetConfiguration("branding"); - _logger.LogDebug("Telegram Controller initialized"); + //_logger.LogDebug("Telegram Controller initialized"); } /// @@ -89,7 +88,7 @@ public async Task Login() if (stream == null) { - _logger.LogError("Failed to get resource {Resource}", view.EmbeddedResourcePath); + //_logger.LogError("Failed to get resource {Resource}", view.EmbeddedResourcePath); return NotFound(); } @@ -143,7 +142,7 @@ public async Task> Authenticate([FromBody] } catch (Exception ex) { - _logger.LogError(ex.ToString()); + //_logger.LogError(ex.ToString()); return StatusCode(500, new SsoAuthenticationResult { ServerAddress = requestBase, ErrorMessage = ex.ToString() }); } @@ -170,7 +169,7 @@ public async Task ExtraFiles([FromRoute] string fileName) var stream = _instance.GetType().Assembly.GetManifestResourceStream(view.EmbeddedResourcePath); if (stream == null) { - _logger.LogError("Failed to get resource {Resource}", view.EmbeddedResourcePath); + //_logger.LogError("Failed to get resource {Resource}", view.EmbeddedResourcePath); return StatusCode(500, $"Resource not found: {view.EmbeddedResourcePath}"); } diff --git a/TeleJelly/ILRepack.targets b/TeleJelly/ILRepack.targets index d12ee9d..1d4c4b4 100644 --- a/TeleJelly/ILRepack.targets +++ b/TeleJelly/ILRepack.targets @@ -7,7 +7,7 @@ + Condition="'%(filename)' == 'Newtonsoft.Json' Or '%(filename)' == 'Telegram.Bot' Or '%(filename)' == 'Microsoft.Extensions.DependencyInjection.Abstractions'"/> net6.0 Jellyfin.Plugin.TeleJelly - 1.0.5.0 - 1.0.5.0 - 1.0.5.0 + 1.0.6.0 + 1.0.6.0 + 1.0.6.0 true false /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary @@ -34,7 +34,6 @@ - all diff --git a/TeleJelly/TeleJellyPlugin.cs b/TeleJelly/TeleJellyPlugin.cs index a519002..eb1e8bb 100644 --- a/TeleJelly/TeleJellyPlugin.cs +++ b/TeleJelly/TeleJellyPlugin.cs @@ -53,7 +53,7 @@ public TeleJellyPlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSer /// - {{JELLYFIN_DEFAULT_LOGIN}} = Fallback Login url /// - {{TELEGRAM_BOT_NAME}} = Bot Username. /// - public PluginPageInfo TelegramLoginPage => new() { Name = "login", EmbeddedResourcePath = $"{GetType().Namespace}.Pages.telegram.login.html" }; + public PluginPageInfo TelegramLoginPage => new() { Name = "login", EmbeddedResourcePath = $"{GetType().Namespace}.Assets.Login.login.html" }; /// /// Returns the available internal web pages of this plugin. diff --git a/TeleJelly/Telegram/TelegramHelper.cs b/TeleJelly/Telegram/TelegramHelper.cs index a60dfc0..dd69db4 100644 --- a/TeleJelly/Telegram/TelegramHelper.cs +++ b/TeleJelly/Telegram/TelegramHelper.cs @@ -17,7 +17,6 @@ using MediaBrowser.Controller.Session; using MediaBrowser.Model.Cryptography; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; #pragma warning disable CA2254 @@ -34,40 +33,40 @@ public class TelegramHelper /// private const long AllowedTimeOffset = 30; - private readonly PluginConfiguration _config; - private readonly ICryptoProvider _cryptoProvider; + private static readonly DateTime _unixStart = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - private readonly HMACSHA256 _hmac; private readonly TeleJellyPlugin _instance; - private readonly ILogger _logger; + //private readonly ILogger _logger; + private readonly PluginConfiguration _config; private readonly ISessionManager _sessionManager; private readonly IUserManager _userManager; + private readonly ICryptoProvider _cryptoProvider; - private static readonly DateTime _unixStart = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + private readonly HMACSHA256 _hmac; /// /// Initializes a new instance of the class. /// /// of the Plugin. + /// for outputting errors. /// for manual sign-in. /// for getting and creating users. /// for hashing passwords. - /// for outputting errors. - internal TelegramHelper(TeleJellyPlugin instance, ISessionManager sessionManager, IUserManager userManager, ICryptoProvider cryptoProvider, ILogger logger) + internal TelegramHelper(TeleJellyPlugin instance, ISessionManager sessionManager, IUserManager userManager, ICryptoProvider cryptoProvider) { _instance = instance; _config = instance.Configuration; + //_logger = logger; _sessionManager = sessionManager; _userManager = userManager; - _logger = logger; _cryptoProvider = cryptoProvider; using var sha256 = SHA256.Create(); _hmac = new HMACSHA256(sha256.ComputeHash(Encoding.ASCII.GetBytes(_config.BotToken))); - _logger.LogDebug("Telegram Helper initialized"); + //_logger.LogDebug("Telegram Helper initialized"); } /// @@ -105,7 +104,7 @@ public async Task GetOrCreateJellyUser(SortedDictionary au var user = _userManager.GetUserByName(userName); if (user == null) { - _logger.LogInformation($"Telegram user '{userName}' doesn't exist, creating..."); + //_logger.LogInformation($"Telegram user '{userName}' doesn't exist, creating..."); user = await _userManager.CreateUserAsync(userName).ConfigureAwait(false); // use a secure random password, can be changed later? @@ -168,7 +167,7 @@ public async Task GetOrCreateJellyUser(SortedDictionary au Username = user.Username }; - _logger.LogInformation("Auth request created..."); + //_logger.LogInformation("Auth request created..."); return await _sessionManager.AuthenticateDirect(authRequest).ConfigureAwait(false); } @@ -278,7 +277,7 @@ public async Task DownloadUserImage(User user, SortedDictionary DownloadUserImage(User user, SortedDictionary DownloadUserImage(User user, SortedDictionary SetDefaultUserImage(User user) var view = _instance.GetExtraFiles().FirstOrDefault(extra => extra.Name == Constants.DefaultUserImageExtraFile); if (view == null) { - _logger.LogError("Failed to get DefaultUserImageExtraFile {Resource}", Constants.DefaultUserImageExtraFile); + //_logger.LogError("Failed to get DefaultUserImageExtraFile {Resource}", Constants.DefaultUserImageExtraFile); return false; } var stream = _instance.GetType().Assembly.GetManifestResourceStream(view.EmbeddedResourcePath); if (stream == null) { - _logger.LogError("Failed to get resource {Resource}", view.EmbeddedResourcePath); + //_logger.LogError("Failed to get resource {Resource}", view.EmbeddedResourcePath); return false; } var userImgPath = Path.Combine(_instance.ApplicationPaths.PluginsPath, Constants.PluginName, Constants.PluginDataFolder, Constants.UserImageFolder); - _logger.LogDebug("Trying to save default image for '{Username}' into '{UserImgPath}'", user.Username, userImgPath); + //_logger.LogDebug("Trying to save default image for '{Username}' into '{UserImgPath}'", user.Username, userImgPath); try { @@ -380,13 +379,13 @@ public async Task SetDefaultUserImage(User user) user.ProfileImage.LastModified = DateTime.UtcNow; } - _logger.LogInformation("Successfully set default telegram user image for '{Username}'.", user.Username); + //_logger.LogInformation("Successfully set default telegram user image for '{Username}'.", user.Username); return true; } catch (Exception ex) { // Log error and return false. - _logger.LogError(ex, "Failed to set default telegram user image for '{Username}' from '{PhotoUrl}'.", user.Username, view.EmbeddedResourcePath); + //_logger.LogError(ex, "Failed to set default telegram user image for '{Username}' from '{PhotoUrl}'.", user.Username, view.EmbeddedResourcePath); return false; } }