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
httpClientFactoryIHttpClientFactoryThe HTTP client factory.
hashingServiceIFileHashingServiceThe file hashing service.
imageOptionsIOptionsMonitor<ImageDownloadOptions>The image download options.
modelOptionsIOptionsMonitor<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
imageImageThe image to download.
baseDirectorystringThe base directory to save the image to.
cancellationTokenCancellationTokenCancellation 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
imageImageThe image to download.
cancellationTokenCancellationTokenCancellation 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
fileModelFileThe model file to download.
versionModelVersionThe model version providing additional context.
baseDirectorystringThe base directory to save the file to.
cancellationTokenCancellationTokenCancellation 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
fileModelFileThe model file to download.
versionModelVersionThe model version providing additional context.
cancellationTokenCancellationTokenCancellation 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
fileModelFileThe model file to download.
baseDirectorystringThe base directory to save the file to.
cancellationTokenCancellationTokenCancellation 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
fileModelFileThe model file to download.
cancellationTokenCancellationTokenCancellation 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
urlstringThe URL to download from.
destinationPathstringThe full path where the file will be saved.
expectedHashstringThe expected hash value for verification.
algorithmHashAlgorithmThe hash algorithm to use for verification.
cancellationTokenCancellationTokenCancellation 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
urlstringThe URL to download from.
destinationPathstringThe full path where the file will be saved.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<Result<DownloadedFile>>
A result containing the downloaded file information on success.