diff --git a/TRENZ.Docs.API/Controllers/SearchController.cs b/TRENZ.Docs.API/Controllers/SearchController.cs index c7233c8..c59a02c 100644 --- a/TRENZ.Docs.API/Controllers/SearchController.cs +++ b/TRENZ.Docs.API/Controllers/SearchController.cs @@ -34,18 +34,20 @@ public async Task Stats() } [HttpGet] - public async Task Reindex([FromQuery] string? key, CancellationToken cancellationToken = default) + public async Task Reindex([FromQuery] string? key, CancellationToken cancellationToken = default) { if (_configuration["ReindexPassword"] != key) - return; + return Unauthorized(); #if !DEBUG - if (DateTime.Now - _lastReindex < TimeSpan.FromMinutes(30)) - return; + if (DateTime.Now - _lastReindex < TimeSpan.FromSeconds(_configuration.GetValue("ReindexThrottling"))) + return new StatusCodeResult(429); _lastReindex = DateTime.Now; #endif await _indexWorker.DoReindex(cancellationToken); + + return Ok(); } } diff --git a/TRENZ.Docs.API/appsettings.json b/TRENZ.Docs.API/appsettings.json index 10f68b8..34d4eae 100644 --- a/TRENZ.Docs.API/appsettings.json +++ b/TRENZ.Docs.API/appsettings.json @@ -5,5 +5,6 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ReindexThrottling": 600 }