Skip to content

Commit

Permalink
Merge pull request #19383 from abpframework/auto-merge/rel-8-1/2598
Browse files Browse the repository at this point in the history
Merge branch dev with rel-8.1
  • Loading branch information
maliming authored Mar 22, 2024
2 parents 26ba51e + a59e43c commit de17c3a
Showing 1 changed file with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Newtonsoft.Json;
using System.Collections.Concurrent;
using NuGet.Versioning;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -14,7 +14,7 @@
using Volo.Abp.DependencyInjection;
using Volo.Abp.Json;
using Volo.Abp.Threading;
using System.Net.Mail;
using System.Text.Json.Serialization;

namespace Volo.Abp.Cli.Version;

Expand Down Expand Up @@ -66,7 +66,7 @@ public async Task<LatestVersionInfo> GetLatestVersionOrNullAsync(string packageI
{
return await GetLatestStableVersionFromGithubAsync();
}

var versionList = await GetPackageVersionListAsync(packageId, includeNightly);
if (versionList == null)
{
Expand All @@ -79,8 +79,8 @@ public async Task<LatestVersionInfo> GetLatestVersionOrNullAsync(string packageI
.Select(SemanticVersion.Parse)
.OrderByDescending(v => v, new VersionComparer()).ToList();

return versions.Any()
? new LatestVersionInfo(versions.Max())
return versions.Any()
? new LatestVersionInfo(versions.Max())
: null;

}
Expand All @@ -96,7 +96,7 @@ public async Task<List<string>> GetPackageVersionListAsync(string packageId, boo
{
return await GetPackageVersionsFromAbpCommercialNuGetAsync(packageId);
}

return await GetPackageVersionsFromNuGetOrgAsync(packageId) ?? new List<string>();
}

Expand All @@ -113,21 +113,32 @@ public async Task<LatestVersionInfo> GetLatestStableVersionFromGithubAsync()
: null;
}

private static ConcurrentDictionary<string, bool> CommercialPackagesCache { get; } = new ();

private async Task<bool> IsCommercialPackageAsync(string packageId)
{
if (CommercialPackagesCache.TryGetValue(packageId, out var isCommercial))
{
return isCommercial;
}

if (CommercialPackages.IsCommercial(packageId))
{
CommercialPackagesCache.TryAdd(packageId, true);
return true;
}

await SetApiKeyResultAsync();
if (_apiKeyResult?.ApiKey == null)
{
CommercialPackagesCache.TryAdd(packageId, false);
return false;
}

var searchUrl = CliUrls.GetNuGetPackageSearchUrl(_apiKeyResult.ApiKey, packageId);
return await HasAnyPackageAsync(searchUrl, packageId);
isCommercial = await HasAnyPackageAsync(searchUrl, packageId);
CommercialPackagesCache.TryAdd(packageId, isCommercial);
return isCommercial;
}

private async Task<bool> HasAnyPackageAsync(string url, string packageId)
Expand All @@ -147,7 +158,7 @@ private async Task<bool> HasAnyPackageAsync(string url, string packageId)
var responseContent = await responseMessage.Content.ReadAsStringAsync();
var nugetSearchResult = JsonSerializer.Deserialize<NuGetSearchResultDto>(responseContent);

return nugetSearchResult.TotalHits > 0 && nugetSearchResult.Packages.Any(package => package.Id.ToLowerInvariant() == packageId.ToLowerInvariant());
return nugetSearchResult.TotalHits > 0 && nugetSearchResult.Data.Any(package => package.Id.ToLowerInvariant() == packageId.ToLowerInvariant());
}
}
catch (Exception)
Expand Down Expand Up @@ -191,7 +202,7 @@ private async Task<List<string>> GetPackageVersionListFromUrlAsync(string url)
//the package doesn't exist...
return new List<string>();
}

await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(responseMessage);

var responseContent = await responseMessage.Content.ReadAsStringAsync();
Expand Down Expand Up @@ -231,7 +242,7 @@ private async Task<LatestStableVersionResult> GetLatestStableVersionOrNullAsync(

var content = await responseMessage.Content.ReadAsStringAsync();
var result = JsonSerializer.Deserialize<List<LatestStableVersionResult>>(content);

return result.FirstOrDefault(x => x.Type.ToLowerInvariant() == "stable");
}
}
Expand All @@ -243,25 +254,20 @@ private async Task<LatestStableVersionResult> GetLatestStableVersionOrNullAsync(

public class NuGetSearchResultDto
{
[JsonProperty("totalHits")]
public int TotalHits { get; set; }

[JsonProperty("data")]
public NuGetSearchResultPackagesDto[] Packages { get; set; }
public NuGetSearchResultPackagesDto[] Data { get; set; }
}

public class NuGetSearchResultPackagesDto
public class NuGetSearchResultPackagesDto
{
[JsonProperty("id")]
public string Id { get; set; }

[JsonProperty("version")]
public string Version { get; set; }
}

public class NuGetVersionResultDto
{
[JsonProperty("versions")]
public List<string> Versions { get; set; }
}

Expand All @@ -272,7 +278,7 @@ public class LatestStableVersionResult
public DateTime? ReleaseDate { get; set; }

public string Type { get; set; }

public string Message { get; set; }
}
}

0 comments on commit de17c3a

Please sign in to comment.