From 39196ea0a5ce7bde037c280da09f2bff8f8bd552 Mon Sep 17 00:00:00 2001 From: zerratar Date: Sun, 30 Jul 2023 11:46:14 +0200 Subject: [PATCH] hopefully this should fix the missing clan cape logos --- src/RavenNest.Blazor.Services/LogoService.cs | 10 ++++---- .../Controllers/PlayersController.cs | 25 ++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/RavenNest.Blazor.Services/LogoService.cs b/src/RavenNest.Blazor.Services/LogoService.cs index 8e99e893..594caea3 100644 --- a/src/RavenNest.Blazor.Services/LogoService.cs +++ b/src/RavenNest.Blazor.Services/LogoService.cs @@ -73,18 +73,18 @@ public bool ClearLogos(string userId) return success; } - public async Task GetChannelPictureAsync(string userId, string downloadUrl = null) + public async Task GetChannelPictureAsync(string twitchUserId, string downloadUrl = null) { try { - var forceRefreshLogo = userId.Contains('_'); + var forceRefreshLogo = twitchUserId.Contains('_'); if (forceRefreshLogo) { - userId = userId.Split('_')[1]; + twitchUserId = twitchUserId.Split('_')[1]; } else { - if (fileCache != null && fileCache.TryGetValue("logo_" + userId, out var logoData) && logoData is byte[] data) + if (fileCache != null && fileCache.TryGetValue("logo_" + twitchUserId, out var logoData) && logoData is byte[] data) { return data; } @@ -93,7 +93,7 @@ public async Task GetChannelPictureAsync(string userId, string downloadU //var twitch = new TwitchRequests(clientId: settings.TwitchClientId, clientSecret: settings.TwitchClientSecret); //var profile = await twitch.KGetUserAsync(userId); - return await DownloadLogoAsync(userId, downloadUrl); + return await DownloadLogoAsync(twitchUserId, downloadUrl); } catch { } diff --git a/src/RavenNest.Blazor/Controllers/PlayersController.cs b/src/RavenNest.Blazor/Controllers/PlayersController.cs index 1d14be1e..b693cc01 100644 --- a/src/RavenNest.Blazor/Controllers/PlayersController.cs +++ b/src/RavenNest.Blazor/Controllers/PlayersController.cs @@ -14,6 +14,7 @@ using RavenNest; using System.IO; using System.Numerics; +using RavenNest.Blazor.Services; namespace RavenNest.Controllers { @@ -21,6 +22,7 @@ namespace RavenNest.Controllers [ApiController] public class PlayersController : GameApiController { + private readonly LogoService logoService; private readonly SessionInfoProvider sessionInfoProvider; private readonly SessionManager sessionManager; private readonly PlayerManager playerManager; @@ -35,16 +37,19 @@ public class PlayersController : GameApiController public PlayersController( ILogger logger, GameData gameData, + LogoService logoService, SessionInfoProvider sessionInfoProvider, PlayerInventoryProvider inventoryProvider, SessionManager sessionManager, PlayerManager playerManager, + IRavenfallDbContextProvider dbProvider, ISecureHasher secureHasher, IAuthManager authManager, IOptions settings) : base(logger, gameData, authManager, sessionInfoProvider, sessionManager, secureHasher) { + this.logoService = logoService; this.sessionInfoProvider = sessionInfoProvider; this.sessionManager = sessionManager; this.playerManager = playerManager; @@ -70,20 +75,22 @@ public async Task GetChannelPictureAsync(Guid userId) { try { - //var imageData = await logoService.GetChannelPictureAsync(userId); - //if (imageData != null) - //{ - // return File(imageData, "image/png"); - //} - - // NOT IMPLEMENTED YET - + //var user = GameData.GetUser(userId); + var twitchUserAccess = GameData.GetUserAccess(userId, "twitch"); + if (twitchUserAccess != null) + { + var imageData = await logoService.GetChannelPictureAsync(twitchUserAccess.PlatformId); + if (imageData != null) + { + return File(imageData, "image/png"); + } + } + if (unknownProfilePictureBytes == null) { return NotFound(); } - //return Redirect(unknownProfilePictureUrl); return File(unknownProfilePictureBytes, "image/png"); } catch { }