diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/UrlProvider/GachaLogUrlWebCacheProvider.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/UrlProvider/GachaLogUrlWebCacheProvider.cs index 6f397185..ef22692d 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/UrlProvider/GachaLogUrlWebCacheProvider.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/UrlProvider/GachaLogUrlWebCacheProvider.cs @@ -25,6 +25,12 @@ internal class GachaLogUrlWebCacheProvider : IGachaLogUrlProvider this.gameService = gameService; } + private enum UrlMatch + { + Chinese, + Oversea, + } + /// 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 span = stream.ToArray(); - ReadOnlySpan match = "https://webstatic.mihoyo.com/hk4e/event/e20190909gacha-v2/index.html"u8; - ReadOnlySpan 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 span = stream.ToArray(); - ReadOnlySpan match = "https://webstatic-sea.hoyoverse.com/genshin/event/e20190909gacha-v2/index.html"u8; + ReadOnlySpan 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 zero = "\0"u8; int index = span.LastIndexOf(match); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs b/src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs index 33479114..4ef215ec 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs @@ -7,7 +7,7 @@ using Snap.Hutao.Web.Hoyolab; namespace Snap.Hutao.Web; /// -/// API 端点 +/// 国服 API 端点 /// [SuppressMessage("", "SA1201")] [SuppressMessage("", "SA1124")] @@ -274,14 +274,7 @@ internal static class ApiEndpoints /// 祈愿记录信息Url 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"; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/ApiOsEndpoints.cs b/src/Snap.Hutao/Snap.Hutao/Web/ApiOsEndpoints.cs new file mode 100644 index 00000000..cb1ab1c4 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/ApiOsEndpoints.cs @@ -0,0 +1,30 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web; + +/// +/// 国际服 API 端点 +/// +[SuppressMessage("", "SA1201")] +[SuppressMessage("", "SA1124")] +internal static class ApiOsEndpoints +{ + #region Hk4eApiOsGachaInfoApi + + /// + /// 获取祈愿记录 + /// + /// query string + /// 祈愿记录信息Url + 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 +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Hk4e/Event/GachaInfo/GachaInfoClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Hk4e/Event/GachaInfo/GachaInfoClient.cs index 6c376957..4aa6956a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Hk4e/Event/GachaInfo/GachaInfoClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Hk4e/Event/GachaInfo/GachaInfoClient.cs @@ -36,6 +36,11 @@ internal class GachaInfoClient /// 单个祈愿记录页面 public Task?> GetGachaLogPageAsync(GachaLogConfigration config, CancellationToken token = default) { - return httpClient.GetFromJsonAsync>(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>(url, options, token); } } \ No newline at end of file