Add asset library extension to HttpClientHelper

This commit is contained in:
Florian Hopfner 2024-01-28 19:01:42 +01:00
Родитель 5427317f2b
Коммит c4536f069a
1 изменённых файлов: 40 добавлений и 0 удалений

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

@ -0,0 +1,40 @@
using LCS.JsonObjects;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
namespace LCS.AssetLibrary;
internal static class HttpClientHelperAssetLibraryExtension
{
internal static string GetGetSharedAssetsUrl(this HttpClientHelper httpClientHelper,
AssetFileType assetFileType)
{
return $"{httpClientHelper.LcsUrl}/FileAsset/GetSharedAssets/?assetKind={((int)assetFileType)}&_={DateTimeOffset.Now.ToUnixTimeSeconds()}";
}
internal static List<Asset> GetSharedAssetList(this HttpClientHelper httpClientHelper,
AssetFileType assetFileType)
{
var assetList = new List<Asset>();
var url = httpClientHelper.GetGetSharedAssetsUrl(assetFileType);
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)
{
var responseData = response.Data as JToken;
if (responseData != null)
{
var assetData = responseData[0].ToObject<AssetData>();
assetList = assetData.Assets;
}
}
return assetList;
}
}