still fucked but less fucked

This commit is contained in:
Alan Moon 2025-12-11 17:03:27 -08:00
parent e06a1d9eb4
commit 8e53e37ce2
2 changed files with 52 additions and 64 deletions

View File

@ -210,7 +210,7 @@ namespace QtCNETAPI.Services.ApiService
{
var restRequest = new RestRequest($"users/profile-pic/{userId}")
.AddHeader("Authorization", $"Bearer {SessionToken}");
var response = await _client.GetAsync(restRequest);
var response = await _client.GetAsync(restRequest).ConfigureAwait(false);
if (response != null)
{

View File

@ -1,17 +1,15 @@
using QtCNETAPI.Models;
using qtcnet_client.Properties;
using QtCNETAPI.Models;
using QtCNETAPI.Schema;
using QtCNETAPI.Services.ApiService;
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Drawing2D;
using Microsoft.Extensions.FileProviders;
using qtcnet_client.Properties;
namespace qtcnet_client.Factories
{
public class ImageFactory
{
private readonly IApiService _apiService;
private readonly HttpClient _http = new();
public ImageFactory(IApiService apiService)
{
_apiService = apiService;
@ -19,61 +17,42 @@ namespace qtcnet_client.Factories
public async Task<Bitmap> GetAndCreateProfileImage(string userId, int status = -1, int cosmeticStoreId = 0)
{
Bitmap combined = new(139, 138);
var pfpTask = _apiService.GetUserProfilePic(userId);
var cosmeticTask = cosmeticStoreId >= 0 ? _apiService.GetStoreItem(cosmeticStoreId) : Task.FromResult<ServiceResponse<StoreItem>?>(null)!;
return await Task.Run(async () =>
{
Bitmap img1 = Resources.DefaultPfp;
Bitmap? img2 = null;
Bitmap img3 = Resources.OfflineIcon;
var _pfpRes = await _apiService.GetUserProfilePic(userId);
if (_pfpRes.Success && _pfpRes.Data != null)
var pfpRes = await pfpTask;
if (pfpRes.Success && pfpRes.Data != null)
{
using var ms = new MemoryStream(_pfpRes.Data);
using var ms = new MemoryStream(pfpRes.Data);
img1 = (Bitmap)Image.FromStream(ms);
}
// get cosmetic image
if (cosmeticStoreId >= 0)
if (cosmeticStoreId > 0)
{
var _storeRes = await _apiService.GetStoreItem(cosmeticStoreId);
if (_storeRes.Success && _storeRes.Data != null)
var storeRes = await cosmeticTask;
if (storeRes?.Success == true)
{
using var _http = new HttpClient();
using var _httpRes = await _http.GetAsync(_storeRes.Data.AssetUrl);
if (_httpRes.IsSuccessStatusCode)
using var httpRes = await _http.GetAsync(storeRes.Data?.AssetUrl);
if (httpRes.IsSuccessStatusCode)
{
var _imgByes = _httpRes.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult();
using var ms = new MemoryStream(_imgByes);
img2 = (Bitmap?)Image.FromStream(ms);
var bytes = await httpRes.Content.ReadAsByteArrayAsync();
using var ms = new MemoryStream(bytes);
img2 = (Bitmap)Image.FromStream(ms);
}
}
}
// set status image
if (!int.IsNegative(status))
{
switch (status)
{
case 0:
img3 = Resources.OfflineIcon;
break;
case 1:
img3 = Resources.OnlineIcon;
break;
case 2:
img3 = Resources.AwayIcon;
break;
case 3:
img3 = Resources.DNDIcon;
break;
}
}
Bitmap combined = new(139, 138);
using var g = Graphics.FromImage(combined);
// finally, combine the images
Graphics g = Graphics.FromImage(combined);
g.Clear(Color.Transparent);
g.CompositingMode = CompositingMode.SourceOver;
g.DrawImage(img1, 4, 6, 128, 128);
if (img2 != null)
@ -84,11 +63,20 @@ namespace qtcnet_client.Factories
if (!int.IsNegative(status))
{
img3 = status switch
{
1 => Resources.OnlineIcon,
2 => Resources.AwayIcon,
3 => Resources.DNDIcon,
_ => Resources.OfflineIcon
};
img3.MakeTransparent();
g.DrawImage(img3, 104, 0, 35, 35);
}
return combined;
});
}
public async Task<Bitmap> GetStoreItemThumb(int id)