mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 16:46:08 +02:00
Add core models, DTOs, and services for EchoHub chat application
- Created User, Channel, Message, and ServerInfo models with necessary properties. - Added DTOs for user profiles, server information, and message handling. - Implemented JWT authentication service for user login and token generation. - Developed Entity Framework Core DbContext for database interactions. - Introduced SignalR ChatHub for real-time messaging and presence tracking. - Implemented file storage and image to ASCII conversion services. - Set up CORS and middleware for API endpoints. - Created launch settings and development configuration for server and web projects.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
namespace EchoHub.Client.Config;
|
||||
|
||||
public class ClientConfig
|
||||
{
|
||||
public List<SavedServer> SavedServers { get; set; } = [];
|
||||
public AccountPreset DefaultPreset { get; set; } = new();
|
||||
public string ActiveTheme { get; set; } = "Default";
|
||||
}
|
||||
|
||||
public class SavedServer
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public required string Url { get; set; }
|
||||
public string? Username { get; set; }
|
||||
public string? Token { get; set; }
|
||||
public DateTimeOffset LastConnected { get; set; }
|
||||
}
|
||||
|
||||
public class AccountPreset
|
||||
{
|
||||
public string? DisplayName { get; set; }
|
||||
public string? Bio { get; set; }
|
||||
public string? NicknameColor { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace EchoHub.Client.Config;
|
||||
|
||||
public static class ConfigManager
|
||||
{
|
||||
private static readonly string ConfigDir = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".echohub");
|
||||
|
||||
private static readonly string ConfigPath = Path.Combine(ConfigDir, "config.json");
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
WriteIndented = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
};
|
||||
|
||||
public static ClientConfig Load()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(ConfigPath))
|
||||
return new ClientConfig();
|
||||
|
||||
var json = File.ReadAllText(ConfigPath);
|
||||
return JsonSerializer.Deserialize<ClientConfig>(json, JsonOptions) ?? new ClientConfig();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new ClientConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Save(ClientConfig config)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(ConfigDir);
|
||||
var json = JsonSerializer.Serialize(config, JsonOptions);
|
||||
File.WriteAllText(ConfigPath, json);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Silently fail — config save is best-effort
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveServer(SavedServer server)
|
||||
{
|
||||
var config = Load();
|
||||
var existing = config.SavedServers.FindIndex(s =>
|
||||
string.Equals(s.Url, server.Url, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (existing >= 0)
|
||||
config.SavedServers[existing] = server;
|
||||
else
|
||||
config.SavedServers.Add(server);
|
||||
|
||||
Save(config);
|
||||
}
|
||||
|
||||
public static void RemoveServer(string url)
|
||||
{
|
||||
var config = Load();
|
||||
config.SavedServers.RemoveAll(s =>
|
||||
string.Equals(s.Url, url, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
Save(config);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user