@page "/search" @attribute [Authorize] @inject IUserSessionService Session @inject ISessionManager SessionMgr @inject IElevationCoordinator Elevation @inject ISearchService SearchSvc @inject SearchCsvExportService CsvExport @inject SearchHtmlExportService HtmlExport @inject WebExportService WebExport @rendermode InteractiveServer

File Search

@if (!Session.HasProfile) { return; }
Search Options
@if (_running) { }
@if (!string.IsNullOrEmpty(_error)) {
@_error
} @if (_results.Count > 0) {
Results @_results.Count
@foreach (var r in _results.Take(500)) { }
NameExtPathCreatedModifiedSize (KB)
@System.IO.Path.GetFileName(r.Path) @r.FileExtension @r.Path @(r.Created?.ToString("yyyy-MM-dd") ?? "") @(r.LastModified?.ToString("yyyy-MM-dd") ?? "") @((r.SizeBytes / 1024.0).ToString("F1"))
@if (_results.Count > 500) {
Showing first 500 of @_results.Count. Export for full results.
}
} @code { private List _sites = new(); private string _extensions = string.Empty, _regex = string.Empty; private string _createdBy = string.Empty, _modifiedBy = string.Empty, _library = string.Empty; private int _maxResults = 5000; private bool _running; private string _status = string.Empty, _error = string.Empty; private int _current, _total; private List _results = new(); private List<(string Label, IReadOnlyList Results)> _bySite = new(); private ReportMergeMode _mergeMode = ReportMergeMode.SingleMerged; private CancellationTokenSource? _cts; private async Task RunSearch() { _error = string.Empty; _results = new(); _bySite = new(); _running = true; _cts = new CancellationTokenSource(); if (_sites.Count == 0) { _error = "Please select at least one site."; _running = false; return; } var progress = new Progress(p => { _status = p.Message; _current = p.Current; _total = p.Total; InvokeAsync(StateHasChanged); }); try { var exts = _extensions.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); var bySite = new List<(string, IReadOnlyList)>(); var flat = new List(); int i = 0; foreach (var site in _sites) { _cts.Token.ThrowIfCancellationRequested(); _status = $"Searching {site.Title} ({++i}/{_sites.Count})…"; await InvokeAsync(StateHasChanged); var opts = new SearchOptions(exts, _regex, null, null, null, null, _createdBy.TrimOrNull(), _modifiedBy.TrimOrNull(), _library.TrimOrNull(), _maxResults, site.Url); var found = await Elevation.RunAsync(async c => { var ctx = await SessionMgr.GetOrCreateContextAsync(site.Url, Session.CurrentProfile!, c); return await SearchSvc.SearchFilesAsync(ctx, opts, progress, c); }, _cts.Token); bySite.Add((site.Title, found)); flat.AddRange(found); } _bySite = bySite; _results = flat; _status = $"Found {_results.Count} files across {_sites.Count} site(s)."; } catch (OperationCanceledException) { _status = "Cancelled."; } catch (Exception ex) { _error = ex.Message; } finally { _running = false; await InvokeAsync(StateHasChanged); } } private void Cancel() => _cts?.Cancel(); private async Task ExportCsv() { var ts = DateTime.Now.ToString("yyyyMMdd_HHmmss"); var output = ReportMergeHelper.Build(_bySite, _mergeMode, "search", ts, ReportFormat.Csv, rs => CsvExport.BuildCsv(rs)); await WebExport.DownloadBytesAsync(output.Bytes, output.FileName, output.Mime); } private async Task ExportHtml() { var ts = DateTime.Now.ToString("yyyyMMdd_HHmmss"); var output = ReportMergeHelper.Build(_bySite, _mergeMode, "search", ts, ReportFormat.Html, rs => HtmlExport.BuildHtml(rs, Session.CurrentBranding)); await WebExport.DownloadBytesAsync(output.Bytes, output.FileName, output.Mime); } }