diff options
| -rw-r--r-- | docs/config.md | 25 | ||||
| -rw-r--r-- | src/slskd/Events/Types/Events.cs | 23 | ||||
| -rw-r--r-- | src/slskd/Program.cs | 56 |
3 files changed, 68 insertions, 36 deletions
diff --git a/docs/config.md b/docs/config.md index e10fcbbe..8ac29622 100644 --- a/docs/config.md +++ b/docs/config.md @@ -405,17 +405,17 @@ groups: strategy: roundrobin slots: 10 speed_limit: 50000 # kibibytes - limits: - queued: - files: 150 - megabytes: 1500 - daily: - files: 2147483647 # effectively unlimited, weekly still applies - megabytes: 2147483647 - weekly: - files: 1500 - megabytes: 15000 - failures: 150 + limits: + queued: + files: 150 + megabytes: 1500 + daily: + files: 2147483647 # effectively unlimited, weekly still applies + megabytes: 2147483647 + weekly: + files: 1500 + megabytes: 15000 + failures: 150 leechers: thresholds: files: 1 @@ -641,7 +641,7 @@ soulseek: child_limit: 25 ``` -## Listen IP Address Port +## Listen IP Address and Port The local IP address and port on which the application listens for incoming connections. @@ -660,6 +660,7 @@ incoming traffic is properly routed. #### **YAML** ```yaml soulseek: + listen_ip_address: 0.0.0.0 listen_port: 50300 ``` diff --git a/src/slskd/Events/Types/Events.cs b/src/slskd/Events/Types/Events.cs index 1f4c6060..f6cb8bd2 100644 --- a/src/slskd/Events/Types/Events.cs +++ b/src/slskd/Events/Types/Events.cs @@ -22,10 +22,11 @@ using slskd.Transfers; public enum EventType { - None, - DownloadFileComplete, - DownloadDirectoryComplete, - Any, + None = 0, + Any = 1, + DownloadFileComplete = 2, + DownloadDirectoryComplete = 3, + Noop = int.MaxValue, } public abstract record Event @@ -47,9 +48,13 @@ public sealed record DownloadFileCompleteEvent : Event public sealed record DownloadDirectoryCompleteEvent : Event { - public override EventType Type { get; } = EventType.DownloadDirectoryComplete; - public override int Version { get; } = 0; - public required string LocalDirectoryName { get; init; } - public required string RemoteDirectoryName { get; init; } - public required string Username { get; init; } + public override EventType Type => EventType.DownloadDirectoryComplete; + public string LocalDirectoryName { get; init; } + public string RemoteDirectoryName { get; init; } + public string Username { get; init; } +} + +public sealed record NoopEvent : Event +{ + public override EventType Type => EventType.Noop; }
\ No newline at end of file diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 1ac798c1..b302cc8c 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -792,12 +792,20 @@ namespace slskd } services.AddRouting(options => options.LowercaseUrls = true); - services.AddControllers().AddJsonOptions(options => - { - options.JsonSerializerOptions.Converters.Add(new IPAddressConverter()); - options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); - options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; - }); + services.AddControllers() + .ConfigureApiBehaviorOptions(options => + { + options.SuppressInferBindingSourcesForParameters = true; // explicit [FromRoute], etc + options.SuppressMapClientErrors = true; // disables automatic ProblemDetails for 4xx + options.SuppressModelStateInvalidFilter = true; // disables automatic 400 for model errors + options.DisableImplicitFromServicesParameters = true; // explicit [FromServices] + }) + .AddJsonOptions(options => + { + options.JsonSerializerOptions.Converters.Add(new IPAddressConverter()); + options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); + options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; + }); services .AddSignalR(options => @@ -813,7 +821,10 @@ namespace slskd services.AddHealthChecks(); - services.AddApiVersioning(options => options.ReportApiVersions = true) + services.AddApiVersioning(options => + { + options.ReportApiVersions = true; + }) .AddApiExplorer(options => { options.GroupNameFormat = "'v'VVV"; @@ -825,13 +836,22 @@ namespace slskd services.AddSwaggerGen(options => { options.DescribeAllParametersInCamelCase(); - options.SwaggerDoc( - "v0", - new OpenApiInfo + options.SwaggerDoc("v0", new OpenApiInfo + { + Version = "v0", + Title = AppName, + Description = "A modern client-server application for the Soulseek file sharing network", + Contact = new OpenApiContact { - Title = AppName, - Version = "v0", - }); + Name = "GitHub", + Url = new Uri("https://github.com/slskd/slskd"), + }, + License = new OpenApiLicense + { + Name = "AGPL-3.0 license", + Url = new Uri("https://github.com/slskd/slskd/blob/master/LICENSE"), + }, + }); if (IOFile.Exists(XmlDocumentationFile)) { @@ -929,6 +949,10 @@ namespace slskd endpoints.MapGet(url, async context => { + // at the time of writing, the prometheus library doesn't include a way to add authentication + // to the UseMetricServer() middleware. this is most likely a consequence of me mixing + // and matching minimal API stuff with controllers. if i ever straighten that out, + // this should be revisited. if (!options.Authentication.Disabled) { var auth = context.Request.Headers["Authorization"].FirstOrDefault(); @@ -944,8 +968,10 @@ namespace slskd } } - var response = await Metrics.BuildAsync(); - await context.Response.WriteAsync(response); + var metricsAsText = await Metrics.BuildAsync(); + + context.Response.Headers.Append("Content-Type", "text/plain; version=0.0.4; charset=utf-8"); + await context.Response.WriteAsync(metricsAsText); }); } }); |
