From e857968ef1004fec6d55736174b7c0c33da01a9c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 5 May 2026 16:47:11 +0000 Subject: [PATCH] feat: Updated OpenAPI spec --- .../Sightengine.AutoSDKHttpResponse.g.cs | 121 ++ ...ISightengineClient.CheckImageByUpload.g.cs | 73 ++ ...ne.ISightengineClient.CheckImageByUrl.g.cs | 17 + ...htengine.ISightengineClient.CheckText.g.cs | 16 + ...ne.ISightengineClient.CheckVideoAsync.g.cs | 87 ++ ...ine.ISightengineClient.CheckVideoSync.g.cs | 73 ++ ...ghtengineClient.CheckWorkflowByUpload.g.cs | 61 + ...ISightengineClient.CheckWorkflowByUrl.g.cs | 15 + ...ine.ISightengineClient.SubmitFeedback.g.cs | 84 ++ .../Generated/Sightengine.OptionsSupport.g.cs | 231 +++- ....SightengineClient.CheckImageByUpload.g.cs | 1088 +++++++++++++++- ...ine.SightengineClient.CheckImageByUrl.g.cs | 74 +- ...ghtengine.SightengineClient.CheckText.g.cs | 69 +- ...ine.SightengineClient.CheckVideoAsync.g.cs | 1150 ++++++++++++++++- ...gine.SightengineClient.CheckVideoSync.g.cs | 1115 +++++++++++++++- ...ghtengineClient.CheckWorkflowByUpload.g.cs | 1076 ++++++++++++++- ....SightengineClient.CheckWorkflowByUrl.g.cs | 72 +- ...gine.SightengineClient.SubmitFeedback.g.cs | 1137 +++++++++++++++- .../Sightengine.SightengineClient.g.cs | 8 +- 19 files changed, 6480 insertions(+), 87 deletions(-) create mode 100644 src/libs/Sightengine/Generated/Sightengine.AutoSDKHttpResponse.g.cs diff --git a/src/libs/Sightengine/Generated/Sightengine.AutoSDKHttpResponse.g.cs b/src/libs/Sightengine/Generated/Sightengine.AutoSDKHttpResponse.g.cs new file mode 100644 index 0000000..49b5029 --- /dev/null +++ b/src/libs/Sightengine/Generated/Sightengine.AutoSDKHttpResponse.g.cs @@ -0,0 +1,121 @@ + +#nullable enable + +namespace Sightengine +{ + /// + /// Represents a successful HTTP response with status code and headers. + /// + public partial class AutoSDKHttpResponse + { + /// + /// Initializes a new instance of the class. + /// + public AutoSDKHttpResponse( + global::System.Net.HttpStatusCode statusCode, + global::System.Collections.Generic.Dictionary> headers) + : this( + statusCode: statusCode, + headers: headers, + requestUri: null) + { + } + + /// + /// Initializes a new instance of the class. + /// + public AutoSDKHttpResponse( + global::System.Net.HttpStatusCode statusCode, + global::System.Collections.Generic.Dictionary> headers, + global::System.Uri? requestUri) + { + StatusCode = statusCode; + Headers = headers ?? throw new global::System.ArgumentNullException(nameof(headers)); + RequestUri = requestUri; + } + + /// + /// Gets the HTTP status code. + /// + public global::System.Net.HttpStatusCode StatusCode { get; } + /// + /// Gets the response headers. + /// + public global::System.Collections.Generic.Dictionary> Headers { get; } + /// + /// Gets the final request URI associated with the response. + /// + public global::System.Uri? RequestUri { get; } + + internal static global::System.Collections.Generic.Dictionary> CreateHeaders( + global::System.Net.Http.HttpResponseMessage response) + { + response = response ?? throw new global::System.ArgumentNullException(nameof(response)); + + var headers = global::System.Linq.Enumerable.ToDictionary( + response.Headers, + static header => header.Key, + static header => (global::System.Collections.Generic.IEnumerable)global::System.Linq.Enumerable.ToArray(header.Value), + global::System.StringComparer.OrdinalIgnoreCase); + + if (response.Content?.Headers == null) + { + return headers; + } + + foreach (var header in response.Content.Headers) + { + if (headers.TryGetValue(header.Key, out var existingValues)) + { + headers[header.Key] = global::System.Linq.Enumerable.ToArray( + global::System.Linq.Enumerable.Concat(existingValues, header.Value)); + } + else + { + headers[header.Key] = global::System.Linq.Enumerable.ToArray(header.Value); + } + } + + return headers; + } + } + + /// + /// Represents a successful HTTP response with status code, headers, and body. + /// + public partial class AutoSDKHttpResponse : AutoSDKHttpResponse + { + /// + /// Initializes a new instance of the class. + /// + public AutoSDKHttpResponse( + global::System.Net.HttpStatusCode statusCode, + global::System.Collections.Generic.Dictionary> headers, + T body) + : this( + statusCode: statusCode, + headers: headers, + requestUri: null, + body: body) + { + } + + /// + /// Initializes a new instance of the class. + /// + public AutoSDKHttpResponse( + global::System.Net.HttpStatusCode statusCode, + global::System.Collections.Generic.Dictionary> headers, + global::System.Uri? requestUri, + T body) + : base(statusCode, headers, requestUri) + { + Body = body; + } + + /// + /// Gets the response body. + /// + public T Body { get; } + } +} \ No newline at end of file diff --git a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckImageByUpload.g.cs b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckImageByUpload.g.cs index 866637a..8846609 100644 --- a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckImageByUpload.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckImageByUpload.g.cs @@ -27,6 +27,22 @@ public partial interface ISightengineClient /// self-harm, scam detection, face analysis, text-in-image (OCR), QR codes,
/// AI-generated image detection, image type, and quality assessment. /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> CheckImageByUploadAsResponseAsync( + + global::Sightengine.CheckImageByUploadRequest request, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Check Image (Upload)
+ /// Moderate an uploaded image using one or more detection models.
+ /// Supports nudity, violence, gore, weapons, drugs, alcohol, offensive content,
+ /// self-harm, scam detection, face analysis, text-in-image (OCR), QR codes,
+ /// AI-generated image detection, image type, and quality assessment. + ///
/// /// The image file to analyze. /// @@ -48,5 +64,62 @@ public partial interface ISightengineClient string models, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); + + /// + /// Check Image (Upload)
+ /// Moderate an uploaded image using one or more detection models.
+ /// Supports nudity, violence, gore, weapons, drugs, alcohol, offensive content,
+ /// self-harm, scam detection, face analysis, text-in-image (OCR), QR codes,
+ /// AI-generated image detection, image type, and quality assessment. + ///
+ /// + /// The image file to analyze. + /// + /// + /// The image file to analyze. + /// + /// + /// Comma-separated list of detection models to apply.
+ /// Available models: nudity-2.1, gore-2.0, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam, face-attributes, text-content,
+ /// qr-content, genai, type, quality. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task CheckImageByUploadAsync( + global::System.IO.Stream media, + string medianame, + string models, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Check Image (Upload)
+ /// Moderate an uploaded image using one or more detection models.
+ /// Supports nudity, violence, gore, weapons, drugs, alcohol, offensive content,
+ /// self-harm, scam detection, face analysis, text-in-image (OCR), QR codes,
+ /// AI-generated image detection, image type, and quality assessment. + ///
+ /// + /// The image file to analyze. + /// + /// + /// The image file to analyze. + /// + /// + /// Comma-separated list of detection models to apply.
+ /// Available models: nudity-2.1, gore-2.0, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam, face-attributes, text-content,
+ /// qr-content, genai, type, quality. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> CheckImageByUploadAsResponseAsync( + global::System.IO.Stream media, + string medianame, + string models, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckImageByUrl.g.cs b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckImageByUrl.g.cs index c72a5a5..5e72741 100644 --- a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckImageByUrl.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckImageByUrl.g.cs @@ -21,5 +21,22 @@ public partial interface ISightengineClient string models, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Check Image (URL)
+ /// Moderate an image by URL using one or more detection models.
+ /// Supports nudity, violence, gore, weapons, drugs, alcohol, offensive content,
+ /// self-harm, scam detection, face analysis, text-in-image (OCR), QR codes,
+ /// AI-generated image detection, image type, and quality assessment. + ///
+ /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> CheckImageByUrlAsResponseAsync( + string url, + string models, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckText.g.cs b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckText.g.cs index 67b9605..900fe4b 100644 --- a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckText.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckText.g.cs @@ -27,6 +27,22 @@ public partial interface ISightengineClient /// Supports rule-based mode for content filtering and username mode
/// for validating usernames. /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> CheckTextAsResponseAsync( + + global::Sightengine.CheckTextRequest request, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Check Text
+ /// Moderate text content for profanity, personal information (emails,
+ /// phone numbers, usernames, IP addresses, SSNs), and links.
+ /// Supports rule-based mode for content filtering and username mode
+ /// for validating usernames. + ///
/// /// UTF-8 formatted text to moderate. /// diff --git a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckVideoAsync.g.cs b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckVideoAsync.g.cs index fc095b4..0a06ec9 100644 --- a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckVideoAsync.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckVideoAsync.g.cs @@ -27,6 +27,22 @@ public partial interface ISightengineClient /// Supports videos longer than 60 seconds and live streams
/// (HLS, RTMP, RTMPS, RTSP, RTP, MPEG-DASH). /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> CheckVideoAsyncAsResponseAsync( + + global::Sightengine.CheckVideoAsyncRequest request, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Check Video (Asynchronous)
+ /// Start asynchronous video or live stream moderation.
+ /// Results are delivered via the callback URL.
+ /// Supports videos longer than 60 seconds and live streams
+ /// (HLS, RTMP, RTMPS, RTSP, RTP, MPEG-DASH). + ///
/// /// The video file to analyze (use this OR stream_url). /// @@ -55,5 +71,76 @@ public partial interface ISightengineClient string? callbackUrl = default, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); + + /// + /// Check Video (Asynchronous)
+ /// Start asynchronous video or live stream moderation.
+ /// Results are delivered via the callback URL.
+ /// Supports videos longer than 60 seconds and live streams
+ /// (HLS, RTMP, RTMPS, RTSP, RTP, MPEG-DASH). + ///
+ /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// Public URL of the video or live stream. + /// + /// + /// Webhook URL to receive moderation results. + /// + /// + /// Comma-separated list of detection models.
+ /// Available: nudity-2.1, gore-2.0, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task CheckVideoAsyncAsync( + string models, + global::System.IO.Stream? media = default, + string? medianame = default, + string? streamUrl = default, + string? callbackUrl = default, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Check Video (Asynchronous)
+ /// Start asynchronous video or live stream moderation.
+ /// Results are delivered via the callback URL.
+ /// Supports videos longer than 60 seconds and live streams
+ /// (HLS, RTMP, RTMPS, RTSP, RTP, MPEG-DASH). + ///
+ /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// Public URL of the video or live stream. + /// + /// + /// Webhook URL to receive moderation results. + /// + /// + /// Comma-separated list of detection models.
+ /// Available: nudity-2.1, gore-2.0, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> CheckVideoAsyncAsResponseAsync( + string models, + global::System.IO.Stream? media = default, + string? medianame = default, + string? streamUrl = default, + string? callbackUrl = default, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckVideoSync.g.cs b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckVideoSync.g.cs index 756443b..082f6e1 100644 --- a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckVideoSync.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckVideoSync.g.cs @@ -23,6 +23,20 @@ public partial interface ISightengineClient /// Moderate a video synchronously (must be under 60 seconds).
/// Submit either a raw video file or a public URL. /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> CheckVideoSyncAsResponseAsync( + + global::Sightengine.CheckVideoSyncRequest request, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Check Video (Synchronous)
+ /// Moderate a video synchronously (must be under 60 seconds).
+ /// Submit either a raw video file or a public URL. + ///
/// /// The video file to analyze (use this OR stream_url). /// @@ -47,5 +61,64 @@ public partial interface ISightengineClient string? streamUrl = default, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); + + /// + /// Check Video (Synchronous)
+ /// Moderate a video synchronously (must be under 60 seconds).
+ /// Submit either a raw video file or a public URL. + ///
+ /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// Public URL of the video (use this OR media). + /// + /// + /// Comma-separated list of detection models.
+ /// Available: nudity-2.1, gore-2.0, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task CheckVideoSyncAsync( + string models, + global::System.IO.Stream? media = default, + string? medianame = default, + string? streamUrl = default, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Check Video (Synchronous)
+ /// Moderate a video synchronously (must be under 60 seconds).
+ /// Submit either a raw video file or a public URL. + ///
+ /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// Public URL of the video (use this OR media). + /// + /// + /// Comma-separated list of detection models.
+ /// Available: nudity-2.1, gore-2.0, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> CheckVideoSyncAsResponseAsync( + string models, + global::System.IO.Stream? media = default, + string? medianame = default, + string? streamUrl = default, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckWorkflowByUpload.g.cs b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckWorkflowByUpload.g.cs index 21400ea..e520538 100644 --- a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckWorkflowByUpload.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckWorkflowByUpload.g.cs @@ -23,6 +23,20 @@ public partial interface ISightengineClient /// Moderate an uploaded image using a pre-configured workflow.
/// Workflows define custom rules and actions from the dashboard. /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> CheckWorkflowByUploadAsResponseAsync( + + global::Sightengine.CheckWorkflowByUploadRequest request, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Check Image with Workflow (Upload)
+ /// Moderate an uploaded image using a pre-configured workflow.
+ /// Workflows define custom rules and actions from the dashboard. + ///
/// /// The image file to analyze. /// @@ -41,5 +55,52 @@ public partial interface ISightengineClient string workflow, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); + + /// + /// Check Image with Workflow (Upload)
+ /// Moderate an uploaded image using a pre-configured workflow.
+ /// Workflows define custom rules and actions from the dashboard. + ///
+ /// + /// The image file to analyze. + /// + /// + /// The image file to analyze. + /// + /// + /// Workflow ID from the Sightengine dashboard. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task CheckWorkflowByUploadAsync( + global::System.IO.Stream media, + string medianame, + string workflow, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Check Image with Workflow (Upload)
+ /// Moderate an uploaded image using a pre-configured workflow.
+ /// Workflows define custom rules and actions from the dashboard. + ///
+ /// + /// The image file to analyze. + /// + /// + /// The image file to analyze. + /// + /// + /// Workflow ID from the Sightengine dashboard. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> CheckWorkflowByUploadAsResponseAsync( + global::System.IO.Stream media, + string medianame, + string workflow, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckWorkflowByUrl.g.cs b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckWorkflowByUrl.g.cs index 659c1cb..7af9bb5 100644 --- a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckWorkflowByUrl.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.CheckWorkflowByUrl.g.cs @@ -19,5 +19,20 @@ public partial interface ISightengineClient string workflow, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Check Image with Workflow (URL)
+ /// Moderate an image by URL using a pre-configured workflow.
+ /// Workflows define custom rules and actions from the dashboard. + ///
+ /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> CheckWorkflowByUrlAsResponseAsync( + string url, + string workflow, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.SubmitFeedback.g.cs b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.SubmitFeedback.g.cs index 091f00f..53b1a12 100644 --- a/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.SubmitFeedback.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.ISightengineClient.SubmitFeedback.g.cs @@ -25,6 +25,21 @@ public partial interface ISightengineClient /// Feedback submissions are free and do not count as operations.
/// The image is used to continuously improve the specified model. /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> SubmitFeedbackAsResponseAsync( + + global::Sightengine.SubmitFeedbackRequest request, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Submit Feedback
+ /// Submit moderation feedback to improve model accuracy.
+ /// Feedback submissions are free and do not count as operations.
+ /// The image is used to continuously improve the specified model. + ///
/// /// Public URL to the image (use this OR media). /// @@ -53,5 +68,74 @@ public partial interface ISightengineClient string? medianame = default, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); + + /// + /// Submit Feedback
+ /// Submit moderation feedback to improve model accuracy.
+ /// Feedback submissions are free and do not count as operations.
+ /// The image is used to continuously improve the specified model. + ///
+ /// + /// Public URL to the image (use this OR media). + /// + /// + /// The image file (use this OR url). + /// + /// + /// The image file (use this OR url). + /// + /// + /// The model that classified the image.
+ /// Available: nudity, gore, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam, genai. + /// + /// + /// The expected/correct classification result. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task SubmitFeedbackAsync( + string model, + string @class, + string? url = default, + global::System.IO.Stream? media = default, + string? medianame = default, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Submit Feedback
+ /// Submit moderation feedback to improve model accuracy.
+ /// Feedback submissions are free and do not count as operations.
+ /// The image is used to continuously improve the specified model. + ///
+ /// + /// Public URL to the image (use this OR media). + /// + /// + /// The image file (use this OR url). + /// + /// + /// The image file (use this OR url). + /// + /// + /// The model that classified the image.
+ /// Available: nudity, gore, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam, genai. + /// + /// + /// The expected/correct classification result. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> SubmitFeedbackAsResponseAsync( + string model, + string @class, + string? url = default, + global::System.IO.Stream? media = default, + string? medianame = default, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Sightengine/Generated/Sightengine.OptionsSupport.g.cs b/src/libs/Sightengine/Generated/Sightengine.OptionsSupport.g.cs index f69428a..673d401 100644 --- a/src/libs/Sightengine/Generated/Sightengine.OptionsSupport.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.OptionsSupport.g.cs @@ -101,9 +101,45 @@ public sealed class AutoSDKRetryOptions public int MaxAttempts { get; set; } = 1; /// - /// Optional fixed delay between retry attempts. + /// Optional fixed delay between retry attempts. When set, this takes precedence over exponential backoff. /// public global::System.TimeSpan? Delay { get; set; } + + /// + /// Initial exponential backoff delay used when is not set. + /// + public global::System.TimeSpan InitialDelay { get; set; } = global::System.TimeSpan.FromSeconds(1); + + /// + /// Maximum retry delay after applying retry headers, backoff, and jitter. + /// + public global::System.TimeSpan MaxDelay { get; set; } = global::System.TimeSpan.FromSeconds(30); + + /// + /// Multiplier applied to exponential backoff after each failed attempt. + /// Values below 1 are normalized to 1. + /// + public double BackoffMultiplier { get; set; } = 2D; + + /// + /// Randomizes computed backoff by plus or minus this ratio. Values are clamped to 0..1. + /// + public double JitterRatio { get; set; } = 0.2D; + + /// + /// Whether Retry-After response headers should control retry delay when present. + /// + public bool UseRetryAfterHeader { get; set; } = true; + + /// + /// Whether a rate-limit reset response header should control retry delay when present. + /// + public bool UseRateLimitResetHeader { get; set; } + + /// + /// Optional provider-specific rate-limit reset header name. Values may be Unix seconds or an HTTP date. + /// + public string? RateLimitResetHeaderName { get; set; } = "X-RateLimit-Reset"; } @@ -231,6 +267,16 @@ public sealed class AutoSDKHookContext /// public bool WillRetry { get; set; } + /// + /// The computed retry delay when is true. + /// + public global::System.TimeSpan? RetryDelay { get; set; } + + /// + /// A short retry reason such as exception or status:429. + /// + public string RetryReason { get; set; } = string.Empty; + /// /// The effective cancellation token for the current request attempt. /// @@ -254,6 +300,8 @@ internal static class AutoSDKRequestOptionsSupport int attempt, int maxAttempts, bool willRetry, + global::System.TimeSpan? retryDelay, + string retryReason, global::System.Threading.CancellationToken cancellationToken) { return new global::Sightengine.AutoSDKHookContext @@ -271,6 +319,8 @@ internal static class AutoSDKRequestOptionsSupport Attempt = attempt, MaxAttempts = maxAttempts, WillRetry = willRetry, + RetryDelay = retryDelay, + RetryReason = retryReason ?? string.Empty, CancellationToken = cancellationToken, }; } @@ -338,19 +388,188 @@ internal static int GetMaxAttempts( return maxAttempts < 1 ? 1 : maxAttempts; } - internal static async global::System.Threading.Tasks.Task DelayBeforeRetryAsync( + internal static global::System.TimeSpan GetRetryDelay( global::Sightengine.AutoSDKClientOptions clientOptions, global::Sightengine.AutoSDKRequestOptions? requestOptions, + global::System.Net.Http.HttpResponseMessage? response, + int attempt) + { + var retryOptions = requestOptions?.Retry ?? clientOptions.Retry ?? new global::Sightengine.AutoSDKRetryOptions(); + + if (retryOptions.UseRetryAfterHeader && + TryGetRetryAfterDelay(response, out var retryAfterDelay)) + { + return ClampRetryDelay(retryAfterDelay, retryOptions); + } + + if (retryOptions.UseRateLimitResetHeader && + TryGetRateLimitResetDelay(response, retryOptions.RateLimitResetHeaderName, out var rateLimitResetDelay)) + { + return ClampRetryDelay(rateLimitResetDelay, retryOptions); + } + + if (retryOptions.Delay.HasValue) + { + return ClampRetryDelay(retryOptions.Delay.Value, retryOptions); + } + + var initialDelay = retryOptions.InitialDelay; + if (initialDelay <= global::System.TimeSpan.Zero) + { + return global::System.TimeSpan.Zero; + } + + var multiplier = retryOptions.BackoffMultiplier < 1D ? 1D : retryOptions.BackoffMultiplier; + var exponent = attempt <= 1 ? 0 : attempt - 1; + var delayMilliseconds = initialDelay.TotalMilliseconds * global::System.Math.Pow(multiplier, exponent); + if (double.IsNaN(delayMilliseconds) || double.IsInfinity(delayMilliseconds) || delayMilliseconds < 0D) + { + delayMilliseconds = 0D; + } + + var delay = global::System.TimeSpan.FromMilliseconds(delayMilliseconds); + delay = ApplyJitter(delay, retryOptions.JitterRatio); + return ClampRetryDelay(delay, retryOptions); + } + + internal static async global::System.Threading.Tasks.Task DelayBeforeRetryAsync( + global::System.TimeSpan retryDelay, global::System.Threading.CancellationToken cancellationToken) { - var delay = requestOptions?.Retry?.Delay ?? - clientOptions.Retry?.Delay; - if (!delay.HasValue || delay.Value <= global::System.TimeSpan.Zero) + if (retryDelay <= global::System.TimeSpan.Zero) { return; } - await global::System.Threading.Tasks.Task.Delay(delay.Value, cancellationToken).ConfigureAwait(false); + await global::System.Threading.Tasks.Task.Delay(retryDelay, cancellationToken).ConfigureAwait(false); + } + + private static bool TryGetRetryAfterDelay( + global::System.Net.Http.HttpResponseMessage? response, + out global::System.TimeSpan delay) + { + delay = global::System.TimeSpan.Zero; + var retryAfter = response?.Headers.RetryAfter; + if (retryAfter == null) + { + return false; + } + + if (retryAfter.Delta.HasValue) + { + delay = retryAfter.Delta.Value; + return delay > global::System.TimeSpan.Zero; + } + + if (retryAfter.Date.HasValue) + { + delay = retryAfter.Date.Value - global::System.DateTimeOffset.UtcNow; + return delay > global::System.TimeSpan.Zero; + } + + return false; + } + + private static bool TryGetRateLimitResetDelay( + global::System.Net.Http.HttpResponseMessage? response, + string? headerName, + out global::System.TimeSpan delay) + { + delay = global::System.TimeSpan.Zero; + if (response == null || string.IsNullOrWhiteSpace(headerName)) + { + return false; + } + + if (!response.Headers.TryGetValues(headerName, out var values) && + (response.Content?.Headers == null || !response.Content.Headers.TryGetValues(headerName, out values))) + { + return false; + } + + var value = global::System.Linq.Enumerable.FirstOrDefault(values); + if (string.IsNullOrWhiteSpace(value)) + { + return false; + } + + value = value.Trim(); + if (long.TryParse( + value, + global::System.Globalization.NumberStyles.Integer, + global::System.Globalization.CultureInfo.InvariantCulture, + out var unixSeconds)) + { + delay = global::System.DateTimeOffset.FromUnixTimeSeconds(unixSeconds) - global::System.DateTimeOffset.UtcNow; + return delay > global::System.TimeSpan.Zero; + } + + if (global::System.DateTimeOffset.TryParse( + value, + global::System.Globalization.CultureInfo.InvariantCulture, + global::System.Globalization.DateTimeStyles.AssumeUniversal | global::System.Globalization.DateTimeStyles.AdjustToUniversal, + out var resetAt)) + { + delay = resetAt - global::System.DateTimeOffset.UtcNow; + return delay > global::System.TimeSpan.Zero; + } + + return false; + } + + private static global::System.TimeSpan ApplyJitter( + global::System.TimeSpan delay, + double jitterRatio) + { + if (delay <= global::System.TimeSpan.Zero || jitterRatio <= 0D) + { + return delay; + } + + if (jitterRatio > 1D) + { + jitterRatio = 1D; + } + + var sample = NextJitterSample(); + var multiplier = 1D - jitterRatio + (sample * jitterRatio * 2D); + var milliseconds = delay.TotalMilliseconds * multiplier; + if (double.IsNaN(milliseconds) || double.IsInfinity(milliseconds) || milliseconds < 0D) + { + milliseconds = 0D; + } + + return global::System.TimeSpan.FromMilliseconds(milliseconds); + } + + private static double NextJitterSample() + { + var bytes = new byte[8]; + using (var randomNumberGenerator = global::System.Security.Cryptography.RandomNumberGenerator.Create()) + { + randomNumberGenerator.GetBytes(bytes); + } + + var value = global::System.BitConverter.ToUInt64(bytes, 0); + return value / (double)ulong.MaxValue; + } + + private static global::System.TimeSpan ClampRetryDelay( + global::System.TimeSpan delay, + global::Sightengine.AutoSDKRetryOptions retryOptions) + { + if (delay <= global::System.TimeSpan.Zero) + { + return global::System.TimeSpan.Zero; + } + + var maxDelay = retryOptions.MaxDelay; + if (maxDelay > global::System.TimeSpan.Zero && delay > maxDelay) + { + return maxDelay; + } + + return delay; } internal static bool ShouldRetryStatusCode( diff --git a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckImageByUpload.g.cs b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckImageByUpload.g.cs index 6769fa6..9d1d5a5 100644 --- a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckImageByUpload.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckImageByUpload.g.cs @@ -54,6 +54,32 @@ partial void ProcessCheckImageByUploadResponseContent( /// public async global::System.Threading.Tasks.Task CheckImageByUploadAsync( + global::Sightengine.CheckImageByUploadRequest request, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await CheckImageByUploadAsResponseAsync( + + request: request, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Check Image (Upload)
+ /// Moderate an uploaded image using one or more detection models.
+ /// Supports nudity, violence, gore, weapons, drugs, alcohol, offensive content,
+ /// self-harm, scam detection, face analysis, text-in-image (OCR), QR codes,
+ /// AI-generated image detection, image type, and quality assessment. + ///
+ /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> CheckImageByUploadAsResponseAsync( + global::Sightengine.CheckImageByUploadRequest request, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) @@ -84,10 +110,11 @@ partial void ProcessCheckImageByUploadResponseContent( var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( clientOptions: Options, requestOptions: requestOptions, - supportsRetry: true); + supportsRetry: false); global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Sightengine.PathBuilder( path: "/check.json", baseUri: HttpClient.BaseAddress); @@ -120,6 +147,7 @@ partial void ProcessCheckImageByUploadResponseContent( __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); } } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); var __contentMedia = new global::System.Net.Http.ByteArrayContent(request.Media ?? global::System.Array.Empty()); __contentMedia.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue( @@ -158,10 +186,13 @@ request.Medianame is null { __contentMedia.Headers.ContentDisposition.FileNameStar = null; } + __httpRequestContent.Add( content: new global::System.Net.Http.StringContent(request.Models ?? string.Empty), name: "\"models\""); + __httpRequest.Content = __httpRequestContent; + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( request: __httpRequest, clientHeaders: Options.Headers, @@ -203,6 +234,8 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -213,6 +246,11 @@ request.Medianame is null } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -230,6 +268,8 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -239,8 +279,7 @@ request.Medianame is null __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -249,6 +288,11 @@ request.Medianame is null __attempt < __maxAttempts && global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -265,14 +309,15 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -312,6 +357,8 @@ request.Medianame is null attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -332,6 +379,8 @@ request.Medianame is null attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Bad request. @@ -432,9 +481,13 @@ request.Medianame is null { __response.EnsureSuccessStatusCode(); - return - global::Sightengine.ImageCheckResponse.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Sightengine.ImageCheckResponse.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -462,9 +515,13 @@ request.Medianame is null #endif ).ConfigureAwait(false); - return - await global::Sightengine.ImageCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Sightengine.ImageCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -543,5 +600,1018 @@ request.Medianame is null requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } + + /// + /// Check Image (Upload)
+ /// Moderate an uploaded image using one or more detection models.
+ /// Supports nudity, violence, gore, weapons, drugs, alcohol, offensive content,
+ /// self-harm, scam detection, face analysis, text-in-image (OCR), QR codes,
+ /// AI-generated image detection, image type, and quality assessment. + ///
+ /// + /// The image file to analyze. + /// + /// + /// The image file to analyze. + /// + /// + /// Comma-separated list of detection models to apply.
+ /// Available models: nudity-2.1, gore-2.0, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam, face-attributes, text-content,
+ /// qr-content, genai, type, quality. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task CheckImageByUploadAsync( + global::System.IO.Stream media, + string medianame, + string models, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + + media = media ?? throw new global::System.ArgumentNullException(nameof(media)); + var request = new global::Sightengine.CheckImageByUploadRequest + { + Media = global::System.Array.Empty(), + Medianame = medianame, + Models = models, + }; + PrepareArguments( + client: HttpClient); + PrepareCheckImageByUploadArguments( + httpClient: HttpClient, + request: request); + + + var __authorizations = global::Sightengine.EndPointSecurityResolver.ResolveAuthorizations( + availableAuthorizations: Authorizations, + securityRequirements: s_CheckImageByUploadSecurityRequirements, + operationName: "CheckImageByUploadAsync"); + + using var __timeoutCancellationTokenSource = global::Sightengine.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Sightengine.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: false); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + + var __pathBuilder = new global::Sightengine.PathBuilder( + path: "/check.json", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Sightengine.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); +#if NET6_0_OR_GREATER + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; +#endif + + foreach (var __authorization in __authorizations) + { + if (__authorization.Type == "Http" || + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") + { + __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( + scheme: __authorization.Name, + parameter: __authorization.Value); + } + else if (__authorization.Type == "ApiKey" && + __authorization.Location == "Header") + { + __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); + } + } + + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + var __contentMedia = new global::System.Net.Http.StreamContent(media); + __contentMedia.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue( + request.Medianame is null + ? "application/octet-stream" + : (global::System.IO.Path.GetExtension(request.Medianame) ?? string.Empty).ToLowerInvariant() switch + { + ".aac" => "audio/aac", + ".flac" => "audio/flac", + ".gif" => "image/gif", + ".jpeg" => "image/jpeg", + ".jpg" => "image/jpeg", + ".json" => "application/json", + ".m4a" => "audio/mp4", + ".mp3" => "audio/mpeg", + ".mp4" => "video/mp4", + ".mpeg" => "audio/mpeg", + ".mpga" => "audio/mpeg", + ".oga" => "audio/ogg", + ".ogg" => "audio/ogg", + ".opus" => "audio/ogg", + ".pdf" => "application/pdf", + ".png" => "image/png", + ".txt" => "text/plain", + ".wav" => "audio/wav", + ".weba" => "audio/webm", + ".webm" => "video/webm", + ".webp" => "image/webp", + _ => "application/octet-stream", + }); + __httpRequestContent.Add( + content: __contentMedia, + name: "\"media\"", + fileName: request.Medianame != null ? $"\"{request.Medianame}\"" : string.Empty); + if (__contentMedia.Headers.ContentDisposition != null) + { + __contentMedia.Headers.ContentDisposition.FileNameStar = null; + } + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Models ?? string.Empty), + name: "\"models\""); + + __httpRequest.Content = __httpRequestContent; + + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCheckImageByUploadRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); + + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try + { + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckImageByUpload", + methodName: "CheckImageByUploadAsync", + pathTemplate: "\"/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try + { + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + } + catch (global::System.Net.Http.HttpRequestException __exception) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckImageByUpload", + methodName: "CheckImageByUploadAsync", + pathTemplate: "\"/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + if (__response != null && + __attempt < __maxAttempts && + global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckImageByUpload", + methodName: "CheckImageByUploadAsync", + pathTemplate: "\"/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + break; + } + + if (__response == null) + { + throw new global::System.InvalidOperationException("No response received."); + } + + using (__response) + { + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCheckImageByUploadResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckImageByUpload", + methodName: "CheckImageByUploadAsync", + pathTemplate: "\"/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckImageByUpload", + methodName: "CheckImageByUploadAsync", + pathTemplate: "\"/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad request. + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Sightengine.ErrorResponse? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized — invalid credentials. + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Sightengine.ErrorResponse? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCheckImageByUploadResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Sightengine.ImageCheckResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Sightengine.ImageCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + + } + } + finally + { + __httpRequest?.Dispose(); + } + } + /// + /// Check Image (Upload)
+ /// Moderate an uploaded image using one or more detection models.
+ /// Supports nudity, violence, gore, weapons, drugs, alcohol, offensive content,
+ /// self-harm, scam detection, face analysis, text-in-image (OCR), QR codes,
+ /// AI-generated image detection, image type, and quality assessment. + ///
+ /// + /// The image file to analyze. + /// + /// + /// The image file to analyze. + /// + /// + /// Comma-separated list of detection models to apply.
+ /// Available models: nudity-2.1, gore-2.0, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam, face-attributes, text-content,
+ /// qr-content, genai, type, quality. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> CheckImageByUploadAsResponseAsync( + global::System.IO.Stream media, + string medianame, + string models, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + + media = media ?? throw new global::System.ArgumentNullException(nameof(media)); + var request = new global::Sightengine.CheckImageByUploadRequest + { + Media = global::System.Array.Empty(), + Medianame = medianame, + Models = models, + }; + PrepareArguments( + client: HttpClient); + PrepareCheckImageByUploadArguments( + httpClient: HttpClient, + request: request); + + + var __authorizations = global::Sightengine.EndPointSecurityResolver.ResolveAuthorizations( + availableAuthorizations: Authorizations, + securityRequirements: s_CheckImageByUploadSecurityRequirements, + operationName: "CheckImageByUploadAsync"); + + using var __timeoutCancellationTokenSource = global::Sightengine.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Sightengine.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: false); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + + var __pathBuilder = new global::Sightengine.PathBuilder( + path: "/check.json", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Sightengine.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); +#if NET6_0_OR_GREATER + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; +#endif + + foreach (var __authorization in __authorizations) + { + if (__authorization.Type == "Http" || + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") + { + __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( + scheme: __authorization.Name, + parameter: __authorization.Value); + } + else if (__authorization.Type == "ApiKey" && + __authorization.Location == "Header") + { + __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); + } + } + + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + var __contentMedia = new global::System.Net.Http.StreamContent(media); + __contentMedia.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue( + request.Medianame is null + ? "application/octet-stream" + : (global::System.IO.Path.GetExtension(request.Medianame) ?? string.Empty).ToLowerInvariant() switch + { + ".aac" => "audio/aac", + ".flac" => "audio/flac", + ".gif" => "image/gif", + ".jpeg" => "image/jpeg", + ".jpg" => "image/jpeg", + ".json" => "application/json", + ".m4a" => "audio/mp4", + ".mp3" => "audio/mpeg", + ".mp4" => "video/mp4", + ".mpeg" => "audio/mpeg", + ".mpga" => "audio/mpeg", + ".oga" => "audio/ogg", + ".ogg" => "audio/ogg", + ".opus" => "audio/ogg", + ".pdf" => "application/pdf", + ".png" => "image/png", + ".txt" => "text/plain", + ".wav" => "audio/wav", + ".weba" => "audio/webm", + ".webm" => "video/webm", + ".webp" => "image/webp", + _ => "application/octet-stream", + }); + __httpRequestContent.Add( + content: __contentMedia, + name: "\"media\"", + fileName: request.Medianame != null ? $"\"{request.Medianame}\"" : string.Empty); + if (__contentMedia.Headers.ContentDisposition != null) + { + __contentMedia.Headers.ContentDisposition.FileNameStar = null; + } + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Models ?? string.Empty), + name: "\"models\""); + + __httpRequest.Content = __httpRequestContent; + + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCheckImageByUploadRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); + + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try + { + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckImageByUpload", + methodName: "CheckImageByUploadAsync", + pathTemplate: "\"/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try + { + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + } + catch (global::System.Net.Http.HttpRequestException __exception) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckImageByUpload", + methodName: "CheckImageByUploadAsync", + pathTemplate: "\"/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + if (__response != null && + __attempt < __maxAttempts && + global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckImageByUpload", + methodName: "CheckImageByUploadAsync", + pathTemplate: "\"/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + break; + } + + if (__response == null) + { + throw new global::System.InvalidOperationException("No response received."); + } + + using (__response) + { + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCheckImageByUploadResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckImageByUpload", + methodName: "CheckImageByUploadAsync", + pathTemplate: "\"/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckImageByUpload", + methodName: "CheckImageByUploadAsync", + pathTemplate: "\"/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad request. + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Sightengine.ErrorResponse? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized — invalid credentials. + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Sightengine.ErrorResponse? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCheckImageByUploadResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Sightengine.ImageCheckResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Sightengine.ImageCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + + } + } + finally + { + __httpRequest?.Dispose(); + } + } } } \ No newline at end of file diff --git a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckImageByUrl.g.cs b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckImageByUrl.g.cs index 949a9ba..a860e7d 100644 --- a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckImageByUrl.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckImageByUrl.g.cs @@ -60,6 +60,33 @@ partial void ProcessCheckImageByUrlResponseContent( string models, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await CheckImageByUrlAsResponseAsync( + url: url, + models: models, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Check Image (URL)
+ /// Moderate an image by URL using one or more detection models.
+ /// Supports nudity, violence, gore, weapons, drugs, alcohol, offensive content,
+ /// self-harm, scam detection, face analysis, text-in-image (OCR), QR codes,
+ /// AI-generated image detection, image type, and quality assessment. + ///
+ /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> CheckImageByUrlAsResponseAsync( + string url, + string models, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( client: HttpClient); @@ -90,12 +117,13 @@ partial void ProcessCheckImageByUrlResponseContent( global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Sightengine.PathBuilder( path: "/check.json", - baseUri: HttpClient.BaseAddress); + baseUri: HttpClient.BaseAddress); __pathBuilder .AddRequiredParameter("url", url) - .AddRequiredParameter("models", models) + .AddRequiredParameter("models", models) ; var __path = __pathBuilder.ToString(); __path = global::Sightengine.AutoSDKRequestOptionsSupport.AppendQueryParameters( @@ -168,6 +196,8 @@ partial void ProcessCheckImageByUrlResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -178,6 +208,11 @@ partial void ProcessCheckImageByUrlResponseContent( } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -195,6 +230,8 @@ partial void ProcessCheckImageByUrlResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -204,8 +241,7 @@ partial void ProcessCheckImageByUrlResponseContent( __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -214,6 +250,11 @@ partial void ProcessCheckImageByUrlResponseContent( __attempt < __maxAttempts && global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -230,14 +271,15 @@ partial void ProcessCheckImageByUrlResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -277,6 +319,8 @@ partial void ProcessCheckImageByUrlResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -297,6 +341,8 @@ partial void ProcessCheckImageByUrlResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Bad request. @@ -397,9 +443,13 @@ partial void ProcessCheckImageByUrlResponseContent( { __response.EnsureSuccessStatusCode(); - return - global::Sightengine.ImageCheckResponse.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Sightengine.ImageCheckResponse.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -427,9 +477,13 @@ partial void ProcessCheckImageByUrlResponseContent( #endif ).ConfigureAwait(false); - return - await global::Sightengine.ImageCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Sightengine.ImageCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { diff --git a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckText.g.cs b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckText.g.cs index 06e0a80..917b913 100644 --- a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckText.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckText.g.cs @@ -54,6 +54,32 @@ partial void ProcessCheckTextResponseContent( /// public async global::System.Threading.Tasks.Task CheckTextAsync( + global::Sightengine.CheckTextRequest request, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await CheckTextAsResponseAsync( + + request: request, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Check Text
+ /// Moderate text content for profanity, personal information (emails,
+ /// phone numbers, usernames, IP addresses, SSNs), and links.
+ /// Supports rule-based mode for content filtering and username mode
+ /// for validating usernames. + ///
+ /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> CheckTextAsResponseAsync( + global::Sightengine.CheckTextRequest request, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) @@ -88,6 +114,7 @@ partial void ProcessCheckTextResponseContent( global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Sightengine.PathBuilder( path: "/text/check.json", baseUri: HttpClient.BaseAddress); @@ -167,6 +194,8 @@ partial void ProcessCheckTextResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -177,6 +206,11 @@ partial void ProcessCheckTextResponseContent( } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -194,6 +228,8 @@ partial void ProcessCheckTextResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -203,8 +239,7 @@ partial void ProcessCheckTextResponseContent( __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -213,6 +248,11 @@ partial void ProcessCheckTextResponseContent( __attempt < __maxAttempts && global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -229,14 +269,15 @@ partial void ProcessCheckTextResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -276,6 +317,8 @@ partial void ProcessCheckTextResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -296,6 +339,8 @@ partial void ProcessCheckTextResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Bad request. @@ -396,9 +441,13 @@ partial void ProcessCheckTextResponseContent( { __response.EnsureSuccessStatusCode(); - return - global::Sightengine.TextCheckResponse.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Sightengine.TextCheckResponse.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -426,9 +475,13 @@ partial void ProcessCheckTextResponseContent( #endif ).ConfigureAwait(false); - return - await global::Sightengine.TextCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Sightengine.TextCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { diff --git a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckVideoAsync.g.cs b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckVideoAsync.g.cs index 8bac1ad..e8b67f9 100644 --- a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckVideoAsync.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckVideoAsync.g.cs @@ -54,6 +54,32 @@ partial void ProcessCheckVideoAsyncResponseContent( /// public async global::System.Threading.Tasks.Task CheckVideoAsyncAsync( + global::Sightengine.CheckVideoAsyncRequest request, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await CheckVideoAsyncAsResponseAsync( + + request: request, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Check Video (Asynchronous)
+ /// Start asynchronous video or live stream moderation.
+ /// Results are delivered via the callback URL.
+ /// Supports videos longer than 60 seconds and live streams
+ /// (HLS, RTMP, RTMPS, RTSP, RTP, MPEG-DASH). + ///
+ /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> CheckVideoAsyncAsResponseAsync( + global::Sightengine.CheckVideoAsyncRequest request, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) @@ -84,10 +110,11 @@ partial void ProcessCheckVideoAsyncResponseContent( var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( clientOptions: Options, requestOptions: requestOptions, - supportsRetry: true); + supportsRetry: false); global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Sightengine.PathBuilder( path: "/video/check.json", baseUri: HttpClient.BaseAddress); @@ -120,6 +147,7 @@ partial void ProcessCheckVideoAsyncResponseContent( __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); } } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); if (request.Media != default) { @@ -161,25 +189,30 @@ request.Medianame is null { __contentMedia.Headers.ContentDisposition.FileNameStar = null; } - } + + } if (request.StreamUrl != default) { __httpRequestContent.Add( content: new global::System.Net.Http.StringContent(request.StreamUrl ?? string.Empty), name: "\"stream_url\""); - } + + } if (request.CallbackUrl != default) { __httpRequestContent.Add( content: new global::System.Net.Http.StringContent(request.CallbackUrl ?? string.Empty), name: "\"callback_url\""); + } __httpRequestContent.Add( content: new global::System.Net.Http.StringContent(request.Models ?? string.Empty), name: "\"models\""); + __httpRequest.Content = __httpRequestContent; + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( request: __httpRequest, clientHeaders: Options.Headers, @@ -221,6 +254,8 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -231,6 +266,11 @@ request.Medianame is null } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -248,6 +288,8 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -257,8 +299,7 @@ request.Medianame is null __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -267,6 +308,11 @@ request.Medianame is null __attempt < __maxAttempts && global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -283,14 +329,15 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -330,6 +377,8 @@ request.Medianame is null attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -350,6 +399,8 @@ request.Medianame is null attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Bad request. @@ -450,9 +501,13 @@ request.Medianame is null { __response.EnsureSuccessStatusCode(); - return - global::Sightengine.VideoCheckAsyncResponse.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Sightengine.VideoCheckAsyncResponse.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -480,9 +535,13 @@ request.Medianame is null #endif ).ConfigureAwait(false); - return - await global::Sightengine.VideoCheckAsyncResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Sightengine.VideoCheckAsyncResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -570,5 +629,1074 @@ request.Medianame is null requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } + + /// + /// Check Video (Asynchronous)
+ /// Start asynchronous video or live stream moderation.
+ /// Results are delivered via the callback URL.
+ /// Supports videos longer than 60 seconds and live streams
+ /// (HLS, RTMP, RTMPS, RTSP, RTP, MPEG-DASH). + ///
+ /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// Public URL of the video or live stream. + /// + /// + /// Webhook URL to receive moderation results. + /// + /// + /// Comma-separated list of detection models.
+ /// Available: nudity-2.1, gore-2.0, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task CheckVideoAsyncAsync( + string models, + global::System.IO.Stream? media = default, + string? medianame = default, + string? streamUrl = default, + string? callbackUrl = default, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + + var request = new global::Sightengine.CheckVideoAsyncRequest + { + Media = global::System.Array.Empty(), + Medianame = medianame, + StreamUrl = streamUrl, + CallbackUrl = callbackUrl, + Models = models, + }; + PrepareArguments( + client: HttpClient); + PrepareCheckVideoAsyncArguments( + httpClient: HttpClient, + request: request); + + + var __authorizations = global::Sightengine.EndPointSecurityResolver.ResolveAuthorizations( + availableAuthorizations: Authorizations, + securityRequirements: s_CheckVideoAsyncSecurityRequirements, + operationName: "CheckVideoAsyncAsync"); + + using var __timeoutCancellationTokenSource = global::Sightengine.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Sightengine.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: false); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + + var __pathBuilder = new global::Sightengine.PathBuilder( + path: "/video/check.json", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Sightengine.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); +#if NET6_0_OR_GREATER + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; +#endif + + foreach (var __authorization in __authorizations) + { + if (__authorization.Type == "Http" || + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") + { + __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( + scheme: __authorization.Name, + parameter: __authorization.Value); + } + else if (__authorization.Type == "ApiKey" && + __authorization.Location == "Header") + { + __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); + } + } + + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (media != default) + { + + var __contentMedia = new global::System.Net.Http.StreamContent(media); + __contentMedia.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue( + request.Medianame is null + ? "application/octet-stream" + : (global::System.IO.Path.GetExtension(request.Medianame) ?? string.Empty).ToLowerInvariant() switch + { + ".aac" => "audio/aac", + ".flac" => "audio/flac", + ".gif" => "image/gif", + ".jpeg" => "image/jpeg", + ".jpg" => "image/jpeg", + ".json" => "application/json", + ".m4a" => "audio/mp4", + ".mp3" => "audio/mpeg", + ".mp4" => "video/mp4", + ".mpeg" => "audio/mpeg", + ".mpga" => "audio/mpeg", + ".oga" => "audio/ogg", + ".ogg" => "audio/ogg", + ".opus" => "audio/ogg", + ".pdf" => "application/pdf", + ".png" => "image/png", + ".txt" => "text/plain", + ".wav" => "audio/wav", + ".weba" => "audio/webm", + ".webm" => "video/webm", + ".webp" => "image/webp", + _ => "application/octet-stream", + }); + __httpRequestContent.Add( + content: __contentMedia, + name: "\"media\"", + fileName: request.Medianame != null ? $"\"{request.Medianame}\"" : string.Empty); + if (__contentMedia.Headers.ContentDisposition != null) + { + __contentMedia.Headers.ContentDisposition.FileNameStar = null; + } + + } + if (request.StreamUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.StreamUrl ?? string.Empty), + name: "\"stream_url\""); + + } + if (request.CallbackUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.CallbackUrl ?? string.Empty), + name: "\"callback_url\""); + + } + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Models ?? string.Empty), + name: "\"models\""); + + __httpRequest.Content = __httpRequestContent; + + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCheckVideoAsyncRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); + + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try + { + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoAsync", + methodName: "CheckVideoAsyncAsync", + pathTemplate: "\"/video/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try + { + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + } + catch (global::System.Net.Http.HttpRequestException __exception) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoAsync", + methodName: "CheckVideoAsyncAsync", + pathTemplate: "\"/video/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + if (__response != null && + __attempt < __maxAttempts && + global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoAsync", + methodName: "CheckVideoAsyncAsync", + pathTemplate: "\"/video/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + break; + } + + if (__response == null) + { + throw new global::System.InvalidOperationException("No response received."); + } + + using (__response) + { + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCheckVideoAsyncResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoAsync", + methodName: "CheckVideoAsyncAsync", + pathTemplate: "\"/video/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoAsync", + methodName: "CheckVideoAsyncAsync", + pathTemplate: "\"/video/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad request. + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Sightengine.ErrorResponse? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized. + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Sightengine.ErrorResponse? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCheckVideoAsyncResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Sightengine.VideoCheckAsyncResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Sightengine.VideoCheckAsyncResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + + } + } + finally + { + __httpRequest?.Dispose(); + } + } + /// + /// Check Video (Asynchronous)
+ /// Start asynchronous video or live stream moderation.
+ /// Results are delivered via the callback URL.
+ /// Supports videos longer than 60 seconds and live streams
+ /// (HLS, RTMP, RTMPS, RTSP, RTP, MPEG-DASH). + ///
+ /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// Public URL of the video or live stream. + /// + /// + /// Webhook URL to receive moderation results. + /// + /// + /// Comma-separated list of detection models.
+ /// Available: nudity-2.1, gore-2.0, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> CheckVideoAsyncAsResponseAsync( + string models, + global::System.IO.Stream? media = default, + string? medianame = default, + string? streamUrl = default, + string? callbackUrl = default, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + + var request = new global::Sightengine.CheckVideoAsyncRequest + { + Media = global::System.Array.Empty(), + Medianame = medianame, + StreamUrl = streamUrl, + CallbackUrl = callbackUrl, + Models = models, + }; + PrepareArguments( + client: HttpClient); + PrepareCheckVideoAsyncArguments( + httpClient: HttpClient, + request: request); + + + var __authorizations = global::Sightengine.EndPointSecurityResolver.ResolveAuthorizations( + availableAuthorizations: Authorizations, + securityRequirements: s_CheckVideoAsyncSecurityRequirements, + operationName: "CheckVideoAsyncAsync"); + + using var __timeoutCancellationTokenSource = global::Sightengine.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Sightengine.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: false); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + + var __pathBuilder = new global::Sightengine.PathBuilder( + path: "/video/check.json", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Sightengine.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); +#if NET6_0_OR_GREATER + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; +#endif + + foreach (var __authorization in __authorizations) + { + if (__authorization.Type == "Http" || + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") + { + __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( + scheme: __authorization.Name, + parameter: __authorization.Value); + } + else if (__authorization.Type == "ApiKey" && + __authorization.Location == "Header") + { + __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); + } + } + + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (media != default) + { + + var __contentMedia = new global::System.Net.Http.StreamContent(media); + __contentMedia.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue( + request.Medianame is null + ? "application/octet-stream" + : (global::System.IO.Path.GetExtension(request.Medianame) ?? string.Empty).ToLowerInvariant() switch + { + ".aac" => "audio/aac", + ".flac" => "audio/flac", + ".gif" => "image/gif", + ".jpeg" => "image/jpeg", + ".jpg" => "image/jpeg", + ".json" => "application/json", + ".m4a" => "audio/mp4", + ".mp3" => "audio/mpeg", + ".mp4" => "video/mp4", + ".mpeg" => "audio/mpeg", + ".mpga" => "audio/mpeg", + ".oga" => "audio/ogg", + ".ogg" => "audio/ogg", + ".opus" => "audio/ogg", + ".pdf" => "application/pdf", + ".png" => "image/png", + ".txt" => "text/plain", + ".wav" => "audio/wav", + ".weba" => "audio/webm", + ".webm" => "video/webm", + ".webp" => "image/webp", + _ => "application/octet-stream", + }); + __httpRequestContent.Add( + content: __contentMedia, + name: "\"media\"", + fileName: request.Medianame != null ? $"\"{request.Medianame}\"" : string.Empty); + if (__contentMedia.Headers.ContentDisposition != null) + { + __contentMedia.Headers.ContentDisposition.FileNameStar = null; + } + + } + if (request.StreamUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.StreamUrl ?? string.Empty), + name: "\"stream_url\""); + + } + if (request.CallbackUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.CallbackUrl ?? string.Empty), + name: "\"callback_url\""); + + } + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Models ?? string.Empty), + name: "\"models\""); + + __httpRequest.Content = __httpRequestContent; + + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCheckVideoAsyncRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); + + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try + { + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoAsync", + methodName: "CheckVideoAsyncAsync", + pathTemplate: "\"/video/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try + { + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + } + catch (global::System.Net.Http.HttpRequestException __exception) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoAsync", + methodName: "CheckVideoAsyncAsync", + pathTemplate: "\"/video/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + if (__response != null && + __attempt < __maxAttempts && + global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoAsync", + methodName: "CheckVideoAsyncAsync", + pathTemplate: "\"/video/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + break; + } + + if (__response == null) + { + throw new global::System.InvalidOperationException("No response received."); + } + + using (__response) + { + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCheckVideoAsyncResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoAsync", + methodName: "CheckVideoAsyncAsync", + pathTemplate: "\"/video/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoAsync", + methodName: "CheckVideoAsyncAsync", + pathTemplate: "\"/video/check.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad request. + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Sightengine.ErrorResponse? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized. + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Sightengine.ErrorResponse? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCheckVideoAsyncResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Sightengine.VideoCheckAsyncResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Sightengine.VideoCheckAsyncResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + + } + } + finally + { + __httpRequest?.Dispose(); + } + } } } \ No newline at end of file diff --git a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckVideoSync.g.cs b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckVideoSync.g.cs index 3167037..14dd231 100644 --- a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckVideoSync.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckVideoSync.g.cs @@ -52,6 +52,30 @@ partial void ProcessCheckVideoSyncResponseContent( /// public async global::System.Threading.Tasks.Task CheckVideoSyncAsync( + global::Sightengine.CheckVideoSyncRequest request, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await CheckVideoSyncAsResponseAsync( + + request: request, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Check Video (Synchronous)
+ /// Moderate a video synchronously (must be under 60 seconds).
+ /// Submit either a raw video file or a public URL. + ///
+ /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> CheckVideoSyncAsResponseAsync( + global::Sightengine.CheckVideoSyncRequest request, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) @@ -82,10 +106,11 @@ partial void ProcessCheckVideoSyncResponseContent( var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( clientOptions: Options, requestOptions: requestOptions, - supportsRetry: true); + supportsRetry: false); global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Sightengine.PathBuilder( path: "/video/check-sync.json", baseUri: HttpClient.BaseAddress); @@ -118,6 +143,7 @@ partial void ProcessCheckVideoSyncResponseContent( __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); } } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); if (request.Media != default) { @@ -159,18 +185,22 @@ request.Medianame is null { __contentMedia.Headers.ContentDisposition.FileNameStar = null; } - } + + } if (request.StreamUrl != default) { __httpRequestContent.Add( content: new global::System.Net.Http.StringContent(request.StreamUrl ?? string.Empty), name: "\"stream_url\""); + } __httpRequestContent.Add( content: new global::System.Net.Http.StringContent(request.Models ?? string.Empty), name: "\"models\""); + __httpRequest.Content = __httpRequestContent; + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( request: __httpRequest, clientHeaders: Options.Headers, @@ -212,6 +242,8 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -222,6 +254,11 @@ request.Medianame is null } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -239,6 +276,8 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -248,8 +287,7 @@ request.Medianame is null __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -258,6 +296,11 @@ request.Medianame is null __attempt < __maxAttempts && global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -274,14 +317,15 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -321,6 +365,8 @@ request.Medianame is null attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -341,6 +387,8 @@ request.Medianame is null attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Bad request. @@ -441,9 +489,13 @@ request.Medianame is null { __response.EnsureSuccessStatusCode(); - return - global::Sightengine.VideoCheckSyncResponse.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Sightengine.VideoCheckSyncResponse.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -471,9 +523,13 @@ request.Medianame is null #endif ).ConfigureAwait(false); - return - await global::Sightengine.VideoCheckSyncResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Sightengine.VideoCheckSyncResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -554,5 +610,1044 @@ request.Medianame is null requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } + + /// + /// Check Video (Synchronous)
+ /// Moderate a video synchronously (must be under 60 seconds).
+ /// Submit either a raw video file or a public URL. + ///
+ /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// Public URL of the video (use this OR media). + /// + /// + /// Comma-separated list of detection models.
+ /// Available: nudity-2.1, gore-2.0, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task CheckVideoSyncAsync( + string models, + global::System.IO.Stream? media = default, + string? medianame = default, + string? streamUrl = default, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + + var request = new global::Sightengine.CheckVideoSyncRequest + { + Media = global::System.Array.Empty(), + Medianame = medianame, + StreamUrl = streamUrl, + Models = models, + }; + PrepareArguments( + client: HttpClient); + PrepareCheckVideoSyncArguments( + httpClient: HttpClient, + request: request); + + + var __authorizations = global::Sightengine.EndPointSecurityResolver.ResolveAuthorizations( + availableAuthorizations: Authorizations, + securityRequirements: s_CheckVideoSyncSecurityRequirements, + operationName: "CheckVideoSyncAsync"); + + using var __timeoutCancellationTokenSource = global::Sightengine.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Sightengine.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: false); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + + var __pathBuilder = new global::Sightengine.PathBuilder( + path: "/video/check-sync.json", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Sightengine.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); +#if NET6_0_OR_GREATER + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; +#endif + + foreach (var __authorization in __authorizations) + { + if (__authorization.Type == "Http" || + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") + { + __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( + scheme: __authorization.Name, + parameter: __authorization.Value); + } + else if (__authorization.Type == "ApiKey" && + __authorization.Location == "Header") + { + __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); + } + } + + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (media != default) + { + + var __contentMedia = new global::System.Net.Http.StreamContent(media); + __contentMedia.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue( + request.Medianame is null + ? "application/octet-stream" + : (global::System.IO.Path.GetExtension(request.Medianame) ?? string.Empty).ToLowerInvariant() switch + { + ".aac" => "audio/aac", + ".flac" => "audio/flac", + ".gif" => "image/gif", + ".jpeg" => "image/jpeg", + ".jpg" => "image/jpeg", + ".json" => "application/json", + ".m4a" => "audio/mp4", + ".mp3" => "audio/mpeg", + ".mp4" => "video/mp4", + ".mpeg" => "audio/mpeg", + ".mpga" => "audio/mpeg", + ".oga" => "audio/ogg", + ".ogg" => "audio/ogg", + ".opus" => "audio/ogg", + ".pdf" => "application/pdf", + ".png" => "image/png", + ".txt" => "text/plain", + ".wav" => "audio/wav", + ".weba" => "audio/webm", + ".webm" => "video/webm", + ".webp" => "image/webp", + _ => "application/octet-stream", + }); + __httpRequestContent.Add( + content: __contentMedia, + name: "\"media\"", + fileName: request.Medianame != null ? $"\"{request.Medianame}\"" : string.Empty); + if (__contentMedia.Headers.ContentDisposition != null) + { + __contentMedia.Headers.ContentDisposition.FileNameStar = null; + } + + } + if (request.StreamUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.StreamUrl ?? string.Empty), + name: "\"stream_url\""); + + } + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Models ?? string.Empty), + name: "\"models\""); + + __httpRequest.Content = __httpRequestContent; + + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCheckVideoSyncRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); + + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try + { + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoSync", + methodName: "CheckVideoSyncAsync", + pathTemplate: "\"/video/check-sync.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try + { + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + } + catch (global::System.Net.Http.HttpRequestException __exception) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoSync", + methodName: "CheckVideoSyncAsync", + pathTemplate: "\"/video/check-sync.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + if (__response != null && + __attempt < __maxAttempts && + global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoSync", + methodName: "CheckVideoSyncAsync", + pathTemplate: "\"/video/check-sync.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + break; + } + + if (__response == null) + { + throw new global::System.InvalidOperationException("No response received."); + } + + using (__response) + { + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCheckVideoSyncResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoSync", + methodName: "CheckVideoSyncAsync", + pathTemplate: "\"/video/check-sync.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoSync", + methodName: "CheckVideoSyncAsync", + pathTemplate: "\"/video/check-sync.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad request. + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Sightengine.ErrorResponse? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized. + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Sightengine.ErrorResponse? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCheckVideoSyncResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Sightengine.VideoCheckSyncResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Sightengine.VideoCheckSyncResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + + } + } + finally + { + __httpRequest?.Dispose(); + } + } + /// + /// Check Video (Synchronous)
+ /// Moderate a video synchronously (must be under 60 seconds).
+ /// Submit either a raw video file or a public URL. + ///
+ /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// The video file to analyze (use this OR stream_url). + /// + /// + /// Public URL of the video (use this OR media). + /// + /// + /// Comma-separated list of detection models.
+ /// Available: nudity-2.1, gore-2.0, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> CheckVideoSyncAsResponseAsync( + string models, + global::System.IO.Stream? media = default, + string? medianame = default, + string? streamUrl = default, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + + var request = new global::Sightengine.CheckVideoSyncRequest + { + Media = global::System.Array.Empty(), + Medianame = medianame, + StreamUrl = streamUrl, + Models = models, + }; + PrepareArguments( + client: HttpClient); + PrepareCheckVideoSyncArguments( + httpClient: HttpClient, + request: request); + + + var __authorizations = global::Sightengine.EndPointSecurityResolver.ResolveAuthorizations( + availableAuthorizations: Authorizations, + securityRequirements: s_CheckVideoSyncSecurityRequirements, + operationName: "CheckVideoSyncAsync"); + + using var __timeoutCancellationTokenSource = global::Sightengine.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Sightengine.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: false); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + + var __pathBuilder = new global::Sightengine.PathBuilder( + path: "/video/check-sync.json", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Sightengine.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); +#if NET6_0_OR_GREATER + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; +#endif + + foreach (var __authorization in __authorizations) + { + if (__authorization.Type == "Http" || + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") + { + __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( + scheme: __authorization.Name, + parameter: __authorization.Value); + } + else if (__authorization.Type == "ApiKey" && + __authorization.Location == "Header") + { + __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); + } + } + + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (media != default) + { + + var __contentMedia = new global::System.Net.Http.StreamContent(media); + __contentMedia.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue( + request.Medianame is null + ? "application/octet-stream" + : (global::System.IO.Path.GetExtension(request.Medianame) ?? string.Empty).ToLowerInvariant() switch + { + ".aac" => "audio/aac", + ".flac" => "audio/flac", + ".gif" => "image/gif", + ".jpeg" => "image/jpeg", + ".jpg" => "image/jpeg", + ".json" => "application/json", + ".m4a" => "audio/mp4", + ".mp3" => "audio/mpeg", + ".mp4" => "video/mp4", + ".mpeg" => "audio/mpeg", + ".mpga" => "audio/mpeg", + ".oga" => "audio/ogg", + ".ogg" => "audio/ogg", + ".opus" => "audio/ogg", + ".pdf" => "application/pdf", + ".png" => "image/png", + ".txt" => "text/plain", + ".wav" => "audio/wav", + ".weba" => "audio/webm", + ".webm" => "video/webm", + ".webp" => "image/webp", + _ => "application/octet-stream", + }); + __httpRequestContent.Add( + content: __contentMedia, + name: "\"media\"", + fileName: request.Medianame != null ? $"\"{request.Medianame}\"" : string.Empty); + if (__contentMedia.Headers.ContentDisposition != null) + { + __contentMedia.Headers.ContentDisposition.FileNameStar = null; + } + + } + if (request.StreamUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.StreamUrl ?? string.Empty), + name: "\"stream_url\""); + + } + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Models ?? string.Empty), + name: "\"models\""); + + __httpRequest.Content = __httpRequestContent; + + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCheckVideoSyncRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); + + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try + { + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoSync", + methodName: "CheckVideoSyncAsync", + pathTemplate: "\"/video/check-sync.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try + { + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + } + catch (global::System.Net.Http.HttpRequestException __exception) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoSync", + methodName: "CheckVideoSyncAsync", + pathTemplate: "\"/video/check-sync.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + if (__response != null && + __attempt < __maxAttempts && + global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoSync", + methodName: "CheckVideoSyncAsync", + pathTemplate: "\"/video/check-sync.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + break; + } + + if (__response == null) + { + throw new global::System.InvalidOperationException("No response received."); + } + + using (__response) + { + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCheckVideoSyncResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoSync", + methodName: "CheckVideoSyncAsync", + pathTemplate: "\"/video/check-sync.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckVideoSync", + methodName: "CheckVideoSyncAsync", + pathTemplate: "\"/video/check-sync.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad request. + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Sightengine.ErrorResponse? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized. + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Sightengine.ErrorResponse? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCheckVideoSyncResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Sightengine.VideoCheckSyncResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Sightengine.VideoCheckSyncResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + + } + } + finally + { + __httpRequest?.Dispose(); + } + } } } \ No newline at end of file diff --git a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckWorkflowByUpload.g.cs b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckWorkflowByUpload.g.cs index bbce4c9..473ad24 100644 --- a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckWorkflowByUpload.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckWorkflowByUpload.g.cs @@ -52,6 +52,30 @@ partial void ProcessCheckWorkflowByUploadResponseContent( /// public async global::System.Threading.Tasks.Task CheckWorkflowByUploadAsync( + global::Sightengine.CheckWorkflowByUploadRequest request, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await CheckWorkflowByUploadAsResponseAsync( + + request: request, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Check Image with Workflow (Upload)
+ /// Moderate an uploaded image using a pre-configured workflow.
+ /// Workflows define custom rules and actions from the dashboard. + ///
+ /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> CheckWorkflowByUploadAsResponseAsync( + global::Sightengine.CheckWorkflowByUploadRequest request, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) @@ -82,10 +106,11 @@ partial void ProcessCheckWorkflowByUploadResponseContent( var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( clientOptions: Options, requestOptions: requestOptions, - supportsRetry: true); + supportsRetry: false); global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Sightengine.PathBuilder( path: "/check-workflow.json", baseUri: HttpClient.BaseAddress); @@ -118,6 +143,7 @@ partial void ProcessCheckWorkflowByUploadResponseContent( __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); } } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); var __contentMedia = new global::System.Net.Http.ByteArrayContent(request.Media ?? global::System.Array.Empty()); __contentMedia.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue( @@ -156,10 +182,13 @@ request.Medianame is null { __contentMedia.Headers.ContentDisposition.FileNameStar = null; } + __httpRequestContent.Add( content: new global::System.Net.Http.StringContent(request.Workflow ?? string.Empty), name: "\"workflow\""); + __httpRequest.Content = __httpRequestContent; + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( request: __httpRequest, clientHeaders: Options.Headers, @@ -201,6 +230,8 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -211,6 +242,11 @@ request.Medianame is null } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -228,6 +264,8 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -237,8 +275,7 @@ request.Medianame is null __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -247,6 +284,11 @@ request.Medianame is null __attempt < __maxAttempts && global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -263,14 +305,15 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -310,6 +353,8 @@ request.Medianame is null attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -330,6 +375,8 @@ request.Medianame is null attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Bad request. @@ -430,9 +477,13 @@ request.Medianame is null { __response.EnsureSuccessStatusCode(); - return - global::Sightengine.WorkflowCheckResponse.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Sightengine.WorkflowCheckResponse.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -460,9 +511,13 @@ request.Medianame is null #endif ).ConfigureAwait(false); - return - await global::Sightengine.WorkflowCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Sightengine.WorkflowCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -536,5 +591,1008 @@ request.Medianame is null requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } + + /// + /// Check Image with Workflow (Upload)
+ /// Moderate an uploaded image using a pre-configured workflow.
+ /// Workflows define custom rules and actions from the dashboard. + ///
+ /// + /// The image file to analyze. + /// + /// + /// The image file to analyze. + /// + /// + /// Workflow ID from the Sightengine dashboard. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task CheckWorkflowByUploadAsync( + global::System.IO.Stream media, + string medianame, + string workflow, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + + media = media ?? throw new global::System.ArgumentNullException(nameof(media)); + var request = new global::Sightengine.CheckWorkflowByUploadRequest + { + Media = global::System.Array.Empty(), + Medianame = medianame, + Workflow = workflow, + }; + PrepareArguments( + client: HttpClient); + PrepareCheckWorkflowByUploadArguments( + httpClient: HttpClient, + request: request); + + + var __authorizations = global::Sightengine.EndPointSecurityResolver.ResolveAuthorizations( + availableAuthorizations: Authorizations, + securityRequirements: s_CheckWorkflowByUploadSecurityRequirements, + operationName: "CheckWorkflowByUploadAsync"); + + using var __timeoutCancellationTokenSource = global::Sightengine.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Sightengine.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: false); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + + var __pathBuilder = new global::Sightengine.PathBuilder( + path: "/check-workflow.json", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Sightengine.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); +#if NET6_0_OR_GREATER + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; +#endif + + foreach (var __authorization in __authorizations) + { + if (__authorization.Type == "Http" || + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") + { + __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( + scheme: __authorization.Name, + parameter: __authorization.Value); + } + else if (__authorization.Type == "ApiKey" && + __authorization.Location == "Header") + { + __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); + } + } + + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + var __contentMedia = new global::System.Net.Http.StreamContent(media); + __contentMedia.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue( + request.Medianame is null + ? "application/octet-stream" + : (global::System.IO.Path.GetExtension(request.Medianame) ?? string.Empty).ToLowerInvariant() switch + { + ".aac" => "audio/aac", + ".flac" => "audio/flac", + ".gif" => "image/gif", + ".jpeg" => "image/jpeg", + ".jpg" => "image/jpeg", + ".json" => "application/json", + ".m4a" => "audio/mp4", + ".mp3" => "audio/mpeg", + ".mp4" => "video/mp4", + ".mpeg" => "audio/mpeg", + ".mpga" => "audio/mpeg", + ".oga" => "audio/ogg", + ".ogg" => "audio/ogg", + ".opus" => "audio/ogg", + ".pdf" => "application/pdf", + ".png" => "image/png", + ".txt" => "text/plain", + ".wav" => "audio/wav", + ".weba" => "audio/webm", + ".webm" => "video/webm", + ".webp" => "image/webp", + _ => "application/octet-stream", + }); + __httpRequestContent.Add( + content: __contentMedia, + name: "\"media\"", + fileName: request.Medianame != null ? $"\"{request.Medianame}\"" : string.Empty); + if (__contentMedia.Headers.ContentDisposition != null) + { + __contentMedia.Headers.ContentDisposition.FileNameStar = null; + } + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Workflow ?? string.Empty), + name: "\"workflow\""); + + __httpRequest.Content = __httpRequestContent; + + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCheckWorkflowByUploadRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); + + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try + { + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckWorkflowByUpload", + methodName: "CheckWorkflowByUploadAsync", + pathTemplate: "\"/check-workflow.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try + { + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + } + catch (global::System.Net.Http.HttpRequestException __exception) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckWorkflowByUpload", + methodName: "CheckWorkflowByUploadAsync", + pathTemplate: "\"/check-workflow.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + if (__response != null && + __attempt < __maxAttempts && + global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckWorkflowByUpload", + methodName: "CheckWorkflowByUploadAsync", + pathTemplate: "\"/check-workflow.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + break; + } + + if (__response == null) + { + throw new global::System.InvalidOperationException("No response received."); + } + + using (__response) + { + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCheckWorkflowByUploadResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckWorkflowByUpload", + methodName: "CheckWorkflowByUploadAsync", + pathTemplate: "\"/check-workflow.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckWorkflowByUpload", + methodName: "CheckWorkflowByUploadAsync", + pathTemplate: "\"/check-workflow.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad request. + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Sightengine.ErrorResponse? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized. + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Sightengine.ErrorResponse? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCheckWorkflowByUploadResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Sightengine.WorkflowCheckResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Sightengine.WorkflowCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + + } + } + finally + { + __httpRequest?.Dispose(); + } + } + /// + /// Check Image with Workflow (Upload)
+ /// Moderate an uploaded image using a pre-configured workflow.
+ /// Workflows define custom rules and actions from the dashboard. + ///
+ /// + /// The image file to analyze. + /// + /// + /// The image file to analyze. + /// + /// + /// Workflow ID from the Sightengine dashboard. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> CheckWorkflowByUploadAsResponseAsync( + global::System.IO.Stream media, + string medianame, + string workflow, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + + media = media ?? throw new global::System.ArgumentNullException(nameof(media)); + var request = new global::Sightengine.CheckWorkflowByUploadRequest + { + Media = global::System.Array.Empty(), + Medianame = medianame, + Workflow = workflow, + }; + PrepareArguments( + client: HttpClient); + PrepareCheckWorkflowByUploadArguments( + httpClient: HttpClient, + request: request); + + + var __authorizations = global::Sightengine.EndPointSecurityResolver.ResolveAuthorizations( + availableAuthorizations: Authorizations, + securityRequirements: s_CheckWorkflowByUploadSecurityRequirements, + operationName: "CheckWorkflowByUploadAsync"); + + using var __timeoutCancellationTokenSource = global::Sightengine.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Sightengine.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: false); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + + var __pathBuilder = new global::Sightengine.PathBuilder( + path: "/check-workflow.json", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Sightengine.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); +#if NET6_0_OR_GREATER + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; +#endif + + foreach (var __authorization in __authorizations) + { + if (__authorization.Type == "Http" || + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") + { + __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( + scheme: __authorization.Name, + parameter: __authorization.Value); + } + else if (__authorization.Type == "ApiKey" && + __authorization.Location == "Header") + { + __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); + } + } + + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + var __contentMedia = new global::System.Net.Http.StreamContent(media); + __contentMedia.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue( + request.Medianame is null + ? "application/octet-stream" + : (global::System.IO.Path.GetExtension(request.Medianame) ?? string.Empty).ToLowerInvariant() switch + { + ".aac" => "audio/aac", + ".flac" => "audio/flac", + ".gif" => "image/gif", + ".jpeg" => "image/jpeg", + ".jpg" => "image/jpeg", + ".json" => "application/json", + ".m4a" => "audio/mp4", + ".mp3" => "audio/mpeg", + ".mp4" => "video/mp4", + ".mpeg" => "audio/mpeg", + ".mpga" => "audio/mpeg", + ".oga" => "audio/ogg", + ".ogg" => "audio/ogg", + ".opus" => "audio/ogg", + ".pdf" => "application/pdf", + ".png" => "image/png", + ".txt" => "text/plain", + ".wav" => "audio/wav", + ".weba" => "audio/webm", + ".webm" => "video/webm", + ".webp" => "image/webp", + _ => "application/octet-stream", + }); + __httpRequestContent.Add( + content: __contentMedia, + name: "\"media\"", + fileName: request.Medianame != null ? $"\"{request.Medianame}\"" : string.Empty); + if (__contentMedia.Headers.ContentDisposition != null) + { + __contentMedia.Headers.ContentDisposition.FileNameStar = null; + } + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Workflow ?? string.Empty), + name: "\"workflow\""); + + __httpRequest.Content = __httpRequestContent; + + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCheckWorkflowByUploadRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); + + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try + { + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckWorkflowByUpload", + methodName: "CheckWorkflowByUploadAsync", + pathTemplate: "\"/check-workflow.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try + { + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + } + catch (global::System.Net.Http.HttpRequestException __exception) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckWorkflowByUpload", + methodName: "CheckWorkflowByUploadAsync", + pathTemplate: "\"/check-workflow.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + if (__response != null && + __attempt < __maxAttempts && + global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckWorkflowByUpload", + methodName: "CheckWorkflowByUploadAsync", + pathTemplate: "\"/check-workflow.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + break; + } + + if (__response == null) + { + throw new global::System.InvalidOperationException("No response received."); + } + + using (__response) + { + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCheckWorkflowByUploadResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckWorkflowByUpload", + methodName: "CheckWorkflowByUploadAsync", + pathTemplate: "\"/check-workflow.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CheckWorkflowByUpload", + methodName: "CheckWorkflowByUploadAsync", + pathTemplate: "\"/check-workflow.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad request. + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Sightengine.ErrorResponse? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized. + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Sightengine.ErrorResponse? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCheckWorkflowByUploadResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Sightengine.WorkflowCheckResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Sightengine.WorkflowCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + + } + } + finally + { + __httpRequest?.Dispose(); + } + } } } \ No newline at end of file diff --git a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckWorkflowByUrl.g.cs b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckWorkflowByUrl.g.cs index 4914c38..8c49a89 100644 --- a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckWorkflowByUrl.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.CheckWorkflowByUrl.g.cs @@ -58,6 +58,31 @@ partial void ProcessCheckWorkflowByUrlResponseContent( string workflow, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await CheckWorkflowByUrlAsResponseAsync( + url: url, + workflow: workflow, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Check Image with Workflow (URL)
+ /// Moderate an image by URL using a pre-configured workflow.
+ /// Workflows define custom rules and actions from the dashboard. + ///
+ /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> CheckWorkflowByUrlAsResponseAsync( + string url, + string workflow, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( client: HttpClient); @@ -88,12 +113,13 @@ partial void ProcessCheckWorkflowByUrlResponseContent( global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Sightengine.PathBuilder( path: "/check-workflow.json", - baseUri: HttpClient.BaseAddress); + baseUri: HttpClient.BaseAddress); __pathBuilder .AddRequiredParameter("url", url) - .AddRequiredParameter("workflow", workflow) + .AddRequiredParameter("workflow", workflow) ; var __path = __pathBuilder.ToString(); __path = global::Sightengine.AutoSDKRequestOptionsSupport.AppendQueryParameters( @@ -166,6 +192,8 @@ partial void ProcessCheckWorkflowByUrlResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -176,6 +204,11 @@ partial void ProcessCheckWorkflowByUrlResponseContent( } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -193,6 +226,8 @@ partial void ProcessCheckWorkflowByUrlResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -202,8 +237,7 @@ partial void ProcessCheckWorkflowByUrlResponseContent( __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -212,6 +246,11 @@ partial void ProcessCheckWorkflowByUrlResponseContent( __attempt < __maxAttempts && global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -228,14 +267,15 @@ partial void ProcessCheckWorkflowByUrlResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -275,6 +315,8 @@ partial void ProcessCheckWorkflowByUrlResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -295,6 +337,8 @@ partial void ProcessCheckWorkflowByUrlResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Bad request. @@ -395,9 +439,13 @@ partial void ProcessCheckWorkflowByUrlResponseContent( { __response.EnsureSuccessStatusCode(); - return - global::Sightengine.WorkflowCheckResponse.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Sightengine.WorkflowCheckResponse.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -425,9 +473,13 @@ partial void ProcessCheckWorkflowByUrlResponseContent( #endif ).ConfigureAwait(false); - return - await global::Sightengine.WorkflowCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Sightengine.WorkflowCheckResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { diff --git a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.SubmitFeedback.g.cs b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.SubmitFeedback.g.cs index 6493f78..522e5a1 100644 --- a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.SubmitFeedback.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.SubmitFeedback.g.cs @@ -53,6 +53,31 @@ partial void ProcessSubmitFeedbackResponseContent( /// public async global::System.Threading.Tasks.Task SubmitFeedbackAsync( + global::Sightengine.SubmitFeedbackRequest request, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await SubmitFeedbackAsResponseAsync( + + request: request, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Submit Feedback
+ /// Submit moderation feedback to improve model accuracy.
+ /// Feedback submissions are free and do not count as operations.
+ /// The image is used to continuously improve the specified model. + ///
+ /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> SubmitFeedbackAsResponseAsync( + global::Sightengine.SubmitFeedbackRequest request, global::Sightengine.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) @@ -83,10 +108,11 @@ partial void ProcessSubmitFeedbackResponseContent( var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( clientOptions: Options, requestOptions: requestOptions, - supportsRetry: true); + supportsRetry: false); global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Sightengine.PathBuilder( path: "/feedback.json", baseUri: HttpClient.BaseAddress); @@ -119,6 +145,7 @@ partial void ProcessSubmitFeedbackResponseContent( __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); } } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); if (request.Url != default) { @@ -126,7 +153,8 @@ partial void ProcessSubmitFeedbackResponseContent( __httpRequestContent.Add( content: new global::System.Net.Http.StringContent(request.Url ?? string.Empty), name: "\"url\""); - } + + } if (request.Media != default) { @@ -167,14 +195,18 @@ request.Medianame is null { __contentMedia.Headers.ContentDisposition.FileNameStar = null; } + } __httpRequestContent.Add( content: new global::System.Net.Http.StringContent(request.Model ?? string.Empty), name: "\"model\""); + __httpRequestContent.Add( content: new global::System.Net.Http.StringContent(request.Class ?? string.Empty), name: "\"class\""); + __httpRequest.Content = __httpRequestContent; + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( request: __httpRequest, clientHeaders: Options.Headers, @@ -216,6 +248,8 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -226,6 +260,11 @@ request.Medianame is null } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -243,6 +282,8 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -252,8 +293,7 @@ request.Medianame is null __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -262,6 +302,11 @@ request.Medianame is null __attempt < __maxAttempts && global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -278,14 +323,15 @@ request.Medianame is null attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -325,6 +371,8 @@ request.Medianame is null attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -345,6 +393,8 @@ request.Medianame is null attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Bad request. @@ -445,9 +495,13 @@ request.Medianame is null { __response.EnsureSuccessStatusCode(); - return - global::Sightengine.FeedbackResponse.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Sightengine.FeedbackResponse.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -475,9 +529,13 @@ request.Medianame is null #endif ).ConfigureAwait(false); - return - await global::Sightengine.FeedbackResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Sightengine.FeedbackResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -564,5 +622,1064 @@ request.Medianame is null requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } + + /// + /// Submit Feedback
+ /// Submit moderation feedback to improve model accuracy.
+ /// Feedback submissions are free and do not count as operations.
+ /// The image is used to continuously improve the specified model. + ///
+ /// + /// Public URL to the image (use this OR media). + /// + /// + /// The image file (use this OR url). + /// + /// + /// The image file (use this OR url). + /// + /// + /// The model that classified the image.
+ /// Available: nudity, gore, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam, genai. + /// + /// + /// The expected/correct classification result. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task SubmitFeedbackAsync( + string model, + string @class, + string? url = default, + global::System.IO.Stream? media = default, + string? medianame = default, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + + var request = new global::Sightengine.SubmitFeedbackRequest + { + Url = url, + Media = global::System.Array.Empty(), + Medianame = medianame, + Model = model, + Class = @class, + }; + PrepareArguments( + client: HttpClient); + PrepareSubmitFeedbackArguments( + httpClient: HttpClient, + request: request); + + + var __authorizations = global::Sightengine.EndPointSecurityResolver.ResolveAuthorizations( + availableAuthorizations: Authorizations, + securityRequirements: s_SubmitFeedbackSecurityRequirements, + operationName: "SubmitFeedbackAsync"); + + using var __timeoutCancellationTokenSource = global::Sightengine.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Sightengine.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: false); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + + var __pathBuilder = new global::Sightengine.PathBuilder( + path: "/feedback.json", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Sightengine.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); +#if NET6_0_OR_GREATER + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; +#endif + + foreach (var __authorization in __authorizations) + { + if (__authorization.Type == "Http" || + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") + { + __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( + scheme: __authorization.Name, + parameter: __authorization.Value); + } + else if (__authorization.Type == "ApiKey" && + __authorization.Location == "Header") + { + __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); + } + } + + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (request.Url != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Url ?? string.Empty), + name: "\"url\""); + + } + if (media != default) + { + + var __contentMedia = new global::System.Net.Http.StreamContent(media); + __contentMedia.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue( + request.Medianame is null + ? "application/octet-stream" + : (global::System.IO.Path.GetExtension(request.Medianame) ?? string.Empty).ToLowerInvariant() switch + { + ".aac" => "audio/aac", + ".flac" => "audio/flac", + ".gif" => "image/gif", + ".jpeg" => "image/jpeg", + ".jpg" => "image/jpeg", + ".json" => "application/json", + ".m4a" => "audio/mp4", + ".mp3" => "audio/mpeg", + ".mp4" => "video/mp4", + ".mpeg" => "audio/mpeg", + ".mpga" => "audio/mpeg", + ".oga" => "audio/ogg", + ".ogg" => "audio/ogg", + ".opus" => "audio/ogg", + ".pdf" => "application/pdf", + ".png" => "image/png", + ".txt" => "text/plain", + ".wav" => "audio/wav", + ".weba" => "audio/webm", + ".webm" => "video/webm", + ".webp" => "image/webp", + _ => "application/octet-stream", + }); + __httpRequestContent.Add( + content: __contentMedia, + name: "\"media\"", + fileName: request.Medianame != null ? $"\"{request.Medianame}\"" : string.Empty); + if (__contentMedia.Headers.ContentDisposition != null) + { + __contentMedia.Headers.ContentDisposition.FileNameStar = null; + } + + } + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Model ?? string.Empty), + name: "\"model\""); + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Class ?? string.Empty), + name: "\"class\""); + + __httpRequest.Content = __httpRequestContent; + + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareSubmitFeedbackRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); + + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try + { + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SubmitFeedback", + methodName: "SubmitFeedbackAsync", + pathTemplate: "\"/feedback.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try + { + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + } + catch (global::System.Net.Http.HttpRequestException __exception) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SubmitFeedback", + methodName: "SubmitFeedbackAsync", + pathTemplate: "\"/feedback.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + if (__response != null && + __attempt < __maxAttempts && + global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SubmitFeedback", + methodName: "SubmitFeedbackAsync", + pathTemplate: "\"/feedback.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + break; + } + + if (__response == null) + { + throw new global::System.InvalidOperationException("No response received."); + } + + using (__response) + { + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessSubmitFeedbackResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SubmitFeedback", + methodName: "SubmitFeedbackAsync", + pathTemplate: "\"/feedback.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SubmitFeedback", + methodName: "SubmitFeedbackAsync", + pathTemplate: "\"/feedback.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad request. + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Sightengine.ErrorResponse? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized. + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Sightengine.ErrorResponse? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessSubmitFeedbackResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Sightengine.FeedbackResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Sightengine.FeedbackResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + + } + } + finally + { + __httpRequest?.Dispose(); + } + } + /// + /// Submit Feedback
+ /// Submit moderation feedback to improve model accuracy.
+ /// Feedback submissions are free and do not count as operations.
+ /// The image is used to continuously improve the specified model. + ///
+ /// + /// Public URL to the image (use this OR media). + /// + /// + /// The image file (use this OR url). + /// + /// + /// The image file (use this OR url). + /// + /// + /// The model that classified the image.
+ /// Available: nudity, gore, weapon, drugs, violence,
+ /// alcohol, offensive, self-harm, scam, genai. + /// + /// + /// The expected/correct classification result. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> SubmitFeedbackAsResponseAsync( + string model, + string @class, + string? url = default, + global::System.IO.Stream? media = default, + string? medianame = default, + global::Sightengine.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + + var request = new global::Sightengine.SubmitFeedbackRequest + { + Url = url, + Media = global::System.Array.Empty(), + Medianame = medianame, + Model = model, + Class = @class, + }; + PrepareArguments( + client: HttpClient); + PrepareSubmitFeedbackArguments( + httpClient: HttpClient, + request: request); + + + var __authorizations = global::Sightengine.EndPointSecurityResolver.ResolveAuthorizations( + availableAuthorizations: Authorizations, + securityRequirements: s_SubmitFeedbackSecurityRequirements, + operationName: "SubmitFeedbackAsync"); + + using var __timeoutCancellationTokenSource = global::Sightengine.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Sightengine.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Sightengine.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: false); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + + var __pathBuilder = new global::Sightengine.PathBuilder( + path: "/feedback.json", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Sightengine.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); +#if NET6_0_OR_GREATER + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; +#endif + + foreach (var __authorization in __authorizations) + { + if (__authorization.Type == "Http" || + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") + { + __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( + scheme: __authorization.Name, + parameter: __authorization.Value); + } + else if (__authorization.Type == "ApiKey" && + __authorization.Location == "Header") + { + __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); + } + } + + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (request.Url != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Url ?? string.Empty), + name: "\"url\""); + + } + if (media != default) + { + + var __contentMedia = new global::System.Net.Http.StreamContent(media); + __contentMedia.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue( + request.Medianame is null + ? "application/octet-stream" + : (global::System.IO.Path.GetExtension(request.Medianame) ?? string.Empty).ToLowerInvariant() switch + { + ".aac" => "audio/aac", + ".flac" => "audio/flac", + ".gif" => "image/gif", + ".jpeg" => "image/jpeg", + ".jpg" => "image/jpeg", + ".json" => "application/json", + ".m4a" => "audio/mp4", + ".mp3" => "audio/mpeg", + ".mp4" => "video/mp4", + ".mpeg" => "audio/mpeg", + ".mpga" => "audio/mpeg", + ".oga" => "audio/ogg", + ".ogg" => "audio/ogg", + ".opus" => "audio/ogg", + ".pdf" => "application/pdf", + ".png" => "image/png", + ".txt" => "text/plain", + ".wav" => "audio/wav", + ".weba" => "audio/webm", + ".webm" => "video/webm", + ".webp" => "image/webp", + _ => "application/octet-stream", + }); + __httpRequestContent.Add( + content: __contentMedia, + name: "\"media\"", + fileName: request.Medianame != null ? $"\"{request.Medianame}\"" : string.Empty); + if (__contentMedia.Headers.ContentDisposition != null) + { + __contentMedia.Headers.ContentDisposition.FileNameStar = null; + } + + } + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Model ?? string.Empty), + name: "\"model\""); + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent(request.Class ?? string.Empty), + name: "\"class\""); + + __httpRequest.Content = __httpRequestContent; + + global::Sightengine.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareSubmitFeedbackRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); + + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try + { + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SubmitFeedback", + methodName: "SubmitFeedbackAsync", + pathTemplate: "\"/feedback.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try + { + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + } + catch (global::System.Net.Http.HttpRequestException __exception) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SubmitFeedback", + methodName: "SubmitFeedbackAsync", + pathTemplate: "\"/feedback.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + if (__response != null && + __attempt < __maxAttempts && + global::Sightengine.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) + { + var __retryDelay = global::Sightengine.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SubmitFeedback", + methodName: "SubmitFeedbackAsync", + pathTemplate: "\"/feedback.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Sightengine.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + break; + } + + if (__response == null) + { + throw new global::System.InvalidOperationException("No response received."); + } + + using (__response) + { + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessSubmitFeedbackResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SubmitFeedback", + methodName: "SubmitFeedbackAsync", + pathTemplate: "\"/feedback.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Sightengine.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Sightengine.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SubmitFeedback", + methodName: "SubmitFeedbackAsync", + pathTemplate: "\"/feedback.json\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad request. + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Sightengine.ErrorResponse? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Sightengine.ErrorResponse.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized. + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Sightengine.ErrorResponse? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Sightengine.ErrorResponse.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Sightengine.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessSubmitFeedbackResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Sightengine.FeedbackResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Sightengine.FeedbackResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Sightengine.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Sightengine.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Sightengine.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + + } + } + finally + { + __httpRequest?.Dispose(); + } + } } } \ No newline at end of file diff --git a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.g.cs b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.g.cs index de50c76..d00b368 100644 --- a/src/libs/Sightengine/Generated/Sightengine.SightengineClient.g.cs +++ b/src/libs/Sightengine/Generated/Sightengine.SightengineClient.g.cs @@ -76,10 +76,10 @@ public SightengineClient( /// Client-wide request defaults such as headers, query parameters, retries, and timeout. /// Dispose the HttpClient when the instance is disposed. True by default. public SightengineClient( - global::System.Net.Http.HttpClient? httpClient = null, - global::System.Uri? baseUri = null, - global::System.Collections.Generic.List? authorizations = null, - global::Sightengine.AutoSDKClientOptions? options = null, + global::System.Net.Http.HttpClient? httpClient, + global::System.Uri? baseUri, + global::System.Collections.Generic.List? authorizations, + global::Sightengine.AutoSDKClientOptions? options, bool disposeHttpClient = true) {