diff options
| -rw-r--r-- | src/slskd/Application/Search/SearchService.cs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/slskd/Application/Search/SearchService.cs b/src/slskd/Application/Search/SearchService.cs index 84cfd756..87ac5e22 100644 --- a/src/slskd/Application/Search/SearchService.cs +++ b/src/slskd/Application/Search/SearchService.cs @@ -15,6 +15,8 @@ // along with this program. If not, see https://www.gnu.org/licenses/. // </copyright> +using Microsoft.Extensions.Options; + namespace slskd.Search { using System; @@ -22,6 +24,7 @@ namespace slskd.Search using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; + using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; @@ -41,14 +44,17 @@ namespace slskd.Search /// <summary> /// Initializes a new instance of the <see cref="SearchService"/> class. /// </summary> + /// <param name="optionsMonitor"></param> /// <param name="client">The client instance to use.</param> /// <param name="contextFactory">The database context to use.</param> /// <param name="log">The logger.</param> public SearchService( + IOptionsMonitor<Options> optionsMonitor, ISoulseekClient client, IDbContextFactory<SearchDbContext> contextFactory, ILogger<SearchService> log) { + OptionsMonitor = optionsMonitor; Client = client; ContextFactory = contextFactory; Log = log; @@ -57,6 +63,7 @@ namespace slskd.Search private ConcurrentDictionary<Guid, CancellationTokenSource> CancellationTokens { get; } = new ConcurrentDictionary<Guid, CancellationTokenSource>(); + private IOptionsMonitor<Options> OptionsMonitor { get; } private ISoulseekClient Client { get; } private IDbContextFactory<SearchDbContext> ContextFactory { get; } private ILogger<SearchService> Log { get; set; } @@ -83,10 +90,15 @@ namespace slskd.Search StartedAt = DateTime.UtcNow, }; + var filters = OptionsMonitor.CurrentValue.Filters.File + .Select(filter => new Regex(filter, RegexOptions.Compiled)); + options ??= new SearchOptions(); options = options.WithActions( stateChanged: (args) => UpdateSearchState(search, args.Search), responseReceived: (args) => UpdateSearchState(search, args.Search)); + options = options.WithFilters( + fileFilter: (file) => !filters.Any(filter => filter.IsMatch(file.Filename))); try { |
