Add GetAssetReleaseDetails capability to asset library extension to HttpClientHelper

This commit is contained in:
Florian Hopfner 2024-01-30 18:42:54 +01:00
Родитель 82c1c8af29
Коммит 2424b8c51e
1 изменённых файлов: 34 добавлений и 0 удалений

Просмотреть файл

@ -23,6 +23,13 @@ internal static class HttpClientHelperAssetLibraryExtension
return $"{httpClientHelper.LcsUrl}/FileAsset/GetFileAssetVersions";
}
internal static string GetDownloadReleaseDetailsForAssetUrl(
this HttpClientHelper httpClientHelper,
string releaseDetailsLink)
{
return $"{httpClientHelper.LcsUrl}{releaseDetailsLink}&_={DateTimeOffset.Now.ToUnixTimeSeconds()}";
}
internal static List<Asset> GetSharedAssetList(
this HttpClientHelper httpClientHelper,
AssetFileType assetFileType)
@ -72,4 +79,31 @@ internal static class HttpClientHelperAssetLibraryExtension
return assetVersionList;
}
internal static string GetAssetReleaseDetails(
this HttpClientHelper httpClientHelper,
string releaseDetailsLink)
{
if (string.IsNullOrEmpty(releaseDetailsLink))
{
return string.Empty;
}
var url = httpClientHelper.GetDownloadReleaseDetailsForAssetUrl(releaseDetailsLink);
var result = httpClientHelper.GetHttpClient().GetAsync(url).Result;
result.EnsureSuccessStatusCode();
var responseBody = result.Content.ReadAsStringAsync().Result;
var response = JsonConvert.DeserializeObject<Response>(responseBody);
if (response.Success
&& response.Data != null
&& response.Data is JToken responseData)
{
var releaseNotesLink = responseData["RedirectLink"].ToString();
var releaseNotes = httpClientHelper.GetHttpClient().GetAsync(releaseNotesLink).Result;
return releaseNotes.Content.ReadAsStringAsync().Result;
}
return string.Empty;
}
}