-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathBaseScreenshotBuilder.cs
More file actions
88 lines (71 loc) · 3.13 KB
/
BaseScreenshotBuilder.cs
File metadata and controls
88 lines (71 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2019-2026 Chris Mohan, Jaben Cargman
// and GotenbergSharpApiClient Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Gotenberg.Sharp.API.Client.Domain.Builders;
/// <summary>
/// Base builder for all Chromium screenshot requests. Provides screenshot properties,
/// conversion behaviors, and asset management shared across URL and HTML screenshot builders.
/// </summary>
public abstract class BaseScreenshotBuilder<TRequest, TBuilder>(TRequest request)
: BaseBuilder<TRequest, TBuilder>(request)
where TRequest : ScreenshotRequest
where TBuilder : BaseScreenshotBuilder<TRequest, TBuilder>
{
/// <summary>
/// Configures screenshot-specific properties (device dimensions, format, quality).
/// </summary>
public TBuilder WithScreenshotProperties(Action<ScreenshotPropertyBuilder> action)
{
if (action == null) throw new ArgumentNullException(nameof(action));
action(new ScreenshotPropertyBuilder(this.Request.ScreenshotProperties));
return (TBuilder)this;
}
/// <summary>
/// Configures Chromium rendering behaviors (wait conditions, cookies, headers, error handling).
/// </summary>
public TBuilder SetConversionBehaviors(Action<HtmlConversionBehaviorBuilder> action)
{
if (action == null) throw new ArgumentNullException(nameof(action));
action(new HtmlConversionBehaviorBuilder(this.Request.ConversionBehaviors));
return (TBuilder)this;
}
/// <summary>
/// Sets pre-configured conversion behaviors.
/// </summary>
public TBuilder SetConversionBehaviors(HtmlConversionBehaviors behaviors)
{
this.Request.ConversionBehaviors = behaviors ?? throw new ArgumentNullException(nameof(behaviors));
return (TBuilder)this;
}
/// <summary>
/// Adds embedded assets (images, fonts, CSS, JS) referenced by the HTML content.
/// </summary>
public TBuilder WithAssets(Action<AssetBuilder> action)
{
if (action == null) throw new ArgumentNullException(nameof(action));
this.Request.Assets ??= new AssetDictionary();
action(new AssetBuilder(this.Request.Assets));
return (TBuilder)this;
}
/// <summary>
/// Adds embedded assets asynchronously (e.g., from streams or files).
/// </summary>
public TBuilder WithAsyncAssets(Func<AssetBuilder, Task> asyncAction)
{
if (asyncAction == null) throw new ArgumentNullException(nameof(asyncAction));
this.Request.Assets ??= new AssetDictionary();
this.BuildTasks.Add(asyncAction(new AssetBuilder(this.Request.Assets)));
return (TBuilder)this;
}
}