mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
apply hutao api changes
This commit is contained in:
@@ -2828,6 +2828,9 @@
|
||||
<data name="WebHoyolabInvalidUid" xml:space="preserve">
|
||||
<value>无效的 UID</value>
|
||||
</data>
|
||||
<data name="WebHutaoServiceUnAvailable" xml:space="preserve">
|
||||
<value>胡桃服务维护中</value>
|
||||
</data>
|
||||
<data name="WebIndexOrSpiralAbyssVerificationFailed" xml:space="preserve">
|
||||
<value>验证失败,请手动验证或前往「米游社-我的角色」页面查看</value>
|
||||
</data>
|
||||
|
||||
@@ -107,12 +107,19 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel
|
||||
protected override async ValueTask<bool> InitializeUIAsync()
|
||||
{
|
||||
Response<IPInformation> resp = await hutaoInfrastructureClient.GetIPInformationAsync().ConfigureAwait(false);
|
||||
IPInformation info;
|
||||
|
||||
if (resp.IsOk())
|
||||
{
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
IPInformation = resp.Data;
|
||||
info = resp.Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
info = IPInformation.Default;
|
||||
}
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
IPInformation = info;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ namespace Snap.Hutao.Web.Hutao;
|
||||
|
||||
internal sealed class IPInformation
|
||||
{
|
||||
private const string Unknown = "Unknown";
|
||||
|
||||
public static IPInformation Default { get; } = new()
|
||||
{
|
||||
Ip = "Unknown",
|
||||
Division = "Unknown",
|
||||
Ip = Unknown,
|
||||
Division = Unknown,
|
||||
};
|
||||
|
||||
[JsonPropertyName("ip")]
|
||||
@@ -19,6 +21,11 @@ internal sealed class IPInformation
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (Ip is Unknown && Division is Unknown)
|
||||
{
|
||||
return SH.WebHutaoServiceUnAvailable;
|
||||
}
|
||||
|
||||
return SH.FormatViewPageSettingDeviceIpDescription(Ip, Division);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Web.Hutao;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Sockets;
|
||||
|
||||
@@ -12,6 +14,7 @@ internal static class HttpRequestMessageBuilderExtension
|
||||
private const string RequestErrorMessage = "请求异常已忽略";
|
||||
|
||||
internal static async ValueTask<TResult?> TryCatchSendAsync<TResult>(this HttpRequestMessageBuilder builder, HttpClient httpClient, ILogger logger, CancellationToken token)
|
||||
where TResult : class
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -26,6 +29,22 @@ internal static class HttpRequestMessageBuilderExtension
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
logger.LogWarning(ex, RequestErrorMessage);
|
||||
|
||||
if (ex.StatusCode is HttpStatusCode.BadGateway)
|
||||
{
|
||||
Type resultType = typeof(TResult);
|
||||
|
||||
if (resultType == typeof(HutaoResponse))
|
||||
{
|
||||
return Activator.CreateInstance(resultType, 502, SH.WebHutaoServiceUnAvailable, default) as TResult;
|
||||
}
|
||||
|
||||
if (resultType.IsConstructedGenericType && resultType.GetGenericTypeDefinition() == typeof(HutaoResponse<>))
|
||||
{
|
||||
return Activator.CreateInstance(resultType, 502, SH.WebHutaoServiceUnAvailable, default, default) as TResult;
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
catch (IOException ex)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Web.Request.Builder;
|
||||
|
||||
internal enum HttpTryCatchSendStrategy
|
||||
{
|
||||
Default,
|
||||
HutaoApi,
|
||||
}
|
||||
Reference in New Issue
Block a user