|
12 | 12 | // Configure configuration |
13 | 13 | builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); |
14 | 14 |
|
15 | | -// Add HTTP client |
16 | | -builder.Services.AddHttpClient("UpdateService", (sp, client) => |
| 15 | +// Add HTTP client for ClientPortal.Api (releases list) |
| 16 | +builder.Services.AddHttpClient("ClientPortalApi", (sp, client) => |
17 | 17 | { |
18 | 18 | var config = sp.GetRequiredService<IConfiguration>(); |
19 | | - var baseUrl = config["UpdateAgent:ApiBaseUrl"] ?? throw new Exception("ApiBaseUrl not configured"); |
| 19 | + var baseUrl = config["UpdateAgent:ClientPortalApiUrl"] ?? throw new Exception("ClientPortalApiUrl not configured"); |
20 | 20 | var apiKey = config["UpdateAgent:DeviceApiKey"] ?? throw new Exception("DeviceApiKey not configured"); |
21 | 21 |
|
22 | 22 | client.BaseAddress = new Uri(baseUrl); |
23 | 23 | client.DefaultRequestHeaders.Add("X-API-Key", apiKey); |
24 | | - client.Timeout = TimeSpan.FromMinutes(10); // Long timeout for large file downloads |
| 24 | + client.Timeout = TimeSpan.FromMinutes(1); |
25 | 25 | }) |
26 | 26 | .ConfigurePrimaryHttpMessageHandler(() => |
27 | 27 | { |
28 | 28 | var handler = new HttpClientHandler(); |
29 | | - |
30 | | - // In development, allow untrusted certificates (self-signed certs) |
31 | 29 | if (builder.Environment.IsDevelopment()) |
32 | 30 | { |
33 | 31 | handler.ServerCertificateCustomValidationCallback = |
34 | 32 | HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; |
35 | 33 | } |
| 34 | + return handler; |
| 35 | +}); |
36 | 36 |
|
| 37 | +// Add HTTP client for Admin.Api (file downloads) |
| 38 | +builder.Services.AddHttpClient("AdminApi", (sp, client) => |
| 39 | +{ |
| 40 | + var config = sp.GetRequiredService<IConfiguration>(); |
| 41 | + var baseUrl = config["UpdateAgent:AdminApiUrl"] ?? throw new Exception("AdminApiUrl not configured"); |
| 42 | + |
| 43 | + client.BaseAddress = new Uri(baseUrl); |
| 44 | + client.Timeout = TimeSpan.FromMinutes(10); // Long timeout for large file downloads |
| 45 | +}) |
| 46 | +.ConfigurePrimaryHttpMessageHandler(() => |
| 47 | +{ |
| 48 | + var handler = new HttpClientHandler(); |
| 49 | + if (builder.Environment.IsDevelopment()) |
| 50 | + { |
| 51 | + handler.ServerCertificateCustomValidationCallback = |
| 52 | + HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; |
| 53 | + } |
37 | 54 | return handler; |
38 | 55 | }); |
39 | 56 |
|
@@ -86,9 +103,9 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) |
86 | 103 |
|
87 | 104 | private async Task CheckForUpdatesAsync(CancellationToken cancellationToken) |
88 | 105 | { |
89 | | - var client = _httpClientFactory.CreateClient("UpdateService"); |
| 106 | + var client = _httpClientFactory.CreateClient("ClientPortalApi"); |
90 | 107 |
|
91 | | - // Get active releases (no leading slash - BaseAddress already includes /api) |
| 108 | + // Get active releases from ClientPortal.Api |
92 | 109 | var releases = await client.GetFromJsonAsync<List<ReleaseDto>>("releases/active", cancellationToken); |
93 | 110 |
|
94 | 111 | if (releases == null || releases.Count == 0) |
@@ -143,17 +160,17 @@ private async Task DownloadAndInstallAsync(ReleaseDto release, CancellationToken |
143 | 160 |
|
144 | 161 | try |
145 | 162 | { |
146 | | - var client = _httpClientFactory.CreateClient("UpdateService"); |
| 163 | + var adminClient = _httpClientFactory.CreateClient("AdminApi"); |
147 | 164 |
|
148 | 165 | // Create download directory |
149 | 166 | var downloadDir = _config["UpdateAgent:DownloadDirectory"] ?? "./downloads"; |
150 | 167 | Directory.CreateDirectory(downloadDir); |
151 | 168 |
|
152 | 169 | var filePath = Path.Combine(downloadDir, $"update-{version}.bin"); |
153 | 170 |
|
154 | | - // Download file |
| 171 | + // Download file from Admin.Api |
155 | 172 | _logger.LogInformation("Downloading to {FilePath}...", filePath); |
156 | | - var response = await client.GetAsync($"updates/{updateId}/download", cancellationToken); |
| 173 | + var response = await adminClient.GetAsync($"updates/{updateId}/download", cancellationToken); |
157 | 174 | response.EnsureSuccessStatusCode(); |
158 | 175 |
|
159 | 176 | await using (var fileStream = File.Create(filePath)) |
|
0 commit comments