mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-22 12:41:14 +00:00
[AZ-374] Refactor C21: named GoogleMapsTiles HttpClient in DI
- Register IHttpClientFactory named client "GoogleMapsTiles" inside AddTileDownloader() with User-Agent and 100s timeout (preserves HttpClient's implicit default). - Resolve the same named client from all three CreateClient() call sites in GoogleMapsDownloaderV2 (session token, single-tile, batch-tile retry lambda) and drop the duplicated per-call UserAgent.ParseAdd setup. - Expose USER_AGENT, the client name, and the timeout as internal consts on GoogleMapsDownloaderV2 so the extension and the downloader share one source of truth. - Add AC test that builds the DI container, resolves the named client, and asserts both the User-Agent header and the timeout. - Archive AZ-374 task file: todo/ -> done/. 175 unit + 5 smoke pass. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -14,7 +14,9 @@ namespace SatelliteProvider.Services.TileDownloader;
|
||||
public class GoogleMapsDownloaderV2 : ISatelliteDownloader
|
||||
{
|
||||
private const string TILE_URL_TEMPLATE = "https://mt{0}.google.com/vt/lyrs=s&x={1}&y={2}&z={3}&token={4}";
|
||||
private const string USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36";
|
||||
internal const string UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36";
|
||||
internal const string GoogleMapsTilesClientName = "GoogleMapsTiles";
|
||||
internal const int DefaultHttpClientTimeoutSeconds = 100;
|
||||
|
||||
private readonly ILogger<GoogleMapsDownloaderV2> _logger;
|
||||
private readonly string _apiKey;
|
||||
@@ -46,7 +48,7 @@ public class GoogleMapsDownloaderV2 : ISatelliteDownloader
|
||||
private async Task<string?> GetSessionToken()
|
||||
{
|
||||
var url = $"https://tile.googleapis.com/v1/createSession?key={_apiKey}";
|
||||
using var httpClient = _httpClientFactory.CreateClient();
|
||||
using var httpClient = _httpClientFactory.CreateClient(GoogleMapsTilesClientName);
|
||||
try
|
||||
{
|
||||
var str = JsonConvert.SerializeObject(new { mapType = "satellite" });
|
||||
@@ -102,8 +104,7 @@ public class GoogleMapsDownloaderV2 : ISatelliteDownloader
|
||||
|
||||
var imageBytes = await ExecuteWithRetryAsync(async () =>
|
||||
{
|
||||
using var httpClient = _httpClientFactory.CreateClient();
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(USER_AGENT);
|
||||
using var httpClient = _httpClientFactory.CreateClient(GoogleMapsTilesClientName);
|
||||
|
||||
var response = await httpClient.GetAsync(url, token);
|
||||
|
||||
@@ -366,8 +367,7 @@ public class GoogleMapsDownloaderV2 : ISatelliteDownloader
|
||||
|
||||
var imageBytes = await ExecuteWithRetryAsync(async () =>
|
||||
{
|
||||
using var httpClient = _httpClientFactory.CreateClient();
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(USER_AGENT);
|
||||
using var httpClient = _httpClientFactory.CreateClient(GoogleMapsTilesClientName);
|
||||
|
||||
var response = await httpClient.GetAsync(url, token);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user