Table of Contents

Class DownloadService

Namespace
CivitaiSharp.Tools.Downloads
Assembly
CivitaiSharp.Tools.dll

Default implementation of IDownloadService.

public sealed class DownloadService : IDownloadService
Inheritance
DownloadService
Implements
Inherited Members

Constructors

DownloadService(IHttpClientFactory, IFileHashingService, IOptionsMonitor<ImageDownloadOptions>, IOptionsMonitor<ModelDownloadOptions>)

Initializes a new instance of the DownloadService class.

public DownloadService(IHttpClientFactory httpClientFactory, IFileHashingService hashingService, IOptionsMonitor<ImageDownloadOptions> imageOptions, IOptionsMonitor<ModelDownloadOptions> modelOptions)

Parameters

httpClientFactory IHttpClientFactory

The HTTP client factory.

hashingService IFileHashingService

The file hashing service.

imageOptions IOptionsMonitor<ImageDownloadOptions>

The image download options.

modelOptions IOptionsMonitor<ModelDownloadOptions>

The model download options.

Methods

DownloadAsync(Image, string, CancellationToken)

Downloads an image to a specific base directory, using the configured path pattern.

public Task<Result<DownloadedFile>> DownloadAsync(Image image, string baseDirectory, CancellationToken cancellationToken = default)

Parameters

image Image

The image to download.

baseDirectory string

The base directory to save the image to.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Result<DownloadedFile>>

A result containing the downloaded file information on success.

DownloadAsync(Image, CancellationToken)

Downloads an image using the configured image download options.

public Task<Result<DownloadedFile>> DownloadAsync(Image image, CancellationToken cancellationToken = default)

Parameters

image Image

The image to download.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Result<DownloadedFile>>

A result containing the downloaded file information on success.

DownloadAsync(ModelFile, ModelVersion, string, CancellationToken)

Downloads a model file with version context to a specific base directory.

public Task<Result<DownloadedFile>> DownloadAsync(ModelFile file, ModelVersion version, string baseDirectory, CancellationToken cancellationToken = default)

Parameters

file ModelFile

The model file to download.

version ModelVersion

The model version providing additional context.

baseDirectory string

The base directory to save the file to.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Result<DownloadedFile>>

A result containing the downloaded file information on success.

DownloadAsync(ModelFile, ModelVersion, CancellationToken)

Downloads a model file with version context using the configured model download options.

public Task<Result<DownloadedFile>> DownloadAsync(ModelFile file, ModelVersion version, CancellationToken cancellationToken = default)

Parameters

file ModelFile

The model file to download.

version ModelVersion

The model version providing additional context.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Result<DownloadedFile>>

A result containing the downloaded file information on success.

Remarks

Providing the version context enables additional path pattern tokens such as {VersionName}, {BaseModel}, {ModelName}, {ModelType}, and {Creator}.

DownloadAsync(ModelFile, string, CancellationToken)

Downloads a model file to a specific base directory, using the configured path pattern.

public Task<Result<DownloadedFile>> DownloadAsync(ModelFile file, string baseDirectory, CancellationToken cancellationToken = default)

Parameters

file ModelFile

The model file to download.

baseDirectory string

The base directory to save the file to.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Result<DownloadedFile>>

A result containing the downloaded file information on success.

DownloadAsync(ModelFile, CancellationToken)

Downloads a model file using the configured model download options.

public Task<Result<DownloadedFile>> DownloadAsync(ModelFile file, CancellationToken cancellationToken = default)

Parameters

file ModelFile

The model file to download.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Result<DownloadedFile>>

A result containing the downloaded file information on success.

DownloadAsync(string, string, string, HashAlgorithm, CancellationToken)

Downloads a file from a raw URL with hash verification.

public Task<Result<DownloadedFile>> DownloadAsync(string url, string destinationPath, string expectedHash, HashAlgorithm algorithm, CancellationToken cancellationToken = default)

Parameters

url string

The URL to download from.

destinationPath string

The full path where the file will be saved.

expectedHash string

The expected hash value for verification.

algorithm HashAlgorithm

The hash algorithm to use for verification.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Result<DownloadedFile>>

A result containing the downloaded file information on success.

DownloadAsync(string, string, CancellationToken)

Downloads a file from a raw URL to a specific destination path.

public Task<Result<DownloadedFile>> DownloadAsync(string url, string destinationPath, CancellationToken cancellationToken = default)

Parameters

url string

The URL to download from.

destinationPath string

The full path where the file will be saved.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Result<DownloadedFile>>

A result containing the downloaded file information on success.