🎨 Optimize code

This commit is contained in:
2026-02-05 13:26:07 +08:00
parent 48a25186fc
commit 541956d0e9
5 changed files with 17 additions and 59 deletions

View File

@@ -1,43 +0,0 @@
# ActivityPub Testing Environment Variables
# Solar Network Configuration
SOLAR_DOMAIN=solar.local
SOLAR_PORT=5000
SOLAR_URL=http://solar.local:5000
# Mastodon (Self-Hosted Test Instance)
MASTODON_DOMAIN=mastodon.local
MASTODON_PORT=3001
MASTODON_STREAMING_PORT=4000
MASTODON_URL=http://mastodon.local:3001
# Database
DB_CONNECTION_STRING=Host=localhost;Port=5432;Database=dyson_network;Username=postgres;Password=postgres
# Test Accounts
SOLAR_TEST_USERNAME=solaruser
MASTODON_TEST_USERNAME=testuser
MASTODON_TEST_PASSWORD=TestPassword123!
# ActivityPub Settings
ACTIVITYPUB_DOMAIN=solar.local
ACTIVITYPUB_ENABLE_FEDERATION=true
ACTIVITYPUB_SIGNATURE_ALGORITHM=rsa-sha256
# HTTP Settings
HTTP_TIMEOUT=30
HTTP_MAX_RETRIES=3
# Logging
LOG_LEVEL=Debug
ACTIVITYPUB_LOG_LEVEL=Trace
# Testing
TEST_SKIP_DATABASE_RESET=false
TEST_SKIP_MASTODON_SETUP=false
TEST_AUTO_ACCEPT_FOLLOWS=false
# Development (only in dev environment)
DEV_DISABLE_SIGNATURE_VERIFICATION=false
DEV_LOG_HTTP_BODIES=false
DEV_DISABLE_CORS=false

View File

