tgstation-server 6.17.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Tgstation.Server.Host.IO.FileDownloader Class Referencesealed

More...

Inheritance diagram for Tgstation.Server.Host.IO.FileDownloader:
Inheritance graph
[legend]
Collaboration diagram for Tgstation.Server.Host.IO.FileDownloader:
Collaboration graph
[legend]

Public Member Functions

 FileDownloader (IAbstractHttpClientFactory httpClientFactory, ILogger< FileDownloader > logger)
 Initializes a new instance of the FileDownloader class.
 
IFileStreamProvider DownloadFile (Uri url, string? bearerToken)
 Downloads a file from a given url .
Parameters
urlThe URL to download.
bearerTokenOptional string to use as the "Bearer" value in the optional "Authorization" header for the request.
Returns
A new IFileStreamProvider for the downloaded file.

 

Private Attributes

readonly IAbstractHttpClientFactory httpClientFactory
 The IAbstractHttpClientFactory for the FileDownloader.
 
readonly ILogger< FileDownloaderlogger
 The ILogger for the FileDownloader.
 

Detailed Description

Definition at line 13 of file FileDownloader.cs.

Constructor & Destructor Documentation

◆ FileDownloader()

Tgstation.Server.Host.IO.FileDownloader.FileDownloader ( IAbstractHttpClientFactory  httpClientFactory,
ILogger< FileDownloader logger 
)

Initializes a new instance of the FileDownloader class.

Parameters
httpClientFactoryThe value of httpClientFactory.
loggerThe value of logger.

Definition at line 30 of file FileDownloader.cs.

31 {
32 this.httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
33 this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
34 }
readonly IAbstractHttpClientFactory httpClientFactory
The IAbstractHttpClientFactory for the FileDownloader.
readonly ILogger< FileDownloader > logger
The ILogger for the FileDownloader.

References Tgstation.Server.Host.IO.FileDownloader.httpClientFactory, and Tgstation.Server.Host.IO.FileDownloader.logger.

Member Function Documentation

◆ DownloadFile()

IFileStreamProvider Tgstation.Server.Host.IO.FileDownloader.DownloadFile ( Uri  url,
string?  bearerToken 
)

Downloads a file from a given url .

Parameters
urlThe URL to download.
bearerTokenOptional string to use as the "Bearer" value in the optional "Authorization" header for the request.
Returns
A new IFileStreamProvider for the downloaded file.

Implements Tgstation.Server.Host.IO.IFileDownloader.

Definition at line 37 of file FileDownloader.cs.

38 {
39 ArgumentNullException.ThrowIfNull(url);
40
41 logger.LogDebug("Starting download of {url}...", url);
42 var httpClient = httpClientFactory.CreateClient();
43 try
44 {
45 var request = new HttpRequestMessage(
46 HttpMethod.Get,
47 url);
48 try
49 {
50 if (bearerToken != null)
51 request.Headers.Authorization = new AuthenticationHeaderValue(ApiHeaders.BearerAuthenticationScheme, bearerToken);
52
53 return new RequestFileStreamProvider(httpClient, request);
54 }
55 catch
56 {
57 request.Dispose();
58 throw;
59 }
60 }
61 catch
62 {
63 httpClient.Dispose();
64 throw;
65 }
66 }
Represents the header that must be present for every server request.
Definition ApiHeaders.cs:25
const string BearerAuthenticationScheme
The JWT authentication header scheme.
Definition ApiHeaders.cs:44
IHttpClient CreateClient()
Create a IHttpClient.

References Tgstation.Server.Api.ApiHeaders.BearerAuthenticationScheme, Tgstation.Server.Common.Http.IAbstractHttpClientFactory.CreateClient(), Tgstation.Server.Host.IO.FileDownloader.httpClientFactory, and Tgstation.Server.Host.IO.FileDownloader.logger.

Here is the call graph for this function:

Member Data Documentation

◆ httpClientFactory

readonly IAbstractHttpClientFactory Tgstation.Server.Host.IO.FileDownloader.httpClientFactory
private

The IAbstractHttpClientFactory for the FileDownloader.

Definition at line 18 of file FileDownloader.cs.

Referenced by Tgstation.Server.Host.IO.FileDownloader.DownloadFile(), and Tgstation.Server.Host.IO.FileDownloader.FileDownloader().

◆ logger

readonly ILogger<FileDownloader> Tgstation.Server.Host.IO.FileDownloader.logger
private

The ILogger for the FileDownloader.

Definition at line 23 of file FileDownloader.cs.

Referenced by Tgstation.Server.Host.IO.FileDownloader.DownloadFile(), and Tgstation.Server.Host.IO.FileDownloader.FileDownloader().


The documentation for this class was generated from the following file: