Refactor downloaders to use generic options and unify logic

Replaces specialized binary and HTML downloaders with a generic, options-driven UnitDownloader and UnitFragmentDownloader pattern. Introduces UnitDownloaderOptions and builder classes for flexible configuration, updates interfaces and method signatures to support progress reporting, and removes redundant binary-specific classes. Updates Playwright and Stealth downloaders to use the new generic base, and adds improved error handling and reporting. Also updates dependency versions and makes minor API consistency improvements across the Fluent and Models layers.
This commit is contained in:
qwsdcvghyu89
2025-09-29 21:27:56 +10:00
parent 8e60109f5e
commit 2958a26e4f
30 changed files with 621 additions and 422 deletions
+4 -3
View File
@@ -1,4 +1,5 @@
using aeqw89.DataKeys;
using Beam.Abstractions;
using Beam.Data;
using Beam.Downloaders;
using Beam.Dynamic;
@@ -7,13 +8,13 @@ using Beam.Models;
namespace Beam.Fluent;
public static class FluentDownload {
public static ITransformStage<RawType, OutType> Links<RawType, OutType>(params IEnumerable<string> links) {
public static ITransformStage<RawType, OutType> Links<RawType, OutType>(params IEnumerable<string> links) where RawType : IDocument {
return new TransformStage<RawType, OutType>(new DownloadContextBuilder<RawType>()
.WithLinks(links));
}
public static ITransformStage<RawType, OutType>
ResourceDefinition<RawType, OutType>(ResourceDefinition definition) {
ResourceDefinition<RawType, OutType>(ResourceDefinition definition) where RawType : IDocument {
if (definition.Location.States.Count == 0)
throw new ArgumentException(Exceptions.Exceptions.resource_definition_invalid_states_count, nameof(definition));
var linkGenerator = new OrderedLinkGenerator(definition.Location.Segments, (NumberedStateChanger)definition.Location.StateChanger.Behavior,
@@ -22,7 +23,7 @@ public static class FluentDownload {
.WithLinks(StringEnumerable.FromGenerator(linkGenerator!)));
}
public static ITransformStage<RawType, OutType> FromContext<RawType, OutType>(DownloadContext<RawType> existing) {
public static ITransformStage<RawType, OutType> FromContext<RawType, OutType>(DownloadContext<RawType> existing) where RawType : IDocument {
return new TransformStage<RawType, OutType>(DownloadContextBuilder<RawType>.FromContext(existing));
}
}