@page "/duplicates" @attribute [Authorize] @inject IUserSessionService Session @inject ISessionManager SessionMgr @inject IElevationCoordinator Elevation @inject IDuplicatesService DupSvc @inject DuplicatesCsvExportService CsvExport @inject DuplicatesHtmlExportService HtmlExport @inject WebExportService WebExport @rendermode InteractiveServer

Duplicate Detection

@if (!Session.HasProfile) { return; }
@if (_mode == "Folders") { }
@if (_running) { }
@if (!string.IsNullOrEmpty(_error)) {
@_error
} @if (_results.Count > 0) {
Duplicate Groups @_results.Count
@foreach (var g in _results.Take(100)) {
@g.Name @g.Items.Count copies
@foreach (var item in g.Items) {
@item.Library › @item.Path @if (item.SizeBytes.HasValue) { (@((item.SizeBytes.Value/1024.0).ToString("F1")) KB) }
}
} @if (_results.Count > 100) {
Showing first 100 groups. Export for all.
}
} @code { private string _siteUrl = string.Empty, _library = string.Empty, _mode = "Files"; private bool _matchSize = true, _matchCreated, _matchModified, _matchFolderCount, _matchFileCount; private bool _running; private string _status = string.Empty, _error = string.Empty; private int _current, _total; private List _results = new(); private CancellationTokenSource? _cts; private async Task RunScan() { _error = string.Empty; _results.Clear(); _running = true; _cts = new CancellationTokenSource(); var siteUrl = string.IsNullOrWhiteSpace(_siteUrl) ? Session.CurrentProfile!.TenantUrl : _siteUrl.Trim(); var progress = new Progress(p => { _status = p.Message; _current = p.Current; _total = p.Total; InvokeAsync(StateHasChanged); }); try { var opts = new DuplicateScanOptions(_mode, _matchSize, _matchCreated, _matchModified, _matchFolderCount, _matchFileCount, Library: _library.TrimOrNull()); _results = (await Elevation.RunAsync(async c => { var ctx = await SessionMgr.GetOrCreateContextAsync(siteUrl, Session.CurrentProfile!, c); return await DupSvc.ScanDuplicatesAsync(ctx, opts, progress, c); }, _cts.Token)).ToList(); _status = $"Found {_results.Count} duplicate groups."; } 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() { await WebExport.DownloadCsvAsync(CsvExport.BuildCsv(_results), $"duplicates_{DateTime.Now:yyyyMMdd_HHmmss}.csv"); } private async Task ExportHtml() { await WebExport.DownloadHtmlAsync(HtmlExport.BuildHtml(_results, Session.CurrentBranding), $"duplicates_{DateTime.Now:yyyyMMdd_HHmmss}.html"); } }