Структура, доп модули, федерация, документация

This commit is contained in:
Халимов Рустам
2026-03-27 00:55:01 +03:00
parent 7cb6ac61dd
commit 7ef73b414c
64 changed files with 3080 additions and 133 deletions

View File

@@ -8,7 +8,15 @@ using Microsoft.Extensions.DependencyInjection;
namespace Knot.Shared.Infrastructure.Configuration;
public class SettingsService : ISettingsService
public class SettingsService : ISettingsService,
ISystemSettings,
IStoriesSettings,
IChatsSettings,
IMessagesSettings,
IWebRtcSettings,
IKlipySettings,
IImportSettings,
IFederationSettings
{
private readonly IServiceProvider _serviceProvider;
private readonly IEncryptionService _encryptionService;
@@ -23,6 +31,15 @@ public class SettingsService : ISettingsService
public SystemSettingsDto Current => _current;
SystemConfig ISystemSettings.Current => _current.System;
StoriesConfig IStoriesSettings.Current => _current.Stories;
ChatsConfig IChatsSettings.Current => _current.Chats;
MessagesConfig IMessagesSettings.Current => _current.Messages;
WebRtcConfig IWebRtcSettings.Current => _current.WebRtc;
KlipyConfig IKlipySettings.Current => _current.Klipy;
ImportConfig IImportSettings.Current => _current.Import;
FederationConfig IFederationSettings.Current => _current.Federation;
public async Task<SystemSettingsDto> GetSettingsAsync(CancellationToken cancellationToken = default)
{
using var scope = _serviceProvider.CreateScope();

View File

@@ -37,7 +37,18 @@ public static class DependencyInjection
options.UseNpgsql(connectionString));
services.AddMemoryCache();
services.AddSingleton<ISettingsService, SettingsService>();
services.AddSingleton<SettingsService>();
services.AddSingleton<ISettingsService>(sp => sp.GetRequiredService<SettingsService>());
services.AddSingleton<ISystemSettings>(sp => sp.GetRequiredService<SettingsService>());
services.AddSingleton<IStoriesSettings>(sp => sp.GetRequiredService<SettingsService>());
services.AddSingleton<IChatsSettings>(sp => sp.GetRequiredService<SettingsService>());
services.AddSingleton<IMessagesSettings>(sp => sp.GetRequiredService<SettingsService>());
services.AddSingleton<IWebRtcSettings>(sp => sp.GetRequiredService<SettingsService>());
services.AddSingleton<IKlipySettings>(sp => sp.GetRequiredService<SettingsService>());
services.AddSingleton<IImportSettings>(sp => sp.GetRequiredService<SettingsService>());
services.AddSingleton<IFederationSettings>(sp => sp.GetRequiredService<SettingsService>());
services.AddScoped<Knot.Shared.Kernel.Services.IStatisticsService, StatisticsService>();
services.AddHostedService<StatisticsWorker>();

View File

@@ -9,3 +9,43 @@ public interface ISettingsService
Task UpdateSettingsAsync(SystemSettingsDto settings, CancellationToken cancellationToken = default);
SystemSettingsDto Current { get; }
}
public interface ISystemSettings
{
SystemConfig Current { get; }
}
public interface IStoriesSettings
{
StoriesConfig Current { get; }
}
public interface IChatsSettings
{
ChatsConfig Current { get; }
}
public interface IMessagesSettings
{
MessagesConfig Current { get; }
}
public interface IWebRtcSettings
{
WebRtcConfig Current { get; }
}
public interface IKlipySettings
{
KlipyConfig Current { get; }
}
public interface IImportSettings
{
ImportConfig Current { get; }
}
public interface IFederationSettings
{
FederationConfig Current { get; }
}

View File

