fix: improve event script controls and daily reviews

This commit is contained in:
2026-04-26 21:16:26 +08:00
parent d2b2f714e0
commit ca2c559555
7 changed files with 86 additions and 12 deletions
@@ -116,18 +116,24 @@ public sealed class SystemSettingsDto
public bool EnableEventScripts { get; set; } = false;
public bool EnableLiveStartedScript { get; set; } = false;
public string LiveStartedScriptMode { get; set; } = EventScriptSourceModes.Path;
public string LiveStartedScriptPath { get; set; } = string.Empty;
public string LiveStartedScriptContent { get; set; } = string.Empty;
public bool EnableLiveEndedScript { get; set; } = false;
public string LiveEndedScriptMode { get; set; } = EventScriptSourceModes.Path;
public string LiveEndedScriptPath { get; set; } = string.Empty;
public string LiveEndedScriptContent { get; set; } = string.Empty;
public bool EnableSegmentCompletedScript { get; set; } = false;
public string SegmentCompletedScriptMode { get; set; } = EventScriptSourceModes.Path;
public string SegmentCompletedScriptPath { get; set; } = string.Empty;
@@ -291,18 +297,24 @@ public sealed class UpdateSystemSettingsRequest
public bool EnableEventScripts { get; set; } = false;
public bool EnableLiveStartedScript { get; set; } = false;
public string LiveStartedScriptMode { get; set; } = EventScriptSourceModes.Path;
public string LiveStartedScriptPath { get; set; } = string.Empty;
public string LiveStartedScriptContent { get; set; } = string.Empty;
public bool EnableLiveEndedScript { get; set; } = false;
public string LiveEndedScriptMode { get; set; } = EventScriptSourceModes.Path;
public string LiveEndedScriptPath { get; set; } = string.Empty;
public string LiveEndedScriptContent { get; set; } = string.Empty;
public bool EnableSegmentCompletedScript { get; set; } = false;
public string SegmentCompletedScriptMode { get; set; } = EventScriptSourceModes.Path;
public string SegmentCompletedScriptPath { get; set; } = string.Empty;
@@ -55,12 +55,15 @@ public sealed class SystemSettingsService : ISystemSettingsService
private const string HuyaProxyEnabledKey = "platform_proxy.huya.enabled";
private const string HuyaProxyUrlKey = "platform_proxy.huya.url";
private const string EnableEventScriptsKey = "event_scripts.enabled";
private const string EnableLiveStartedScriptKey = "event_scripts.live_started.enabled";
private const string LiveStartedScriptModeKey = "event_scripts.live_started.mode";
private const string LiveStartedScriptPathKey = "event_scripts.live_started.path";
private const string LiveStartedScriptContentKey = "event_scripts.live_started.content";
private const string EnableLiveEndedScriptKey = "event_scripts.live_ended.enabled";
private const string LiveEndedScriptModeKey = "event_scripts.live_ended.mode";
private const string LiveEndedScriptPathKey = "event_scripts.live_ended.path";
private const string LiveEndedScriptContentKey = "event_scripts.live_ended.content";
private const string EnableSegmentCompletedScriptKey = "event_scripts.segment_completed.enabled";
private const string SegmentCompletedScriptModeKey = "event_scripts.segment_completed.mode";
private const string SegmentCompletedScriptPathKey = "event_scripts.segment_completed.path";
private const string SegmentCompletedScriptContentKey = "event_scripts.segment_completed.content";
@@ -179,12 +182,30 @@ public sealed class SystemSettingsService : ISystemSettingsService
ForcePathStyle = bool.TryParse(GetValue(lookup, S3ForcePathStyleKey, "false"), out var s3ForcePathStyle) && s3ForcePathStyle
},
EnableEventScripts = bool.TryParse(GetValue(lookup, EnableEventScriptsKey, "false"), out var enableEventScripts) && enableEventScripts,
EnableLiveStartedScript = GetEventScriptEnabled(
lookup,
EnableLiveStartedScriptKey,
enableEventScripts,
LiveStartedScriptPathKey,
LiveStartedScriptContentKey),
LiveStartedScriptMode = GetEventScriptMode(lookup, LiveStartedScriptModeKey, LiveStartedScriptPathKey, LiveStartedScriptContentKey),
LiveStartedScriptPath = GetValue(lookup, LiveStartedScriptPathKey, string.Empty),
LiveStartedScriptContent = GetValue(lookup, LiveStartedScriptContentKey, string.Empty),
EnableLiveEndedScript = GetEventScriptEnabled(
lookup,
EnableLiveEndedScriptKey,
enableEventScripts,
LiveEndedScriptPathKey,
LiveEndedScriptContentKey),
LiveEndedScriptMode = GetEventScriptMode(lookup, LiveEndedScriptModeKey, LiveEndedScriptPathKey, LiveEndedScriptContentKey),
LiveEndedScriptPath = GetValue(lookup, LiveEndedScriptPathKey, string.Empty),
LiveEndedScriptContent = GetValue(lookup, LiveEndedScriptContentKey, string.Empty),
EnableSegmentCompletedScript = GetEventScriptEnabled(
lookup,
EnableSegmentCompletedScriptKey,
enableEventScripts,
SegmentCompletedScriptPathKey,
SegmentCompletedScriptContentKey),
SegmentCompletedScriptMode = GetEventScriptMode(lookup, SegmentCompletedScriptModeKey, SegmentCompletedScriptPathKey, SegmentCompletedScriptContentKey),
SegmentCompletedScriptPath = GetValue(lookup, SegmentCompletedScriptPathKey, string.Empty),
SegmentCompletedScriptContent = GetValue(lookup, SegmentCompletedScriptContentKey, string.Empty),
@@ -329,12 +350,15 @@ public sealed class SystemSettingsService : ISystemSettingsService
await UpsertAsync(HuyaProxyEnabledKey, huyaProxy.Enabled.ToString(), now, cancellationToken);
await UpsertAsync(HuyaProxyUrlKey, huyaProxy.ProxyUrl.Trim(), now, cancellationToken);
await UpsertAsync(EnableEventScriptsKey, request.EnableEventScripts.ToString(), now, cancellationToken);
await UpsertAsync(EnableLiveStartedScriptKey, request.EnableLiveStartedScript.ToString(), now, cancellationToken);
await UpsertAsync(LiveStartedScriptModeKey, NormalizeEventScriptMode(request.LiveStartedScriptMode), now, cancellationToken);
await UpsertAsync(LiveStartedScriptPathKey, request.LiveStartedScriptPath.Trim(), now, cancellationToken);
await UpsertAsync(LiveStartedScriptContentKey, request.LiveStartedScriptContent, now, cancellationToken);
await UpsertAsync(EnableLiveEndedScriptKey, request.EnableLiveEndedScript.ToString(), now, cancellationToken);
await UpsertAsync(LiveEndedScriptModeKey, NormalizeEventScriptMode(request.LiveEndedScriptMode), now, cancellationToken);
await UpsertAsync(LiveEndedScriptPathKey, request.LiveEndedScriptPath.Trim(), now, cancellationToken);
await UpsertAsync(LiveEndedScriptContentKey, request.LiveEndedScriptContent, now, cancellationToken);
await UpsertAsync(EnableSegmentCompletedScriptKey, request.EnableSegmentCompletedScript.ToString(), now, cancellationToken);
await UpsertAsync(SegmentCompletedScriptModeKey, NormalizeEventScriptMode(request.SegmentCompletedScriptMode), now, cancellationToken);
await UpsertAsync(SegmentCompletedScriptPathKey, request.SegmentCompletedScriptPath.Trim(), now, cancellationToken);
await UpsertAsync(SegmentCompletedScriptContentKey, request.SegmentCompletedScriptContent, now, cancellationToken);
@@ -425,4 +449,28 @@ public sealed class SystemSettingsService : ISystemSettingsService
existing.Update(value, updatedAt);
_appSettingRepository.Update(existing);
}
private static bool GetEventScriptEnabled(
IReadOnlyDictionary<string, string> lookup,
string enabledKey,
bool legacyGlobalEnabled,
string pathKey,
string contentKey)
{
if (lookup.TryGetValue(enabledKey, out var configured) && bool.TryParse(configured, out var enabled))
{
return enabled;
}
return legacyGlobalEnabled && HasAnyConfiguredValue(lookup, pathKey, contentKey);
}
private static bool HasAnyConfiguredValue(
IReadOnlyDictionary<string, string> lookup,
string pathKey,
string contentKey)
{
return !string.IsNullOrWhiteSpace(GetValue(lookup, pathKey, string.Empty))
|| !string.IsNullOrWhiteSpace(GetValue(lookup, contentKey, string.Empty));
}
}