diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-07-12 11:24:36 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-12 11:24:36 -0500 |
| commit | de40c346bd5086eeab846f3fe3a329da81692f93 (patch) | |
| tree | 05635ddec17ce9bc5880b7b8aac57dfbf112fed5 /src/slskd/Integrations/Scripts | |
| parent | 7d302ce2a65bac34f0795ce5eafb3e06b746872d (diff) | |
| parent | eed42e9c4916e2ba653e40147de546e7af3af563 (diff) | |
| download | slskd-de40c346bd5086eeab846f3fe3a329da81692f93.tar.gz | |
Merge branch 'master' into dns
Diffstat (limited to 'src/slskd/Integrations/Scripts')
| -rw-r--r-- | src/slskd/Integrations/Scripts/ScriptService.cs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/slskd/Integrations/Scripts/ScriptService.cs b/src/slskd/Integrations/Scripts/ScriptService.cs index 05769a6d..f5cc4d4c 100644 --- a/src/slskd/Integrations/Scripts/ScriptService.cs +++ b/src/slskd/Integrations/Scripts/ScriptService.cs @@ -22,6 +22,9 @@ namespace slskd.Integrations.Scripts; using System; using System.Diagnostics; using System.Linq; +using System.Text.Encodings.Web; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Text.RegularExpressions; using System.Threading.Tasks; using Serilog; @@ -37,6 +40,15 @@ public class ScriptService Events = eventBus; OptionsMonitor = optionsMonitor; + var json = new JsonSerializerOptions(); + json.Converters.Add(new IPAddressConverter()); + json.Converters.Add(new JsonStringEnumConverter()); + json.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; + json.DefaultIgnoreCondition = JsonIgnoreCondition.Never; // include properties with null values + json.Encoder = JavaScriptEncoder.Default; // IMPORTANT! don't change this to 'UnsafeRelaxedJsonEscaping'; as the name implies, it's unsafe! + + JsonSerializerOptions = json; + Events.Subscribe<Event>(nameof(ScriptService), HandleEvent); if (OperatingSystem.IsWindows()) @@ -64,6 +76,7 @@ public class ScriptService private EventBus Events { get; } private string DefaultExecutable { get; } private string DefaultCommandPrefix { get; } + private JsonSerializerOptions JsonSerializerOptions { get; } private async Task HandleEvent(Event data) { @@ -167,7 +180,11 @@ public class ScriptService Log.Debug("Running script '{Script}': \"{Executable}\" {Args} (id: {ProcessId})", script.Key, executable, run.Args ?? string.Join(' ', run.Arglist ?? []), processId); var sw = Stopwatch.StartNew(); - process.StartInfo.EnvironmentVariables["SLSKD_SCRIPT_DATA"] = data.ToJson(); + process.StartInfo.EnvironmentVariables["SLSKD_SCRIPT_DATA"] = JsonSerializer.Serialize( + value: data, + inputType: data.GetType(), // if omitted object is serialized as EventType, losing everything else + options: JsonSerializerOptions); + process.Start(); process.WaitForExit(); |