@@ -1,28 +1,118 @@
using System.Collections.Generic;
namespace Knot.Shared.Kernel.Configuration;
public class SystemSettingsDto
public class SystemConfig
{
// Storage Limits
public double MaxStorageQuotaTb { get; set; } = 5.0;
public int MaxGroupMembers { get; set; } = 500;
public int MaxFileSizeMb { get; set; } = 100;
public string ServerTimezone { get; set; } = "UTC";
public string DomainUrl { get; set; } = "https://example.com";
public string AdminRoute { get; set; } = "admin";
public bool EnableRegistration { get; set; } = true;
}
// Calls
public bool EnableCalls { get; set; } = false;
public class StoriesConfig
{
public bool Enabled { get; set; } = true;
public int MaxStoriesPerPeriod { get; set; } = 5; // 1 to 10
public int StoryLifetimeHours { get; set; } = 24; // 4 to 48
// Text Stories
public bool TextStoriesEnabled { get; set; } = true;
public int TextStoryDurationSeconds { get; set; } = 15; // 5 to 30
// Media Stories
public int MediaStoryMaxDurationSeconds { get; set; } = 30; // 5 to 60
public int MaxMediaSizeBytes { get; set; } = 15 * 1024 * 1024; // 15MB
}
public class ChatsConfig
{
public bool SupportGroups { get; set; } = true;
public int MaxGroupParticipants { get; set; } = 200000; // 5 to 1,000,000
public bool AutoCleanChats { get; set; } = false;
public bool AllowChatToGroupConversion { get; set; } = true;
public bool EnableFolders { get; set; } = true;
}
public class MessagesConfig
{
public int DailyMessageLimitPerUser { get; set; } = 0; // 0 = unlimited
public int ChatMessageLimit { get; set; } = 0; // 0 = unlimited
public bool AllowMedia { get; set; } = true;
public int MaxMediaSizeBytes { get; set; } = 50 * 1024 * 1024; // 50MB
public List<string> AllowedMediaTypes { get; set; } = new() { "image/jpeg", "image/png", "video/mp4", "image/gif" };
public bool AllowVoiceMessages { get; set; } = true;
public bool AllowForwarding { get; set; } = true;
public bool AllowReactions { get; set; } = true;
public bool AllowReplies { get; set; } = true;
public bool AllowQuoting { get; set; } = true;
public bool AllowMessageDeletion { get; set; } = true;
public bool ForbidCopying { get; set; } = false;
public bool AllowLinks { get; set; } = true;
public bool AllowPolls { get; set; } = true;
public bool AllowPinning { get; set; } = true;
}
public class WebRtcConfig
{
public bool Enabled { get; set; } = false;
public bool EnableVoiceCalls { get; set; } = true;
public bool EnableVideoCalls { get; set; } = true;
public bool EnableScreenSharing { get; set; } = true;
public string TurnHost { get; set; } = string.Empty;
public int TurnPort { get; set; } = 3478;
public string TurnUser { get; set; } = string.Empty;
public string TurnSecret { get; set; } = string.Empty;
// Klipy
public bool EnableKlipy { get; set; } = false;
public string KlipyApiKey { get; set; } = string.Empty;
public string KlipyCustomerId { get; set; } = string.Empty;
// Confederation
public bool EnableConfederation { get; set; } = false;
public List<string> AllowedDomains { get; set; } = new();
// Auth
public bool EnableRegistration { get; set; } = true;
}
public class KlipyConfig
{
public bool Enabled { get; set; } = false;
public string ApiKey { get; set; } = string.Empty;
public string AppName { get; set; } = string.Empty;
}
public class ImportConfig
{
public bool EnableTelegramImport { get; set; } = false;
}
public class FederationDomainConfig
{
public string Domain { get; set; } = string.Empty;
public bool IsEnabled { get; set; } = true;
public string? PublicKey { get; set; }
public RemoteCapabilities? Capabilities { get; set; }
}
public class RemoteCapabilities
{
public bool AllowMedia { get; set; }
public bool AllowPolls { get; set; }
public bool AllowVoiceMessages { get; set; }
public bool AllowVideoCalls { get; set; }
public bool AllowScreenSharing { get; set; }
}
public class FederationConfig
{
public bool Enabled { get; set; } = false;
public string ServerDescription { get; set; } = string.Empty; // 20 to 120 chars
public string? PrivateKey { get; set; } // RSA PEM
public string? PublicKey { get; set; } // RSA PEM
public List<FederationDomainConfig> AllowedDomains { get; set; } = new();
}
public class SystemSettingsDto
{
public SystemConfig System { get; set; } = new();
public StoriesConfig Stories { get; set; } = new();
public ChatsConfig Chats { get; set; } = new();
public MessagesConfig Messages { get; set; } = new();
public WebRtcConfig WebRtc { get; set; } = new();
public KlipyConfig Klipy { get; set; } = new();
public ImportConfig Import { get; set; } = new();
public FederationConfig Federation { get; set; } = new();
}

View File

@@ -6,6 +6,7 @@ namespace Knot.Shared.Kernel;
public sealed record Error(string Code, string Description)
{
public static readonly Error None = new(string.Empty, string.Empty);
public static Error NotFound(string code, string description) => new(code, description);
}
/// <summary>