fix up oversea api style

This commit is contained in:
DismissedLight
2023-01-10 15:52:10 +08:00
parent f7bd184a3c
commit a24fbf535d
4 changed files with 50 additions and 44 deletions

View File

@@ -25,6 +25,12 @@ internal class GachaLogUrlWebCacheProvider : IGachaLogUrlProvider
this.gameService = gameService;
}
private enum UrlMatch
{
Chinese,
Oversea,
}
/// <inheritdoc/>
public string Name { get => nameof(GachaLogUrlWebCacheProvider); }
@@ -38,7 +44,7 @@ internal class GachaLogUrlWebCacheProvider : IGachaLogUrlProvider
string folder = Path.GetDirectoryName(path) ?? string.Empty;
string cacheDataPathChinese = Path.Combine(folder, @"YuanShen_Data\webCaches\Cache\Cache_Data\data_2");
string cacheDataPathOversea = Path.Combine(folder, @"GenshinImpact_Data\webCaches\Cache\Cache_Data\data_2");
return File.Exists(cacheDataPathChinese) ? cacheDataPathChinese : cacheDataPathOversea;
}
@@ -63,17 +69,7 @@ internal class GachaLogUrlWebCacheProvider : IGachaLogUrlProvider
using (MemoryStream memoryStream = new())
{
await fileStream.CopyToAsync(memoryStream).ConfigureAwait(false);
string? result = null;
if (tempFile.Path.Contains("YuanShen_Data"))
{
result = Match(memoryStream);
}
else
{
result = MatchIntl(memoryStream);
}
string? result = Match(memoryStream, !tempFile.Path.Contains("GenshinImpact_Data"));
return new(!string.IsNullOrEmpty(result), result!);
}
}
@@ -85,26 +81,12 @@ internal class GachaLogUrlWebCacheProvider : IGachaLogUrlProvider
}
}
private static string? Match(MemoryStream stream)
private static string? Match(MemoryStream stream, bool isOversea)
{
ReadOnlySpan<byte> span = stream.ToArray();
ReadOnlySpan<byte> match = "https://webstatic.mihoyo.com/hk4e/event/e20190909gacha-v2/index.html"u8;
ReadOnlySpan<byte> zero = "\0"u8;
int index = span.LastIndexOf(match);
if (index >= 0)
{
int length = span[index..].IndexOf(zero);
return Encoding.UTF8.GetString(span.Slice(index, length));
}
return null;
}
private static string? MatchIntl(MemoryStream stream)
{
ReadOnlySpan<byte> span = stream.ToArray();
ReadOnlySpan<byte> match = "https://webstatic-sea.hoyoverse.com/genshin/event/e20190909gacha-v2/index.html"u8;
ReadOnlySpan<byte> match = isOversea
? "https://webstatic-sea.hoyoverse.com/genshin/event/e20190909gacha-v2/index.html"u8
: "https://webstatic.mihoyo.com/hk4e/event/e20190909gacha-v2/index.html"u8;
ReadOnlySpan<byte> zero = "\0"u8;
int index = span.LastIndexOf(match);

View File

@@ -7,7 +7,7 @@ using Snap.Hutao.Web.Hoyolab;
namespace Snap.Hutao.Web;
/// <summary>
/// API 端点
/// 国服 API 端点
/// </summary>
[SuppressMessage("", "SA1201")]
[SuppressMessage("", "SA1124")]
@@ -274,14 +274,7 @@ internal static class ApiEndpoints
/// <returns>祈愿记录信息Url</returns>
public static string GachaInfoGetGachaLog(string query)
{
if (query.Contains("mihoyo.com"))
{
return $"{Hk4eApiGachaInfoApi}/getGachaLog?{query}";
}
else
{
return $"{Hk4eIntlApiGachaInfoApi}/getGachaLog?{query}";
}
return $"{Hk4eApiGachaInfoApi}/getGachaLog?{query}";
}
#endregion
@@ -363,10 +356,6 @@ internal static class ApiEndpoints
private const string Hk4eApiAnnouncementApi = $"{Hk4eApi}/common/hk4e_cn/announcement/api";
private const string Hk4eApiGachaInfoApi = $"{Hk4eApi}/event/gacha_info/api";
private const string Hk4eIntlApi = "https://hk4e-api-os.hoyoverse.com";
private const string Hk4eIntlApiAnnouncementApi = $"{Hk4eIntlApi}/common/hk4e_cn/announcement/api";
private const string Hk4eIntlApiGachaInfoApi = $"{Hk4eIntlApi}/event/gacha_info/api";
private const string PassportApi = "https://passport-api.mihoyo.com";
private const string PassportApiAuthApi = $"{PassportApi}/account/auth/api";
private const string PassportApiV4 = "https://passport-api-v4.mihoyo.com";

View File

@@ -0,0 +1,30 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Web;
/// <summary>
/// 国际服 API 端点
/// </summary>
[SuppressMessage("", "SA1201")]
[SuppressMessage("", "SA1124")]
internal static class ApiOsEndpoints
{
#region Hk4eApiOsGachaInfoApi
/// <summary>
/// 获取祈愿记录
/// </summary>
/// <param name="query">query string</param>
/// <returns>祈愿记录信息Url</returns>
public static string GachaInfoGetGachaLog(string query)
{
return $"{Hk4eApiOsGachaInfoApi}/getGachaLog?{query}";
}
#endregion
#region Hosts | Queries
private const string Hk4eApiOs = "https://hk4e-api-os.hoyoverse.com";
private const string Hk4eApiOsGachaInfoApi = $"{Hk4eApiOs}/event/gacha_info/api";
#endregion
}

View File

@@ -36,6 +36,11 @@ internal class GachaInfoClient
/// <returns>单个祈愿记录页面</returns>
public Task<Response<GachaLogPage>?> GetGachaLogPageAsync(GachaLogConfigration config, CancellationToken token = default)
{
return httpClient.GetFromJsonAsync<Response<GachaLogPage>>(ApiEndpoints.GachaInfoGetGachaLog(config.AsQuery()), options, token);
string query = config.AsQuery();
string url = query.Contains("hoyoverse.com")
? ApiOsEndpoints.GachaInfoGetGachaLog(query)
: ApiEndpoints.GachaInfoGetGachaLog(query);
return httpClient.GetFromJsonAsync<Response<GachaLogPage>>(url, options, token);
}
}