diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-07-31 12:24:12 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-07-31 12:24:12 -0500 |
| commit | a7225aa52d71f76e5426dda3c5071f113491b0dd (patch) | |
| tree | 446a175c5bddb1ab2b1c5546aa2db3f890a5972d /src | |
| parent | d4481e3868f39c03f6a0c08387f474bb430517eb (diff) | |
| download | slskd-a7225aa52d71f76e5426dda3c5071f113491b0dd.tar.gz | |
replace 3 character search request check for check of filters from options
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index a2598d1e..1c7031cc 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -21,6 +21,7 @@ namespace slskd { using System; using System.Collections.Concurrent; + using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; @@ -28,6 +29,7 @@ namespace slskd using System.Net.Sockets; using System.Reflection; using System.Runtime; + using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR; @@ -94,6 +96,8 @@ namespace slskd PreviousOptions = OptionsMonitor.CurrentValue; + CompiledSearchResponseFilters = OptionsAtStartup.Filters.Search.Request.Select(f => new Regex(f, RegexOptions.Compiled)); + State = state; State.OnChange(state => State_OnChange(state)); @@ -164,6 +168,7 @@ namespace slskd private IUserService Users { get; set; } private IShareService Shares { get; set; } private IMemoryCache Cache { get; set; } = new MemoryCache(new MemoryCacheOptions()); + private IEnumerable<Regex> CompiledSearchResponseFilters { get; set; } public void CollectGarbage() { @@ -735,6 +740,13 @@ namespace slskd Log.Information("File filter configuration changed. Shares must be re-scanned for changes to take effect."); } + if (PreviousOptions.Filters.Search.Request.Except(newOptions.Filters.Search.Request).Any() + || newOptions.Filters.Search.Request.Except(PreviousOptions.Filters.Search.Request).Any()) + { + CompiledSearchResponseFilters = newOptions.Filters.Search.Request.Select(f => new Regex(f, RegexOptions.Compiled)); + Log.Information("Updated and re-compiled search response filters"); + } + if (PreviousOptions.Rooms.Except(newOptions.Rooms).Any() || newOptions.Rooms.Except(PreviousOptions.Rooms).Any()) { @@ -856,8 +868,7 @@ namespace slskd /// <returns>A Task resolving a SearchResponse, or null.</returns> private async Task<SearchResponse> SearchResponseResolver(string username, int token, SearchQuery query) { - // some bots and perhaps users search for very short terms. only respond to queries >= 3 characters. sorry, U2 fans. - if (query.Query.Length < 3) + if (CompiledSearchResponseFilters.Any(filter => filter.IsMatch(query.SearchText))) { return null; } |
