- Added methods to `IMediaStore` for loading, saving, and removing media rules, allowing users to manage rules for media items effectively. - Updated `MediaFetcher` to utilize the new rule management system, integrating rule checks into the fetching process to handle geo-blocks and previously ruled items. - Enhanced `ProxyPool` to support exclusion of proxies from specific countries during acquisition, improving the handling of geo-blocked content. - Adjusted `FetchOptions` to include rules instead of tombstones, streamlining the decision-making process during media fetching. - Updated UI components to support rule editing, providing users with a more interactive experience when managing media rules. These changes improve the overall media collection process by allowing users to define rules for handling media items and enhancing the proxy management system for better content accessibility.
104 lines
4.0 KiB
C#
104 lines
4.0 KiB
C#
using AvParser.Core.Collecting;
|
|
|
|
namespace AvParser.UI.Tests.Fakes;
|
|
|
|
/// <summary>A store that records what it was asked to do and holds nothing.</summary>
|
|
internal sealed class FakeMediaStore : IMediaStore
|
|
{
|
|
public List<string> Purged { get; } = [];
|
|
|
|
public MediaStoreStats Stats { get; set; } = new(0, 0, 0, 0);
|
|
|
|
public List<StoredMedia> Browse { get; } = [];
|
|
|
|
public List<string> SourceIds { get; } = [];
|
|
|
|
public MediaBrowseQuery? LastBrowse { get; private set; }
|
|
|
|
public int? TotalOverride { get; set; }
|
|
|
|
public bool BrowseThrows { get; set; }
|
|
|
|
public PurgeResult PurgeResult { get; set; } = new(3, 2, 4096);
|
|
|
|
public ShowcaseMode Mode { get; private set; } = ShowcaseMode.HardLink;
|
|
|
|
public Task InitialiseAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
|
|
|
|
public void Configure(ShowcaseMode mode) => Mode = mode;
|
|
|
|
public Task<string> BeginRunAsync(string sourceId, CancellationToken cancellationToken = default) =>
|
|
Task.FromResult("run");
|
|
|
|
public Task CompleteRunAsync(string runId, RunSummary summary, CancellationToken cancellationToken = default) =>
|
|
Task.CompletedTask;
|
|
|
|
public Task<IReadOnlyDictionary<string, SeenOutcome>> GetSeenAsync(
|
|
string sourceId,
|
|
IReadOnlyCollection<string> urls,
|
|
CancellationToken cancellationToken = default
|
|
) =>
|
|
Task.FromResult<IReadOnlyDictionary<string, SeenOutcome>>(
|
|
new Dictionary<string, SeenOutcome>(StringComparer.Ordinal)
|
|
);
|
|
|
|
public Task RecordSeenAsync(
|
|
string sourceId,
|
|
string url,
|
|
SeenOutcome outcome,
|
|
int? httpStatus = null,
|
|
string? errorCode = null,
|
|
CancellationToken cancellationToken = default
|
|
) => Task.CompletedTask;
|
|
|
|
public Task<IReadOnlySet<string>> LoadTombstonesAsync(CancellationToken cancellationToken = default) =>
|
|
Task.FromResult<IReadOnlySet<string>>(new HashSet<string>(StringComparer.Ordinal));
|
|
|
|
public Task<int> TombstoneAsync(string sha256, string? reason, CancellationToken cancellationToken = default) =>
|
|
Task.FromResult(0);
|
|
|
|
/// <summary>Rules the page under test has saved.</summary>
|
|
public List<MediaRule> Rules { get; } = [];
|
|
|
|
public Task<IReadOnlyList<MediaRule>> LoadRulesAsync(CancellationToken cancellationToken = default) =>
|
|
Task.FromResult<IReadOnlyList<MediaRule>>([.. Rules]);
|
|
|
|
public Task<int> SaveRuleAsync(MediaRule rule, CancellationToken cancellationToken = default)
|
|
{
|
|
Rules.RemoveAll(existing => existing.Sha256 == rule.Sha256);
|
|
Rules.Add(rule);
|
|
|
|
return Task.FromResult(rule.Action == MediaRuleAction.Skip ? 1 : 0);
|
|
}
|
|
|
|
public Task<bool> RemoveRuleAsync(string sha256, CancellationToken cancellationToken = default) =>
|
|
Task.FromResult(Rules.RemoveAll(existing => existing.Sha256 == sha256) > 0);
|
|
|
|
public Task<CollectedItem> StoreAsync(MediaStoreRequest request, CancellationToken cancellationToken = default) =>
|
|
Task.FromResult(new CollectedItem(request.Candidate, request.Blob, CollectStatus.Stored));
|
|
|
|
public Task<PurgeResult> PurgeAsync(PurgeOptions options, CancellationToken cancellationToken = default)
|
|
{
|
|
Purged.Add(options.SourceId);
|
|
|
|
return Task.FromResult(PurgeResult);
|
|
}
|
|
|
|
public Task<int> RebuildShowcaseAsync(string sourceId, CancellationToken cancellationToken = default) =>
|
|
Task.FromResult(0);
|
|
|
|
public Task<MediaStoreStats> GetStatsAsync(CancellationToken cancellationToken = default) => Task.FromResult(Stats);
|
|
|
|
public Task<MediaPage> BrowseAsync(MediaBrowseQuery query, CancellationToken cancellationToken = default)
|
|
{
|
|
LastBrowse = query;
|
|
|
|
return BrowseThrows
|
|
? throw new InvalidOperationException("the index is unreadable")
|
|
: Task.FromResult(new MediaPage(Browse, TotalOverride ?? Browse.Count));
|
|
}
|
|
|
|
public Task<IReadOnlyList<string>> GetSourceIdsAsync(CancellationToken cancellationToken = default) =>
|
|
Task.FromResult<IReadOnlyList<string>>(SourceIds);
|
|
}
|