Skip to content

Commit

Permalink
hopefully this should fix the missing clan cape logos
Browse files Browse the repository at this point in the history
  • Loading branch information
zerratar committed Jul 30, 2023
1 parent 65faa2a commit 39196ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/RavenNest.Blazor.Services/LogoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ public bool ClearLogos(string userId)
return success;
}

public async Task<byte[]> GetChannelPictureAsync(string userId, string downloadUrl = null)
public async Task<byte[]> 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;
}
Expand All @@ -93,7 +93,7 @@ public async Task<byte[]> 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 { }
Expand Down
25 changes: 16 additions & 9 deletions src/RavenNest.Blazor/Controllers/PlayersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
using RavenNest;
using System.IO;
using System.Numerics;
using RavenNest.Blazor.Services;

namespace RavenNest.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class PlayersController : GameApiController
{
private readonly LogoService logoService;
private readonly SessionInfoProvider sessionInfoProvider;
private readonly SessionManager sessionManager;
private readonly PlayerManager playerManager;
Expand All @@ -35,16 +37,19 @@ public class PlayersController : GameApiController
public PlayersController(
ILogger<PlayersController> logger,
GameData gameData,
LogoService logoService,
SessionInfoProvider sessionInfoProvider,
PlayerInventoryProvider inventoryProvider,
SessionManager sessionManager,
PlayerManager playerManager,

IRavenfallDbContextProvider dbProvider,
ISecureHasher secureHasher,
IAuthManager authManager,
IOptions<AppSettings> settings)
: base(logger, gameData, authManager, sessionInfoProvider, sessionManager, secureHasher)
{
this.logoService = logoService;
this.sessionInfoProvider = sessionInfoProvider;
this.sessionManager = sessionManager;
this.playerManager = playerManager;
Expand All @@ -70,20 +75,22 @@ public async Task<ActionResult> 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 { }
Expand Down

0 comments on commit 39196ea

Please sign in to comment.