@@ -24,6 +24,7 @@ using DysonNetwork.Pass.Safety;
using DysonNetwork.Shared.Cache; using DysonNetwork.Shared.Cache;
using DysonNetwork.Shared.Geometry; using DysonNetwork.Shared.Geometry;
using DysonNetwork.Shared.Registry; using DysonNetwork.Shared.Registry;
using DysonNetwork.Shared.Localization;
namespace DysonNetwork.Pass.Startup; namespace DysonNetwork.Pass.Startup;
@@ -138,9 +139,9 @@ public static class ServiceCollectionExtensions
{ {
var assembly = System.Reflection.Assembly.GetExecutingAssembly(); var assembly = System.Reflection.Assembly.GetExecutingAssembly();
var resourceNamespace = "DysonNetwork.Pass.Resources.Locales"; var resourceNamespace = "DysonNetwork.Pass.Resources.Locales";
return new DysonNetwork.Shared.Localization.JsonLocalizationService(assembly, resourceNamespace); return new JsonLocalizationService(assembly, resourceNamespace);
}); });
services.AddScoped<DysonNetwork.Shared.Templating.ITemplateService, DysonNetwork.Shared.Templating.RazorLightTemplateService>(sp => services.AddScoped<Shared.Templating.ITemplateService, Shared.Templating.RazorLightTemplateService>(sp =>
{ {
var assembly = System.Reflection.Assembly.GetExecutingAssembly(); var assembly = System.Reflection.Assembly.GetExecutingAssembly();
var resourceNamespace = "DysonNetwork.Pass.Resources.Templates"; var resourceNamespace = "DysonNetwork.Pass.Resources.Templates";
@@ -166,18 +167,18 @@ public static class ServiceCollectionExtensions
services.AddScoped<RealmService>(); services.AddScoped<RealmService>();
services.AddScoped<LotteryService>(); services.AddScoped<LotteryService>();
services.AddScoped<AffiliationSpellService>(); services.AddScoped<AffiliationSpellService>();
services.AddScoped<SpotifyPresenceService>(); services.AddScoped<SpotifyPresenceService>();
services.AddScoped<SteamPresenceService>(); services.AddScoped<SteamPresenceService>();
services.AddScoped<IPresenceService, SpotifyPresenceService>(); services.AddScoped<IPresenceService, SpotifyPresenceService>();
services.AddScoped<IPresenceService, SteamPresenceService>(); services.AddScoped<IPresenceService, SteamPresenceService>();
services.Configure<OidcProviderOptions>(configuration.GetSection("OidcProvider")); services.Configure<OidcProviderOptions>(configuration.GetSection("OidcProvider"));
services.AddScoped<OidcProviderService>(); services.AddScoped<OidcProviderService>();
services.AddScoped<PassRewindService>(); services.AddScoped<PassRewindService>();
services.AddScoped<AccountRewindService>(); services.AddScoped<AccountRewindService>();
services.AddHostedService<BroadcastEventHandler>(); services.AddHostedService<BroadcastEventHandler>();
return services; return services;

View File

@@ -10,7 +10,7 @@ public class JsonLocalizationService : ILocalizationService
private readonly Assembly _assembly; private readonly Assembly _assembly;
private readonly string _resourceNamespace; private readonly string _resourceNamespace;
private readonly object _lock = new(); private readonly object _lock = new();
private readonly List<string> _availableLocales = new(); private readonly List<string> _availableLocales = [];
public JsonLocalizationService(Assembly? assembly = null, string? resourceNamespace = null) public JsonLocalizationService(Assembly? assembly = null, string? resourceNamespace = null)
{ {
@@ -24,7 +24,7 @@ public class JsonLocalizationService : ILocalizationService
var resourceNames = _assembly.GetManifestResourceNames(); var resourceNames = _assembly.GetManifestResourceNames();
var prefix = $"{_resourceNamespace}."; var prefix = $"{_resourceNamespace}.";
var suffix = ".json"; var suffix = ".json";
foreach (var resourceName in resourceNames) foreach (var resourceName in resourceNames)
{ {
if (resourceName.StartsWith(prefix) && resourceName.EndsWith(suffix)) if (resourceName.StartsWith(prefix) && resourceName.EndsWith(suffix))
@@ -135,7 +135,7 @@ public class JsonLocalizationService : ILocalizationService
private Dictionary<string, LocalizationEntry> LoadLocale(string locale) private Dictionary<string, LocalizationEntry> LoadLocale(string locale)
{ {
var resourceName = $"{_resourceNamespace}.{locale}.json"; var resourceName = $"{_resourceNamespace}.{locale}.json";
using var stream = _assembly.GetManifestResourceStream(resourceName); using var stream = _assembly.GetManifestResourceStream(resourceName);
if (stream == null) if (stream == null)
{ {
@@ -144,7 +144,7 @@ public class JsonLocalizationService : ILocalizationService
using var reader = new StreamReader(stream); using var reader = new StreamReader(stream);
var json = reader.ReadToEnd(); var json = reader.ReadToEnd();
var root = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(json); var root = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(json);
if (root == null) if (root == null)
{ {
@@ -199,14 +199,14 @@ public class JsonLocalizationService : ILocalizationService
return entry.One; return entry.One;
} }
} }
return entry.Other ?? entry.One ?? string.Empty; return entry.Other ?? entry.One ?? string.Empty;
} }
private int? GetCountValue(object args) private int? GetCountValue(object args)
{ {
if (args == null) return null; if (args == null) return null;
var type = args.GetType(); var type = args.GetType();
var countProperty = type.GetProperty("Count", BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); var countProperty = type.GetProperty("Count", BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
if (countProperty != null) if (countProperty != null)

View File

@@ -86,13 +86,13 @@ public static class ServiceCollectionExtensions
public IServiceCollection AddAppBusinessServices(IConfiguration configuration public IServiceCollection AddAppBusinessServices(IConfiguration configuration
) )
{ {
services.AddSingleton<DysonNetwork.Shared.Localization.ILocalizationService, DysonNetwork.Shared.Localization.JsonLocalizationService>(sp => _ = services.AddSingleton<DysonNetwork.Shared.Localization.ILocalizationService, DysonNetwork.Shared.Localization.JsonLocalizationService>(sp =>
{ {
var assembly = System.Reflection.Assembly.GetExecutingAssembly(); var assembly = System.Reflection.Assembly.GetExecutingAssembly();
var resourceNamespace = "DysonNetwork.Sphere.Resources.Locales"; var resourceNamespace = "DysonNetwork.Sphere.Resources.Locales";
return new DysonNetwork.Shared.Localization.JsonLocalizationService(assembly, resourceNamespace); return new Shared.Localization.JsonLocalizationService(assembly, resourceNamespace);
}); });
services.Configure<GeoOptions>(configuration.GetSection("GeoIP")); services.Configure<GeoOptions>(configuration.GetSection("GeoIP"));
services.Configure<ActivityPubDeliveryOptions>(configuration.GetSection("ActivityPubDelivery")); services.Configure<ActivityPubDeliveryOptions>(configuration.GetSection("ActivityPubDelivery"));
services.AddScoped<GeoService>(); services.AddScoped<GeoService>();

View File

@@ -90,9 +90,9 @@ public static class ServiceCollectionExtensions
{ {
var assembly = System.Reflection.Assembly.GetExecutingAssembly(); var assembly = System.Reflection.Assembly.GetExecutingAssembly();
var resourceNamespace = "DysonNetwork.Wallet.Resources.Locales"; var resourceNamespace = "DysonNetwork.Wallet.Resources.Locales";
return new DysonNetwork.Shared.Localization.JsonLocalizationService(assembly, resourceNamespace); return new Shared.Localization.JsonLocalizationService(assembly, resourceNamespace);
}); });
services.Configure<GeoOptions>(configuration.GetSection("GeoIP")); services.Configure<GeoOptions>(configuration.GetSection("GeoIP"));
services.AddScoped<GeoService>(); services.AddScoped<GeoService>();