From 27acaad6580674c4de426583fe7959a8428acc9a Mon Sep 17 00:00:00 2001 From: "hexx.one" <5312542+hexxone@users.noreply.github.com> Date: Tue, 7 May 2024 20:46:59 +0200 Subject: [PATCH] chore: Cleanup --- HttpsReverseProxy/HttpsReverseProxy.csproj | 6 +- README.md | 38 +- TeleJelly/Assets/Config/config.css | 76 +-- TeleJelly/Assets/Config/config.html | 574 ++++++++++----------- TeleJelly/Assets/Config/config.js | 4 +- TeleJelly/Assets/Login/login.css | 72 +-- TeleJelly/Assets/Login/login.html | 158 +++--- TeleJelly/Classes/ExtraPageInfo.cs | 2 +- TeleJelly/Classes/TelegramAuthResult.cs | 2 +- TeleJelly/Controller/TelegramController.cs | 4 +- TeleJelly/ILRepack.targets | 6 +- TeleJelly/TeleJelly.csproj | 42 +- TeleJelly/TeleJellyPlugin.cs | 39 +- TeleJelly/Telegram/TelegramHelper.cs | 19 +- 14 files changed, 512 insertions(+), 530 deletions(-) diff --git a/HttpsReverseProxy/HttpsReverseProxy.csproj b/HttpsReverseProxy/HttpsReverseProxy.csproj index c9ce089..38036e6 100644 --- a/HttpsReverseProxy/HttpsReverseProxy.csproj +++ b/HttpsReverseProxy/HttpsReverseProxy.csproj @@ -7,11 +7,11 @@ - + - - + + diff --git a/README.md b/README.md index 3ec758c..70cbc48 100644 --- a/README.md +++ b/README.md @@ -41,23 +41,23 @@ Created from [jellyfin-plugin-template](https://github.com/jellyfin/jellyfin-plu ## Features - SSO Login page (at `/sso/Telegram`) - - styled similar to the regular login page - - responsive / mobile capable - - shows a "Back to Normal Login" button - - shows the Telegram Login Widget - - checks the Telegram Auth data against the backend - - if data is invalid -> show error message - - if data is valid -> takes the Jellyfin Auth Response and authenticates the user - - loading animation - - supports Custom CSS + - styled similar to the regular login page + - responsive / mobile capable + - shows a "Back to Normal Login" button + - shows the Telegram Login Widget + - checks the Telegram Auth data against the backend + - if data is invalid -> show error message + - if data is valid -> takes the Jellyfin Auth Response and authenticates the user + - loading animation + - supports Custom CSS - Config page (reachable via Jellyfin Plugin Page) - - requires setting the Telegram Bot Token - - allows setting a List of Administrator Telegram Usernames (get full Access) - - allows forcing an external Protocol Scheme (for reverse proxies like Traefik) - - allows Creating/Editing/Deleting a "virtual" management Group - - Grants access to all OR specific Libraries for non-Administrators. - - _Note: A user needs to be Admin OR part of at least ONE Group to Log-in._ + - requires setting the Telegram Bot Token + - allows setting a List of Administrator Telegram Usernames (get full Access) + - allows forcing an external Protocol Scheme (for reverse proxies like Traefik) + - allows Creating/Editing/Deleting a "virtual" management Group + - Grants access to all OR specific Libraries for non-Administrators. + - _Note: A user needs to be Admin OR part of at least ONE Group to Log-in._ ## Requirements @@ -105,16 +105,16 @@ E.g.: `[Telegram-Login](https://jelly.fin/sso/telegram)` or screenshots below. ## Known issues - The `Sign in with Telegram` button will sometimes get hidden by Browser Plugins like "I don't like Cookies" or "UBlock Origin". -Try disabling these on your Jellyfin domain and inform your users. + Try disabling these on your Jellyfin domain and inform your users. - If a User's profile picture fails to download even though the url is given (err 404), he has probably set it to private. -In this case, the plugin will fall back to its default icon. + In this case, the plugin will fall back to its default icon. - If a User were to change/sell his Username, a random person would possibly be able to use this Service. -However, having Names over ID's is much more convenient for Management. + However, having Names over ID's is much more convenient for Management. - If your server is publicly reachable, make sure to take care of rate limiting with your reverse proxy, -otherwise adversaries might be able to lag the system. + otherwise adversaries might be able to lag the system. ## Demo Video diff --git a/TeleJelly/Assets/Config/config.css b/TeleJelly/Assets/Config/config.css index 8981df0..063854f 100644 --- a/TeleJelly/Assets/Config/config.css +++ b/TeleJelly/Assets/Config/config.css @@ -18,9 +18,9 @@ width: 100%; } - .emby-textarea::-moz-focus-inner { - border: 0; - } +.emby-textarea::-moz-focus-inner { + border: 0; +} .textareaLabel { display: inline-block; @@ -44,15 +44,15 @@ padding-top: 0.5em; } - .sso-role-mapping-container + .sso-role-mapping-container, - .sso-bordered-list + .sso-bordered-list { - margin-top: 1em; - } +.sso-role-mapping-container + .sso-role-mapping-container, +.sso-bordered-list + .sso-bordered-list { + margin-top: 1em; +} - .sso-role-mapping-container .sso-folder-list { - padding-bottom: 0.25em; - padding-left: 1em; - } +.sso-role-mapping-container .sso-folder-list { + padding-bottom: 0.25em; + padding-left: 1em; +} .sso-role-mapping-input-label { padding-left: 0.5em; @@ -106,16 +106,16 @@ code { height: 20px; } - .eye-icon::before { - content: ''; - position: absolute; - background-color: currentColor; - border-radius: 50%; - width: 8px; - height: 8px; - left: 5px; - top: 5px; - } +.eye-icon::before { + content: ''; + position: absolute; + background-color: currentColor; + border-radius: 50%; + width: 8px; + height: 8px; + left: 5px; + top: 5px; +} /* Slash to represent "hide" */ .eye-slash { @@ -131,20 +131,20 @@ code { color: #000; /* Eye icon hover color */ } - /* Tooltip */ - .toggle-eye:hover::after { - content: "Show / Hide Token"; - visibility: visible; - position: absolute; - width: 120px; - background-color: black; - color: white; - text-align: center; - border-radius: 5px; - padding: 5px; - bottom: 110%; - left: 50%; - transform: translateX(-90%); - font-size: 12px; - z-index: 999999; - } +/* Tooltip */ +.toggle-eye:hover::after { + content: "Show / Hide Token"; + visibility: visible; + position: absolute; + width: 120px; + background-color: black; + color: white; + text-align: center; + border-radius: 5px; + padding: 5px; + bottom: 110%; + left: 50%; + transform: translateX(-90%); + font-size: 12px; + z-index: 999999; +} diff --git a/TeleJelly/Assets/Config/config.html b/TeleJelly/Assets/Config/config.html index 0c1b304..d83753d 100644 --- a/TeleJelly/Assets/Config/config.html +++ b/TeleJelly/Assets/Config/config.html @@ -5,332 +5,332 @@ -
-
-
- -
-

TeleJelly Configuration

-

Version: 1.0.6.0

- Github Repository -
-

- Note: - This plug-in is free open-source software. I do not accept any responsibilities. -
- Live "Production"-usage is NOT recommended unless you really know what you are doing. -

-

- Requirements: -

    -
  • You must have a Telegram username to use this login method.
  • -
  • A Telegram Bot is required to validate the Telegram login.
  • -
  • A valid, public domain SSL certificate is required for the Login Widget to work.
  • -
  • The Bot Token can be obtained from @BotFather.
  • -
  • Once you have chosen a bot, use the /setdomain command to link your jellyfin domain to the bot.
  • -
  • A Telegram User has to be Administrator OR part of at least one Group in order to login.
  • -
-

+
+
+
+ +
+

TeleJelly Configuration

+

Version: 1.0.6.0

+ Github Repository +
+

+ Note: + This plug-in is free open-source software. I do not accept any responsibilities. +
+ Live "Production"-usage is NOT recommended unless you really know what you are doing. +

+

+ Requirements: +

    +
  • You must have a Telegram username to use this login method.
  • +
  • A Telegram Bot is required to validate the Telegram login.
  • +
  • A valid, public domain SSL certificate is required for the Login Widget to work.
  • +
  • The Bot Token can be obtained from @BotFather.
  • +
  • Once you have chosen a bot, use the /setdomain command to link your jellyfin domain to the bot.
  • +
  • A Telegram User has to be Administrator OR part of at least one Group in order to login.
  • +
+

- -
-
-
- - - Link to the Telegram SSO Page - - -
- You can share the link with your friends and also include it in the Login Page "Branding". -
- Here is an example (the stylesheet will differ on the actual Login page): -
- -
+            
+            
+                
+
+ + + Link to the Telegram SSO Page + + +
+ You can share the link with your friends and also include it in the Login Page "Branding". +
+ Here is an example (the stylesheet will differ on the actual Login page): +
+ +
                                 Please enable JavaScript.
                             
-
- Please enable JavaScript. -
-
-
- To automatically set the Branding, you can also press the following button. - Notice, this will override your existing Branding. - +
+ Please enable JavaScript.
+
+
+ To automatically set the Branding, you can also press the following button. + Notice, this will override your existing Branding. +
- +
+ - -
-
-
+ + +
+
- -
- -
- -
-
-
-
+ +
+ +
+ +
+
+
-
-
-

Telegram Bot Username:

-

-
+
+
+
+

Telegram Bot Username:

+

- + } + - -
- - -
- A List of - - Telegram Usernames to grant Jellyfin - Admin privileges. - - One per-line. -
-
+
+ A List of + + Telegram Usernames to grant Jellyfin + Admin privileges. + + One per-line. +
+
- -
- -
- Should the Plugin force a Specific - protocol Scheme on it's returned URLS? - This is probably useful if your jellyfin - is running behind a Reverse Proxy which - does "SSL-stripping" (like Traefik). -
- If you are unsure, leave this setting - turned off. -
- + "ForceUrlScheme" + ).checked + ? "block" + : "none"; + } + -
-
- - -
+
+
+ +
- - -
+ + +
- +
+ - -
-
-
-
- - -
-
- 0 -
- + + +
+
+
+ + +
+
+ 0
+
+
- + - -
+
- +
+ - -
-
-
-
- - -
- - Only alphanumeric characters and - underscores allowed. - -
- The name used by the Plugin to identify - a virtual Group of Telegram users for - granting Folder permissions. -
- If a Group with a matching name does NOT - exist, a new one will be created. -
- If a Group with a matching name exists, - the settings for that group will be - updated. -
+ + +
+
+
+ + +
+ + Only alphanumeric characters and + underscores allowed. + +
+ The name used by the Plugin to identify + a virtual Group of Telegram users for + granting Folder permissions. +
+ If a Group with a matching name does NOT + exist, a new one will be created. +
+ If a Group with a matching name exists, + the settings for that group will be + updated.
+
- -
- -
- If enabled, ALL libraries on this server - will be accessible to all Users which - Login through this Group. -
+ +
+ +
+ If enabled, ALL libraries on this server + will be accessible to all Users which + Login through this Group.
+
- -
- -
-
- Determines which libraries will be - accessible to a user that logs in - through this Group. -
- If - "Enable All Folders" is - checked, then this has no effect. -
+ +
+ +
+
+ Determines which libraries will be + accessible to a user that logs in + through this Group. +
+ If + "Enable All Folders" is + checked, then this has no effect.
+
- -
- - -
- A list of allowed Telegram Usernames for - this group, one per-line. -
+
+ A list of allowed Telegram Usernames for + this group, one per-line.
- - -
+ + +
- -
+
+
+
diff --git a/TeleJelly/Assets/Config/config.js b/TeleJelly/Assets/Config/config.js index 30d6d3a..e6bcfdc 100644 --- a/TeleJelly/Assets/Config/config.js +++ b/TeleJelly/Assets/Config/config.js @@ -227,7 +227,7 @@ const tgTokenHelper = { { url: window.ApiClient.getUrl("/api/TeleJellyConfig/ValidateBotToken"), type: "POST", - data: JSON.stringify({ Token: token }), + data: JSON.stringify({Token: token}), contentType: "application/json", dataType: "json" }) @@ -235,7 +235,7 @@ const tgTokenHelper = { tgTokenHelper.handleValidationResponse(data); }) .catch(error => { - tgTokenHelper.handleValidationResponse({ ErrorMessage: error.message }); + tgTokenHelper.handleValidationResponse({ErrorMessage: error.message}); }); }, diff --git a/TeleJelly/Assets/Login/login.css b/TeleJelly/Assets/Login/login.css index 6c51f73..367b7f1 100644 --- a/TeleJelly/Assets/Login/login.css +++ b/TeleJelly/Assets/Login/login.css @@ -10,7 +10,7 @@ } html { - font-family: Montserrat,Noto Sans,Noto Sans HK,Noto Sans JP,Noto Sans KR,Noto Sans SC,Noto Sans TC,sans-serif; + font-family: Montserrat, Noto Sans, Noto Sans HK, Noto Sans JP, Noto Sans KR, Noto Sans SC, Noto Sans TC, sans-serif; line-height: 1.35; text-size-adjust: 100%; font-size: 93%; @@ -21,12 +21,12 @@ body { transition: opacity ease-in 0.2s; } - body[unresolved] { - display: block; - opacity: 0; - overflow: hidden; - position: relative; - } +body[unresolved] { + display: block; + opacity: 0; + overflow: hidden; + position: relative; +} h1, h2 { @@ -85,10 +85,10 @@ h2 { color: rgba(255, 255, 255, 0.8); } - .skinHeader.semiTransparent { - backdrop-filter: none !important; - background-color: rgba(0, 0, 0, 0.4); - } +.skinHeader.semiTransparent { + backdrop-filter: none !important; + background-color: rgba(0, 0, 0, 0.4); +} .headerTop { padding: 0.8em; @@ -122,12 +122,12 @@ h2 { transition: all 0.25s ease-in-out; } - .headerBackButton:hover { - color: #ddd; - border-color: #ddd; - background-color: rgba(100, 100, 100, 0.3); - border-width: 0.05em; - } +.headerBackButton:hover { + color: #ddd; + border-color: #ddd; + background-color: rgba(100, 100, 100, 0.3); + border-width: 0.05em; +} .linkLogos > * { margin: 0.5rem; @@ -355,8 +355,8 @@ h2 { @-webkit-keyframes view-slideleft { 0% { - -webkit-transform: translate3d(100%,0,0); - transform: translate3d(100%,0,0) + -webkit-transform: translate3d(100%, 0, 0); + transform: translate3d(100%, 0, 0) } to { @@ -367,8 +367,8 @@ h2 { @keyframes view-slideleft { 0% { - -webkit-transform: translate3d(100%,0,0); - transform: translate3d(100%,0,0) + -webkit-transform: translate3d(100%, 0, 0); + transform: translate3d(100%, 0, 0) } to { @@ -384,8 +384,8 @@ h2 { } to { - -webkit-transform: translate3d(-100%,0,0); - transform: translate3d(-100%,0,0) + -webkit-transform: translate3d(-100%, 0, 0); + transform: translate3d(-100%, 0, 0) } } @@ -396,15 +396,15 @@ h2 { } to { - -webkit-transform: translate3d(-100%,0,0); - transform: translate3d(-100%,0,0) + -webkit-transform: translate3d(-100%, 0, 0); + transform: translate3d(-100%, 0, 0) } } @-webkit-keyframes view-slideright { 0% { - -webkit-transform: translate3d(-100%,0,0); - transform: translate3d(-100%,0,0) + -webkit-transform: translate3d(-100%, 0, 0); + transform: translate3d(-100%, 0, 0) } to { @@ -415,8 +415,8 @@ h2 { @keyframes view-slideright { 0% { - -webkit-transform: translate3d(-100%,0,0); - transform: translate3d(-100%,0,0) + -webkit-transform: translate3d(-100%, 0, 0); + transform: translate3d(-100%, 0, 0) } to { @@ -432,8 +432,8 @@ h2 { } to { - -webkit-transform: translate3d(100%,0,0); - transform: translate3d(100%,0,0) + -webkit-transform: translate3d(100%, 0, 0); + transform: translate3d(100%, 0, 0) } } @@ -444,8 +444,8 @@ h2 { } to { - -webkit-transform: translate3d(100%,0,0); - transform: translate3d(100%,0,0) + -webkit-transform: translate3d(100%, 0, 0); + transform: translate3d(100%, 0, 0) } } @@ -710,9 +710,9 @@ h2 { border-color: inherit; } - .mdl-spinner__circle-clipper .mdl-spinner__circle { - width: 200%; - } +.mdl-spinner__circle-clipper .mdl-spinner__circle { + width: 200%; +} .mdl-spinner__circleLeft { border-right-color: transparent !important; diff --git a/TeleJelly/Assets/Login/login.html b/TeleJelly/Assets/Login/login.html index 19c38f0..1ef74dd 100644 --- a/TeleJelly/Assets/Login/login.html +++ b/TeleJelly/Assets/Login/login.html @@ -1,9 +1,9 @@ - - - - + + + + Jellyfin - Telegram SSO @@ -11,103 +11,103 @@ + type="text/css"/> + type="text/css"/> + type="image/x-icon"/> -
-
- -
-
-
- -
+
+
+ +
+
+
+
-
- -
-
-
-
- -
- -
- - - - - - - - Telegram_logo - - - - +
+
+ +
+
+
+
+ +
+ +
+ + + + + + + + Telegram_logo + + + + autorenew - - - - - - - - - - - Jellyfin_logo - - - - - -
- -

Telegram SSO

-

Login to continue to Jellyfin.

-
- -
+ + + + + + + + + + + Jellyfin_logo + + + + +
- -
- - -
- -
-
+ +
+
+ +
+ + +
+ +
+ -
+ Use Default Login +
+
diff --git a/TeleJelly/Classes/ExtraPageInfo.cs b/TeleJelly/Classes/ExtraPageInfo.cs index 387e810..c5e0366 100644 --- a/TeleJelly/Classes/ExtraPageInfo.cs +++ b/TeleJelly/Classes/ExtraPageInfo.cs @@ -8,7 +8,7 @@ namespace Jellyfin.Plugin.TeleJelly.Classes; public class ExtraPageInfo : PluginPageInfo { /// - /// Whether the file needs to have strings like {{SERVER_URL}} replaced. + /// Gets or sets a value indicating whether the file needs to have strings like {{SERVER_URL}} replaced. /// public bool NeedsReplacement { get; set; } } diff --git a/TeleJelly/Classes/TelegramAuthResult.cs b/TeleJelly/Classes/TelegramAuthResult.cs index e7cb280..f6cd67a 100644 --- a/TeleJelly/Classes/TelegramAuthResult.cs +++ b/TeleJelly/Classes/TelegramAuthResult.cs @@ -3,7 +3,7 @@ namespace Jellyfin.Plugin.TeleJelly.Classes; /// /// Represents the result of a Telegram auth data validation. /// -public class TelegramAuthResult +public record TelegramAuthResult { /// /// Gets or sets a value indicating whether data is valid. diff --git a/TeleJelly/Controller/TelegramController.cs b/TeleJelly/Controller/TelegramController.cs index b83ebb5..3bf7aa2 100644 --- a/TeleJelly/Controller/TelegramController.cs +++ b/TeleJelly/Controller/TelegramController.cs @@ -75,7 +75,7 @@ public TelegramController( /// 1. User will click on "Login with Telegram" /// 2. a Telegram.org popup opens, asking for login and bot permission /// 3. when confirmed by user -> will get redirected to "Confirm" method. - /// TODO: cache should be cleared when custom CSS changes + /// TODO: cache should be cleared when custom CSS changes. /// /// to search and return. /// Stream of file. @@ -92,7 +92,7 @@ public async Task Files([FromRoute] string fileName) lowerFilename = "index"; } - var view = _instance.GetExtraFiles().FirstOrDefault(extra => extra.Name == lowerFilename); + var view = TeleJellyPlugin.LoginFiles.FirstOrDefault(extra => extra.Name == lowerFilename); if (view == null) { return NotFound($"Resource not found: '{lowerFilename}'"); diff --git a/TeleJelly/ILRepack.targets b/TeleJelly/ILRepack.targets index 1d4c4b4..a31c304 100644 --- a/TeleJelly/ILRepack.targets +++ b/TeleJelly/ILRepack.targets @@ -2,14 +2,14 @@ - + - + - + - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -43,10 +43,10 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + @@ -54,8 +54,8 @@ True \ - - + + @@ -65,29 +65,29 @@ $(AssemblyVersion) $(MinVerVersion) - + - - - - + + + + - + $(LocalAppData) - - - + + + - - + + diff --git a/TeleJelly/TeleJellyPlugin.cs b/TeleJelly/TeleJellyPlugin.cs index 07895de..8f489fe 100644 --- a/TeleJelly/TeleJellyPlugin.cs +++ b/TeleJelly/TeleJellyPlugin.cs @@ -14,6 +14,17 @@ namespace Jellyfin.Plugin.TeleJelly; /// public class TeleJellyPlugin : BasePlugin, IPlugin, IHasWebPages { + /// + /// Gets the always available list of extra files for Telegram SSO. + /// e.g. Fonts and CSS. + /// has replaceable params: + /// - {{SERVER_URL}} = Jellyfin base Url + /// - {{JELLYFIN_DEFAULT_LOGIN}} = Fallback Login url + /// - {{TELEGRAM_BOT_NAME}} = Bot Username. + /// + /// A list of internal webpages in this application. + public static readonly ExtraPageInfo[] LoginFiles = { new() { Name = "index", EmbeddedResourcePath = $"{typeof(TeleJellyPlugin).Namespace}.Assets.Login.login.html", NeedsReplacement = true }, new() { Name = "login.css", EmbeddedResourcePath = $"{typeof(TeleJellyPlugin).Namespace}.Assets.Login.login.css", NeedsReplacement = true }, new() { Name = "login.js", EmbeddedResourcePath = $"{typeof(TeleJellyPlugin).Namespace}.Assets.Login.login.js", NeedsReplacement = true }, new() { Name = "material_icons.woff2", EmbeddedResourcePath = $"{typeof(TeleJellyPlugin).Namespace}.Assets.Login.material_icons.woff2" }, new() { Name = Constants.DefaultUserImageExtraFile, EmbeddedResourcePath = $"{typeof(TeleJellyPlugin).Namespace}.Assets.Login.TeleJellyLogo.jpg" }, }; + /// /// Initializes a new instance of the class. /// @@ -60,32 +71,6 @@ public TeleJellyPlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSer /// A list of internal webpages in this application. public IEnumerable GetPages() { - return new PluginPageInfo[] - { - new() { Name = Name, EmbeddedResourcePath = $"{GetType().Namespace}.Assets.Config.config.html" }, - new() { Name = Name + ".js", EmbeddedResourcePath = $"{GetType().Namespace}.Assets.Config.config.js" }, - new() { Name = Name + ".css", EmbeddedResourcePath = $"{GetType().Namespace}.Assets.Config.config.css" } - }; - } - - /// - /// Gets the always available list of extra files for Telegram SSO. - /// e.g. Fonts and CSS. - /// has replaceable params: - /// - {{SERVER_URL}} = Jellyfin base Url - /// - {{JELLYFIN_DEFAULT_LOGIN}} = Fallback Login url - /// - {{TELEGRAM_BOT_NAME}} = Bot Username. - /// - /// A list of internal webpages in this application. - public IEnumerable GetExtraFiles() - { - return new ExtraPageInfo[] - { - new() { Name = "index", EmbeddedResourcePath = $"{GetType().Namespace}.Assets.Login.login.html", NeedsReplacement = true }, - new() { Name = "login.css", EmbeddedResourcePath = $"{GetType().Namespace}.Assets.Login.login.css", NeedsReplacement = true }, - new() { Name = "login.js", EmbeddedResourcePath = $"{GetType().Namespace}.Assets.Login.login.js", NeedsReplacement = true }, - new() { Name = "material_icons.woff2", EmbeddedResourcePath = $"{GetType().Namespace}.Assets.Login.material_icons.woff2" }, - new() { Name = Constants.DefaultUserImageExtraFile, EmbeddedResourcePath = $"{GetType().Namespace}.Assets.Login.TeleJellyLogo.jpg" }, - }; + return new PluginPageInfo[] { new() { Name = Name, EmbeddedResourcePath = $"{typeof(TeleJellyPlugin).Namespace}.Assets.Config.config.html" }, new() { Name = Name + ".js", EmbeddedResourcePath = $"{typeof(TeleJellyPlugin).Namespace}.Assets.Config.config.js" }, new() { Name = Name + ".css", EmbeddedResourcePath = $"{typeof(TeleJellyPlugin).Namespace}.Assets.Config.config.css" } }; } } diff --git a/TeleJelly/Telegram/TelegramHelper.cs b/TeleJelly/Telegram/TelegramHelper.cs index 16ca565..8325c87 100644 --- a/TeleJelly/Telegram/TelegramHelper.cs +++ b/TeleJelly/Telegram/TelegramHelper.cs @@ -34,6 +34,7 @@ public class TelegramHelper private static readonly DateTime _unixStart = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); private readonly TeleJellyPlugin _instance; + // private readonly ILogger _logger; private readonly PluginConfiguration _config; @@ -206,12 +207,9 @@ public TelegramAuthResult CheckTelegramAuthorizationImpl(SortedDictionary $"{key}={fields[key]}")); var signature = _hmac.ComputeHash(Encoding.UTF8.GetBytes(dataCheckString)); - if (signature.Where(FailCheckPredicate).Any()) - { - return new TelegramAuthResult { ErrorMessage = "Invalid hash." }; - } - - return new TelegramAuthResult { Ok = true }; + return signature.Where(FailCheckPredicate).Any() + ? new TelegramAuthResult { ErrorMessage = "Invalid hash." } + : new TelegramAuthResult { Ok = true }; bool FailCheckPredicate(byte t, int i) { @@ -224,7 +222,6 @@ bool FailCheckPredicate(byte t, int i) } } - /// /// Small helper for finding the Value for a key, ignoring the CaSiNg Of ThE sTrInG. /// @@ -232,7 +229,7 @@ bool FailCheckPredicate(byte t, int i) /// string indexed data. /// to search for. /// found value or null. - public static T? GetDictValue(IDictionary? dataDictionary, string key) + private static T? GetDictValue(IDictionary? dataDictionary, string key) { var foundKey = dataDictionary?.Keys.FirstOrDefault(k => string.Equals(k, key, StringComparison.CurrentCultureIgnoreCase)); return foundKey != null ? dataDictionary![foundKey] : default; @@ -244,7 +241,7 @@ bool FailCheckPredicate(byte t, int i) /// To set the Profile picture for. /// To download from Telegram. /// whether image was successfully downloaded and set. - public async Task DownloadUserImage(User user, SortedDictionary authData) + private async Task DownloadUserImage(User user, SortedDictionary authData) { if (user == null) { @@ -316,14 +313,14 @@ public async Task DownloadUserImage(User user, SortedDictionary /// Jellyfin Telegram User. /// Whether action was successful. - public async Task SetDefaultUserImage(User user) + private async Task SetDefaultUserImage(User user) { if (user == null) { throw new ArgumentNullException(nameof(user), "User is null."); } - var view = _instance.GetExtraFiles().FirstOrDefault(extra => extra.Name == Constants.DefaultUserImageExtraFile); + var view = TeleJellyPlugin.LoginFiles.FirstOrDefault(extra => extra.Name == Constants.DefaultUserImageExtraFile); if (view == null) { // _logger.LogError("Failed to get DefaultUserImageExtraFile {Resource}", Constants.DefaultUserImageExtraFile);