apply api changes

This commit is contained in:
Lightczx
2023-12-06 15:45:30 +08:00
parent a97aa26d79
commit 97842559d7
2 changed files with 11 additions and 6 deletions

View File

@@ -24,6 +24,7 @@ using Snap.Hutao.Service.User;
using Snap.Hutao.View.Dialog;
using Snap.Hutao.ViewModel.Guide;
using Snap.Hutao.Web.Hutao;
using Snap.Hutao.Web.Response;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
@@ -105,10 +106,13 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
protected override async ValueTask<bool> InitializeUIAsync()
{
IPInformation? information = await hutaoInfrastructureClient.GetIPInformationAsync().ConfigureAwait(false);
Response<IPInformation> resp = await hutaoInfrastructureClient.GetIPInformationAsync().ConfigureAwait(false);
await taskContext.SwitchToMainThreadAsync();
IPInformation = information;
if (resp.IsOk())
{
await taskContext.SwitchToMainThreadAsync();
IPInformation = resp.Data;
}
return true;
}

View File

@@ -5,6 +5,7 @@ using Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient;
using Snap.Hutao.Service.Hutao;
using Snap.Hutao.Web.Request.Builder;
using Snap.Hutao.Web.Request.Builder.Abstraction;
using Snap.Hutao.Web.Response;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
@@ -19,13 +20,13 @@ internal sealed partial class HutaoInfrastructureClient
private readonly ILogger<HutaoInfrastructureClient> logger;
private readonly HttpClient httpClient;
public async ValueTask<IPInformation> GetIPInformationAsync(CancellationToken token = default)
public async ValueTask<Response<IPInformation>> GetIPInformationAsync(CancellationToken token = default)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(HutaoEndpoints.Ip)
.Get();
IPInformation? resp = await builder.TryCatchSendAsync<IPInformation>(httpClient, logger, token).ConfigureAwait(false);
return resp ?? IPInformation.Default;
Response<IPInformation>? resp = await builder.TryCatchSendAsync<Response<IPInformation>>(httpClient, logger, token).ConfigureAwait(false);
return Response.Response.DefaultIfNull(resp);
}
}