mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-06 07:36:01 +02:00
Add hex color parsing helper and implement custom list sources for channels and users
- Introduced HexColorHelper for parsing hex color strings to Terminal.Gui Attributes and Colors. - Created ChannelListSource for managing and rendering a list of channels with unread counts and active indicators. - Developed UserListSource for displaying online users with per-user nickname colors. - Refactored MainWindow to utilize ChatMessageManager for handling messages and channel state. - Updated project references and removed unused content from the server project. - Adjusted tests to reflect changes in namespaces and structure.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using Serilog;
|
||||
|
||||
namespace EchoHub.Client.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Shared avatar upload logic — resolves a file path or URL to a stream
|
||||
/// and uploads it via ApiClient.
|
||||
/// </summary>
|
||||
internal static class AvatarHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Upload an avatar from a local file path or HTTP(S) URL.
|
||||
/// Returns the ASCII art response from the server.
|
||||
/// </summary>
|
||||
public static async Task<string?> UploadAsync(ApiClient apiClient, string target)
|
||||
{
|
||||
Stream stream;
|
||||
string fileName;
|
||||
|
||||
if (Uri.TryCreate(target, UriKind.Absolute, out var uri)
|
||||
&& (uri.Scheme == "http" || uri.Scheme == "https"))
|
||||
{
|
||||
using var http = new HttpClient();
|
||||
var bytes = await http.GetByteArrayAsync(uri);
|
||||
stream = new MemoryStream(bytes);
|
||||
fileName = Path.GetFileName(uri.LocalPath);
|
||||
if (string.IsNullOrWhiteSpace(fileName) || !fileName.Contains('.'))
|
||||
fileName = "avatar.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!File.Exists(target))
|
||||
throw new FileNotFoundException($"File not found: {target}");
|
||||
|
||||
stream = File.OpenRead(target);
|
||||
fileName = Path.GetFileName(target);
|
||||
}
|
||||
|
||||
await using (stream)
|
||||
{
|
||||
return await apiClient.UploadAvatarAsync(stream, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user