Skip to content

Commit 937d96c

Browse files
authored
Improve queries to Cloudsmith API (#120)
1 parent 01e011d commit 937d96c

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

nanoFirmwareFlasher/FirmwarePackage.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ namespace nanoFramework.Tools.FirmwareFlasher
2020
internal abstract class FirmwarePackage : IDisposable
2121
{
2222
// HttpClient is intended to be instantiated once per application, rather than per-use.
23-
static readonly HttpClient _cloudsmithClient = new();
24-
25-
/// <summary>
26-
/// Uri of Cloudsmith API
27-
/// </summary>
28-
private const string _cloudsmithPackages = "https://api.cloudsmith.io/v1/packages/net-nanoframework";
23+
static readonly HttpClient _cloudsmithClient;
2924

3025
private const string _refTargetsDevRepo = "nanoframework-images-dev";
3126
private const string _refTargetsStableRepo = "nanoframework-images";
@@ -63,6 +58,13 @@ public static string LocationPathBase
6358

6459
public VerbosityLevel Verbosity { get; internal set; }
6560

61+
static FirmwarePackage()
62+
{
63+
_cloudsmithClient = new HttpClient();
64+
_cloudsmithClient.BaseAddress = new Uri("https://api.cloudsmith.io/v1/packages/net-nanoframework/");
65+
_cloudsmithClient.DefaultRequestHeaders.Add("Accept", "*/*");
66+
}
67+
6668
/// <summary>
6769
/// Constructor
6870
/// </summary>
@@ -92,7 +94,11 @@ public static List<CloudSmithPackageDetail> GetTargetList(
9294
VerbosityLevel verbosity)
9395
{
9496
string repoName = communityTargets ? _communityTargetsRepo : preview ? _refTargetsDevRepo : _refTargetsStableRepo;
95-
string requestUri = $"{_cloudsmithPackages}/{repoName}/?&q=uploaded:>'2 months ago'&tag={platform}";
97+
98+
// NOTE: the query seems to be the oposite, it should be LESS THAN.
99+
// this has been reported to Cloudsmith and it's being checked. Maybe need to revisit this if changes are made in their API.
100+
string requestUri = $"{repoName}/?page_size=500&q=uploaded:'>1 month ago' AND tag:{platform}";
101+
96102
List<CloudSmithPackageDetail> targetPackages = new();
97103

98104
if (verbosity > VerbosityLevel.Normal)
@@ -145,17 +151,14 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()
145151
{
146152
string fwFileName = null;
147153

148-
// query URL
149-
// https://api.cloudsmith.io/v1/packages/net-nanoframework/REPO-NAME-HERE/?page=1&query=/PACKAGE-NAME-HERE latest
150-
151-
// download URL
152-
// https://dl.cloudsmith.io/public/net-nanoframework/REPO-NAME-HERE/raw/names/PACKAGE-NAME-HERE/versions/VERSION-HERE/ST_STM32F429I_DISCOVERY-1.6.2-preview.9.zip
153-
154154
// reference targets
155155
var repoName = _preview ? _refTargetsDevRepo : _refTargetsStableRepo;
156+
156157
// get the firmware version if it is defined
157158
var fwVersion = string.IsNullOrEmpty(_fwVersion) ? "latest" : _fwVersion;
158-
string requestUri = $"{_cloudsmithPackages}/{repoName}/?page=1&query=^{_targetName}$ {fwVersion}";
159+
160+
// compose query
161+
string requestUri = $"{repoName}/?query=name:{_targetName} version:^{fwVersion}$";
159162

160163
string downloadUrl = string.Empty;
161164

0 commit comments

Comments
 (0)