-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathHttpDownloadSource.cs
More file actions
87 lines (77 loc) · 2.65 KB
/
Copy pathHttpDownloadSource.cs
File metadata and controls
87 lines (77 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using GeneralUpdate.Core.Configuration;
using GeneralUpdate.Core.Download.Models;
using GeneralUpdate.Core.Network;
namespace GeneralUpdate.Core.Download.Sources;
/// <summary>
/// HTTP download source — calls the version validation API
/// and converts the server response to a list of DownloadAssets.
/// </summary>
public class HttpDownloadSource : Abstractions.IDownloadSource
{
private readonly string _updateUrl;
private readonly string _clientVersion;
private readonly string? _upgradeClientVersion;
private readonly string _appSecretKey;
private readonly int _platform;
private readonly string? _productId;
private readonly string? _scheme;
private readonly string? _token;
public HttpDownloadSource(
string updateUrl,
string clientVersion,
string? upgradeClientVersion,
string appSecretKey,
int platform,
string? productId,
string? scheme,
string? token)
{
_updateUrl = updateUrl;
_clientVersion = clientVersion;
_upgradeClientVersion = upgradeClientVersion;
_appSecretKey = appSecretKey;
_platform = platform;
_productId = productId;
_scheme = scheme;
_token = token;
}
/// <summary>Call version API and return download assets.</summary>
public async Task<IReadOnlyList<DownloadAsset>> ListAsync(CancellationToken token = default)
{
var mainResp = await VersionService.Validate(
_updateUrl, _clientVersion, AppType.ClientApp,
_appSecretKey, _platform, _productId,
_scheme, _token, token);
var upgradeResp = await VersionService.Validate(
_updateUrl, _upgradeClientVersion ?? _clientVersion, AppType.UpgradeApp,
_appSecretKey, _platform, _productId,
_scheme, _token, token);
var assets = new List<DownloadAsset>();
if (mainResp?.Body != null)
{
foreach (var v in mainResp.Body)
assets.Add(MapVersionInfo(v));
}
if (upgradeResp?.Body != null)
{
foreach (var v in upgradeResp.Body)
assets.Add(MapVersionInfo(v));
}
return assets;
}
private static DownloadAsset MapVersionInfo(VersionInfo v)
{
return new DownloadAsset(
Name: v.Name ?? v.Version ?? "unknown",
Url: v.Url ?? string.Empty,
Size: v.Size ?? 0,
SHA256: v.Hash,
Version: v.Version ?? "0.0.0",
IsForcibly: v.IsForcibly == true
);
}
}