mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
Refactor and update various components of EchoHub.Server
- Updated launchSettings.json for consistency. - Refactored FileValidationHelper to improve image validation logic. - Enhanced ServerDirectoryService for better connection handling and user count updates. - Improved DatabaseSetup for legacy database handling and seeding default channels. - Refined FirstRunSetup to ensure JWT secret generation. - Removed appsettings.Development.json as it is no longer needed. - Updated EchoHub.Tests project file for consistency. - Added unit tests for FileValidationHelper and PresenceTracker with improved assertions. - Updated ValidationConstantsTests to ensure regex validations are correct. - Cleaned up solution file formatting for better readability.
This commit is contained in:
@@ -1,48 +1,48 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace EchoHub.Server.Setup;
|
||||
|
||||
public static class FirstRunSetup
|
||||
{
|
||||
public static void EnsureAppSettings()
|
||||
{
|
||||
var contentRoot = Directory.GetCurrentDirectory();
|
||||
var settingsPath = Path.Combine(contentRoot, "appsettings.json");
|
||||
var examplePath = Path.Combine(contentRoot, "appsettings.example.json");
|
||||
|
||||
if (!File.Exists(settingsPath) && File.Exists(examplePath))
|
||||
{
|
||||
File.Copy(examplePath, settingsPath);
|
||||
Console.WriteLine("Created appsettings.json from example config.");
|
||||
}
|
||||
|
||||
if (!File.Exists(settingsPath))
|
||||
return;
|
||||
|
||||
EnsureJwtSecret(settingsPath);
|
||||
}
|
||||
|
||||
private static void EnsureJwtSecret(string settingsPath)
|
||||
{
|
||||
var json = File.ReadAllText(settingsPath);
|
||||
var root = JsonNode.Parse(json, documentOptions: new JsonDocumentOptions { CommentHandling = JsonCommentHandling.Skip });
|
||||
if (root is null)
|
||||
return;
|
||||
|
||||
var currentSecret = root["Jwt"]?["Secret"]?.GetValue<string>();
|
||||
|
||||
if (!string.IsNullOrEmpty(currentSecret) && !currentSecret.StartsWith("CHANGE_ME"))
|
||||
return;
|
||||
|
||||
var secret = Convert.ToBase64String(RandomNumberGenerator.GetBytes(48));
|
||||
|
||||
root["Jwt"] ??= new JsonObject();
|
||||
root["Jwt"]!["Secret"] = secret;
|
||||
|
||||
var writeOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||
File.WriteAllText(settingsPath, root.ToJsonString(writeOptions));
|
||||
Console.WriteLine("Generated new JWT secret in appsettings.json.");
|
||||
}
|
||||
}
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace EchoHub.Server.Setup;
|
||||
|
||||
public static class FirstRunSetup
|
||||
{
|
||||
public static void EnsureAppSettings()
|
||||
{
|
||||
var contentRoot = Directory.GetCurrentDirectory();
|
||||
var settingsPath = Path.Combine(contentRoot, "appsettings.json");
|
||||
var examplePath = Path.Combine(contentRoot, "appsettings.example.json");
|
||||
|
||||
if (!File.Exists(settingsPath) && File.Exists(examplePath))
|
||||
{
|
||||
File.Copy(examplePath, settingsPath);
|
||||
Console.WriteLine("Created appsettings.json from example config.");
|
||||
}
|
||||
|
||||
if (!File.Exists(settingsPath))
|
||||
return;
|
||||
|
||||
EnsureJwtSecret(settingsPath);
|
||||
}
|
||||
|
||||
private static void EnsureJwtSecret(string settingsPath)
|
||||
{
|
||||
var json = File.ReadAllText(settingsPath);
|
||||
var root = JsonNode.Parse(json, documentOptions: new JsonDocumentOptions { CommentHandling = JsonCommentHandling.Skip });
|
||||
if (root is null)
|
||||
return;
|
||||
|
||||
var currentSecret = root["Jwt"]?["Secret"]?.GetValue<string>();
|
||||
|
||||
if (!string.IsNullOrEmpty(currentSecret) && !currentSecret.StartsWith("CHANGE_ME"))
|
||||
return;
|
||||
|
||||
var secret = Convert.ToBase64String(RandomNumberGenerator.GetBytes(48));
|
||||
|
||||
root["Jwt"] ??= new JsonObject();
|
||||
root["Jwt"]!["Secret"] = secret;
|
||||
|
||||
var writeOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||
File.WriteAllText(settingsPath, root.ToJsonString(writeOptions));
|
||||
Console.WriteLine("Generated new JWT secret in appsettings.json.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user