From bfacf42d71d0d738b3ebdc3f30ec8a29598f46db Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Sun, 19 Mar 2023 21:57:49 +0800 Subject: [PATCH] refactor user initialization --- .../Snap.Hutao/Model/Binding/User/User.cs | 180 +++++++++++------- .../Entity/Configuration/UserConfiguration.cs | 4 +- .../Snap.Hutao/Model/Entity/User.cs | 12 +- .../Snap.Hutao/Service/User/UserService.cs | 4 +- .../View/Dialog/AdoptCalculatorDialog.xaml.cs | 2 +- .../Dialog/CommunityGameRecordDialog.xaml.cs | 2 +- .../DailyNoteVerificationDialog.xaml.cs | 2 +- .../View/Dialog/SignInWebViewDialog.xaml.cs | 2 +- .../View/Page/SpiralAbyssRecordPage.xaml.cs | 2 +- .../SpiralAbyss/AvatarView.cs | 11 +- .../SpiralAbyss/BattleView.cs | 4 +- .../SpiralAbyss/FloorView.cs | 4 +- .../SpiralAbyss/LevelView.cs | 4 +- .../SpiralAbyss/RankAvatar.cs | 4 +- .../SpiralAbyssRecordViewModel.cs | 3 +- .../SpiralAbyss/SpiralAbyssView.cs | 4 +- .../Snap.Hutao/ViewModel/UserViewModel.cs | 8 +- .../Web/Bridge/MiHoYoJSInterface.cs | 6 +- .../Web/Hoyolab/App/Account/AccountClient.cs | 4 +- .../Web/Hoyolab/Bbs/User/UserClient.cs | 4 +- .../Snap.Hutao/Web/Hoyolab/CookieType.cs | 10 +- .../Web/Hoyolab/HoyolabHttpClientExtension.cs | 8 +- .../Web/Hoyolab/Passport/PassportClient.cs | 4 +- .../Web/Hoyolab/Passport/PassportClient2.cs | 10 +- .../Web/Hoyolab/Takumi/Auth/AuthClient.cs | 6 +- .../Hoyolab/Takumi/Binding/BindingClient.cs | 4 +- .../Hoyolab/Takumi/Binding/BindingClient2.cs | 8 +- .../Hoyolab/Takumi/GameRecord/CardClient.cs | 6 +- .../Takumi/GameRecord/GameRecordClient.cs | 12 +- 29 files changed, 185 insertions(+), 149 deletions(-) rename src/Snap.Hutao/Snap.Hutao/{Model/Binding => ViewModel}/SpiralAbyss/AvatarView.cs (70%) rename src/Snap.Hutao/Snap.Hutao/{Model/Binding => ViewModel}/SpiralAbyss/BattleView.cs (85%) rename src/Snap.Hutao/Snap.Hutao/{Model/Binding => ViewModel}/SpiralAbyss/FloorView.cs (90%) rename src/Snap.Hutao/Snap.Hutao/{Model/Binding => ViewModel}/SpiralAbyss/LevelView.cs (86%) rename src/Snap.Hutao/Snap.Hutao/{Model/Binding => ViewModel}/SpiralAbyss/RankAvatar.cs (87%) rename src/Snap.Hutao/Snap.Hutao/ViewModel/{ => SpiralAbyss}/SpiralAbyssRecordViewModel.cs (98%) rename src/Snap.Hutao/Snap.Hutao/{Model/Binding => ViewModel}/SpiralAbyss/SpiralAbyssView.cs (95%) diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Binding/User/User.cs b/src/Snap.Hutao/Snap.Hutao/Model/Binding/User/User.cs index e7427697..4da00a9b 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Binding/User/User.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Binding/User/User.cs @@ -75,18 +75,18 @@ internal sealed class User : ObservableObject set => inner.CookieToken = value; } - /// - public Cookie? Ltoken + /// + public Cookie? LToken { - get => inner.Ltoken; - set => inner.Ltoken = value; + get => inner.LToken; + set => inner.LToken = value; } - /// - public Cookie? Stoken + /// + public Cookie? SToken { - get => inner.Stoken; - set => inner.Stoken = value; + get => inner.SToken; + set => inner.SToken = value; } /// @@ -145,93 +145,127 @@ internal sealed class User : ObservableObject { if (isInitialized) { + // Prevent multiple initialization. return true; } - if (Stoken == null) + if (SToken == null) { return false; } using (IServiceScope scope = Ioc.Default.CreateScope()) { - Response response = await scope.ServiceProvider - .GetRequiredService() - .GetUserFullInfoAsync(Entity, token) - .ConfigureAwait(false); - UserInfo = response.Data?.UserInfo; - - // 自动填充 Ltoken - if (Ltoken == null) + if (!await TrySetUserInfoAsync(scope.ServiceProvider, token).ConfigureAwait(false)) { - Response ltokenResponse = await scope.ServiceProvider - .GetRequiredService() - .GetLtokenBySTokenAsync(Entity, token) - .ConfigureAwait(false); - - if (ltokenResponse.IsOk()) - { - Cookie ltokenCookie = Cookie.Parse($"ltuid={Entity.Aid};ltoken={ltokenResponse.Data.Ltoken}"); - Entity.Ltoken = ltokenCookie; - } - else - { - return false; - } + return false; } - Response actionTicketResponse = await scope.ServiceProvider + if (!await TrySetLTokenAsync(scope.ServiceProvider, token).ConfigureAwait(false)) + { + return false; + } + + if (!await TrySetUserGameRolesAsync(scope.ServiceProvider, token).ConfigureAwait(false)) + { + return false; + } + + if (await TrySetCookieTokenAsync(scope.ServiceProvider, token).ConfigureAwait(false)) + { + return false; + } + } + + SelectedUserGameRole = UserGameRoles.FirstOrFirstOrDefault(role => role.IsChosen); + return isInitialized = true; + } + + private async Task TrySetLTokenAsync(IServiceProvider provider, CancellationToken token) + { + if (LToken != null) + { + return true; + } + + Response lTokenResponse = await provider + .GetRequiredService() + .GetLTokenBySTokenAsync(Entity, token) + .ConfigureAwait(false); + + if (lTokenResponse.IsOk()) + { + LToken = Cookie.Parse($"{Cookie.LTUID}={Entity.Aid};{Cookie.LTOKEN}={lTokenResponse.Data.Ltoken}"); + return true; + } + else + { + return false; + } + } + + private async Task TrySetCookieTokenAsync(IServiceProvider provider, CancellationToken token) + { + if (CookieToken != null) + { + return true; + } + + Response cookieTokenResponse = await provider + .GetRequiredService() + .GetCookieAccountInfoBySTokenAsync(Entity, token) + .ConfigureAwait(false); + + if (cookieTokenResponse.IsOk()) + { + CookieToken = Cookie.Parse($"{Cookie.ACCOUNT_ID}={Entity.Aid};{Cookie.COOKIE_TOKEN}={cookieTokenResponse.Data.CookieToken}"); + return true; + } + else + { + return false; + } + } + + private async Task TrySetUserInfoAsync(IServiceProvider provider, CancellationToken token) + { + Response response = await provider + .GetRequiredService() + .GetUserFullInfoAsync(Entity, token) + .ConfigureAwait(false); + UserInfo = response.Data?.UserInfo; + return UserInfo != null; + } + + private async Task TrySetUserGameRolesAsync(IServiceProvider provider, CancellationToken token) + { + Response actionTicketResponse = await provider .GetRequiredService() .GetActionTicketByStokenAsync("game_role", Entity) .ConfigureAwait(false); - if (actionTicketResponse.IsOk()) + if (actionTicketResponse.IsOk()) + { + string actionTicket = actionTicketResponse.Data.Ticket; + + Response> userGameRolesResponse = await provider + .GetRequiredService() + .GetUserGameRolesByActionTicketAsync(actionTicket, Entity, token) + .ConfigureAwait(false); + + if (userGameRolesResponse.IsOk()) { - string actionTicket = actionTicketResponse.Data.Ticket; - - Response> userGameRolesResponse = await scope.ServiceProvider - .GetRequiredService() - .GetUserGameRolesByActionTicketAsync(actionTicket, Entity, token) - .ConfigureAwait(false); - - if (userGameRolesResponse.IsOk()) - { - UserGameRoles = userGameRolesResponse.Data.List; - } - else - { - return false; - } + UserGameRoles = userGameRolesResponse.Data.List; + return UserGameRoles.Any(); } else { return false; } - - // 自动填充 CookieToken - if (CookieToken == null) - { - Response cookieTokenResponse = await scope.ServiceProvider - .GetRequiredService() - .GetCookieAccountInfoBySTokenAsync(Entity, token) - .ConfigureAwait(false); - - if (cookieTokenResponse.IsOk()) - { - Cookie cookieTokenCookie = Cookie.Parse($"account_id={Entity.Aid};cookie_token={cookieTokenResponse.Data.CookieToken}"); - Entity.CookieToken = cookieTokenCookie; - } - else - { - return false; - } - } } - - SelectedUserGameRole = UserGameRoles.FirstOrFirstOrDefault(role => role.IsChosen); - - isInitialized = true; - - return UserInfo != null && UserGameRoles.Any(); + else + { + return false; + } } } diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Entity/Configuration/UserConfiguration.cs b/src/Snap.Hutao/Snap.Hutao/Model/Entity/Configuration/UserConfiguration.cs index 33d22f42..8777baaf 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Entity/Configuration/UserConfiguration.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Entity/Configuration/UserConfiguration.cs @@ -20,11 +20,11 @@ internal sealed class UserConfiguration : IEntityTypeConfiguration .HasColumnType("TEXT") .HasConversion(e => e!.ToString(), e => Cookie.Parse(e)); - builder.Property(e => e.Ltoken) + builder.Property(e => e.LToken) .HasColumnType("TEXT") .HasConversion(e => e!.ToString(), e => Cookie.Parse(e)); - builder.Property(e => e.Stoken) + builder.Property(e => e.SToken) .HasColumnType("TEXT") .HasConversion(e => e!.ToString(), e => Cookie.Parse(e)); } diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Entity/User.cs b/src/Snap.Hutao/Snap.Hutao/Model/Entity/User.cs index e6a71600..4b492b93 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Entity/User.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Entity/User.cs @@ -43,14 +43,16 @@ internal sealed class User : ISelectable public Cookie? CookieToken { get; set; } /// - /// 用户的 Ltoken + /// 用户的 LToken /// - public Cookie? Ltoken { get; set; } + [Column("Ltoken")] // DO NOT RENAME + public Cookie? LToken { get; set; } /// - /// 用户的 Stoken V2 + /// 用户的 SToken V2 /// - public Cookie? Stoken { get; set; } + [Column("Stoken")] // DO NOT RENAME + public Cookie? SToken { get; set; } /// /// 是否为国际服账号 @@ -68,6 +70,6 @@ internal sealed class User : ISelectable _ = cookie.TryGetAsLtoken(out Cookie? ltoken); _ = cookie.TryGetAsCookieToken(out Cookie? cookieToken); - return new() { Stoken = stoken, Ltoken = ltoken, CookieToken = cookieToken }; + return new() { SToken = stoken, LToken = ltoken, CookieToken = cookieToken }; } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/User/UserService.cs b/src/Snap.Hutao/Snap.Hutao/Service/User/UserService.cs index 8d2ebc24..e111713c 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/User/UserService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/User/UserService.cs @@ -210,8 +210,8 @@ internal class UserService : IUserService if (cookie.TryGetAsStoken(out Cookie? stoken)) { - user.Stoken = stoken; - user.Ltoken = cookie.TryGetAsLtoken(out Cookie? ltoken) ? ltoken : user.Ltoken; + user.SToken = stoken; + user.LToken = cookie.TryGetAsLtoken(out Cookie? ltoken) ? ltoken : user.LToken; user.CookieToken = cookie.TryGetAsCookieToken(out Cookie? cookieToken) ? cookieToken : user.CookieToken; await appDbContext.Users.UpdateAndSaveAsync(user.Entity).ConfigureAwait(false); diff --git a/src/Snap.Hutao/Snap.Hutao/View/Dialog/AdoptCalculatorDialog.xaml.cs b/src/Snap.Hutao/Snap.Hutao/View/Dialog/AdoptCalculatorDialog.xaml.cs index 50788e57..6ba927a2 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Dialog/AdoptCalculatorDialog.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/View/Dialog/AdoptCalculatorDialog.xaml.cs @@ -49,7 +49,7 @@ internal sealed partial class AdoptCalculatorDialog : ContentDialog return; } - coreWebView2.SetCookie(user.CookieToken, user.Ltoken, null).SetMobileUserAgent(); + coreWebView2.SetCookie(user.CookieToken, user.LToken, null).SetMobileUserAgent(); jsInterface = new(coreWebView2, scope.ServiceProvider); jsInterface.ClosePageRequested += OnClosePageRequested; diff --git a/src/Snap.Hutao/Snap.Hutao/View/Dialog/CommunityGameRecordDialog.xaml.cs b/src/Snap.Hutao/Snap.Hutao/View/Dialog/CommunityGameRecordDialog.xaml.cs index d4b80572..868e8f2b 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Dialog/CommunityGameRecordDialog.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/View/Dialog/CommunityGameRecordDialog.xaml.cs @@ -47,7 +47,7 @@ internal sealed partial class CommunityGameRecordDialog : ContentDialog return; } - coreWebView2.SetCookie(user.CookieToken, user.Ltoken, null).SetMobileUserAgent(); + coreWebView2.SetCookie(user.CookieToken, user.LToken, null).SetMobileUserAgent(); jsInterface = new(coreWebView2, scope.ServiceProvider); jsInterface.ClosePageRequested += OnClosePageRequested; diff --git a/src/Snap.Hutao/Snap.Hutao/View/Dialog/DailyNoteVerificationDialog.xaml.cs b/src/Snap.Hutao/Snap.Hutao/View/Dialog/DailyNoteVerificationDialog.xaml.cs index 622d4cb5..85076a5b 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Dialog/DailyNoteVerificationDialog.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/View/Dialog/DailyNoteVerificationDialog.xaml.cs @@ -45,7 +45,7 @@ internal sealed partial class DailyNoteVerificationDialog : ContentDialog CoreWebView2 coreWebView2 = WebView.CoreWebView2; Model.Entity.User user = userAndUid.User; - coreWebView2.SetCookie(user.CookieToken, user.Ltoken, null).SetMobileUserAgent(); + coreWebView2.SetCookie(user.CookieToken, user.LToken, null).SetMobileUserAgent(); jsInterface = new(coreWebView2, scope.ServiceProvider); jsInterface.ClosePageRequested += OnClosePageRequested; diff --git a/src/Snap.Hutao/Snap.Hutao/View/Dialog/SignInWebViewDialog.xaml.cs b/src/Snap.Hutao/Snap.Hutao/View/Dialog/SignInWebViewDialog.xaml.cs index 175a6e8f..e712f613 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Dialog/SignInWebViewDialog.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/View/Dialog/SignInWebViewDialog.xaml.cs @@ -47,7 +47,7 @@ internal sealed partial class SignInWebViewDialog : ContentDialog return; } - coreWebView2.SetCookie(user.CookieToken, user.Ltoken, null).SetMobileUserAgent(); + coreWebView2.SetCookie(user.CookieToken, user.LToken, null).SetMobileUserAgent(); signInJsInterface = new(coreWebView2, scope.ServiceProvider); coreWebView2.Navigate("https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?act_id=e202009291139501"); } diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/SpiralAbyssRecordPage.xaml.cs b/src/Snap.Hutao/Snap.Hutao/View/Page/SpiralAbyssRecordPage.xaml.cs index 0a491acf..316342b2 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/SpiralAbyssRecordPage.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/SpiralAbyssRecordPage.xaml.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. using Snap.Hutao.Control; -using Snap.Hutao.ViewModel; +using Snap.Hutao.ViewModel.SpiralAbyss; namespace Snap.Hutao.View.Page; diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/AvatarView.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/AvatarView.cs similarity index 70% rename from src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/AvatarView.cs rename to src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/AvatarView.cs index 8146b455..f1df5e97 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/AvatarView.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/AvatarView.cs @@ -1,10 +1,11 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using Snap.Hutao.Model.Binding; using Snap.Hutao.Model.Intrinsic; using Snap.Hutao.Model.Primitive; -namespace Snap.Hutao.Model.Binding.SpiralAbyss; +namespace Snap.Hutao.ViewModel.SpiralAbyss; /// /// 角色视图 @@ -16,11 +17,11 @@ internal class AvatarView : INameIconSide /// 构造一个新的角色视图 /// /// 角色 - public AvatarView(Metadata.Avatar.Avatar metaAvatar) + public AvatarView(Model.Metadata.Avatar.Avatar metaAvatar) { Name = metaAvatar.Name; - Icon = Metadata.Converter.AvatarIconConverter.IconNameToUri(metaAvatar.Icon); - SideIcon = Metadata.Converter.AvatarIconConverter.IconNameToUri(metaAvatar.SideIcon); + Icon = Model.Metadata.Converter.AvatarIconConverter.IconNameToUri(metaAvatar.Icon); + SideIcon = Model.Metadata.Converter.AvatarIconConverter.IconNameToUri(metaAvatar.SideIcon); Quality = metaAvatar.Quality; } @@ -29,7 +30,7 @@ internal class AvatarView : INameIconSide /// /// 角色Id /// Id角色映射 - public AvatarView(AvatarId avatarId, Dictionary idAvatarMap) + public AvatarView(AvatarId avatarId, Dictionary idAvatarMap) : this(idAvatarMap[avatarId]) { } diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/BattleView.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/BattleView.cs similarity index 85% rename from src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/BattleView.cs rename to src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/BattleView.cs index 9067e4a3..f2e544f6 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/BattleView.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/BattleView.cs @@ -4,7 +4,7 @@ using Snap.Hutao.Model.Primitive; using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord.SpiralAbyss; -namespace Snap.Hutao.Model.Binding.SpiralAbyss; +namespace Snap.Hutao.ViewModel.SpiralAbyss; /// /// 上下半视图 @@ -17,7 +17,7 @@ internal sealed class BattleView /// /// 战斗 /// Id角色映射 - public BattleView(Battle battle, Dictionary idAvatarMap) + public BattleView(Battle battle, Dictionary idAvatarMap) { Time = DateTimeOffset.FromUnixTimeSeconds(battle.Timestamp).ToLocalTime().ToString("yyyy.MM.dd HH:mm:ss"); Avatars = battle.Avatars.Select(a => new AvatarView(a.Id, idAvatarMap)).ToList(); diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/FloorView.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/FloorView.cs similarity index 90% rename from src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/FloorView.cs rename to src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/FloorView.cs index 9c6f1bbf..fe8b052c 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/FloorView.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/FloorView.cs @@ -3,7 +3,7 @@ using Snap.Hutao.Model.Primitive; -namespace Snap.Hutao.Model.Binding.SpiralAbyss; +namespace Snap.Hutao.ViewModel.SpiralAbyss; /// /// 层视图 @@ -16,7 +16,7 @@ internal sealed class FloorView /// /// 层 /// Id角色映射 - public FloorView(Web.Hoyolab.Takumi.GameRecord.SpiralAbyss.Floor floor, Dictionary idAvatarMap) + public FloorView(Web.Hoyolab.Takumi.GameRecord.SpiralAbyss.Floor floor, Dictionary idAvatarMap) { Index = string.Format(SH.ModelBindingHutaoComplexRankFloor, floor.Index); SettleTime = $"{DateTimeOffset.FromUnixTimeSeconds(floor.SettleTime).ToLocalTime():yyyy.MM.dd HH:mm:ss}"; diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/LevelView.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/LevelView.cs similarity index 86% rename from src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/LevelView.cs rename to src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/LevelView.cs index 611098cd..7bfe4b77 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/LevelView.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/LevelView.cs @@ -4,7 +4,7 @@ using Snap.Hutao.Model.Primitive; using Snap.Hutao.Web.Hoyolab.Takumi.GameRecord.SpiralAbyss; -namespace Snap.Hutao.Model.Binding.SpiralAbyss; +namespace Snap.Hutao.ViewModel.SpiralAbyss; /// /// 间视图 @@ -17,7 +17,7 @@ internal sealed class LevelView /// /// 间 /// Id角色映射 - public LevelView(Level level, Dictionary idAvatarMap) + public LevelView(Level level, Dictionary idAvatarMap) { Index = string.Format(SH.ModelBindingHutaoComplexRankLevel, level.Index); Star = level.Star; diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/RankAvatar.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/RankAvatar.cs similarity index 87% rename from src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/RankAvatar.cs rename to src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/RankAvatar.cs index 6a9937c0..4ab540cf 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/RankAvatar.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/RankAvatar.cs @@ -3,7 +3,7 @@ using Snap.Hutao.Model.Primitive; -namespace Snap.Hutao.Model.Binding.SpiralAbyss; +namespace Snap.Hutao.ViewModel.SpiralAbyss; /// /// 排行角色 @@ -17,7 +17,7 @@ internal sealed class RankAvatar : AvatarView /// 值 /// 角色Id /// Id角色映射 - public RankAvatar(int value, AvatarId avatarId, Dictionary idAvatarMap) + public RankAvatar(int value, AvatarId avatarId, Dictionary idAvatarMap) : base(avatarId, idAvatarMap) { Value = value; diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyssRecordViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/SpiralAbyssRecordViewModel.cs similarity index 98% rename from src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyssRecordViewModel.cs rename to src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/SpiralAbyssRecordViewModel.cs index b290d9df..fafda204 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyssRecordViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/SpiralAbyssRecordViewModel.cs @@ -5,7 +5,6 @@ using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using Microsoft.Extensions.DependencyInjection; using Snap.Hutao.Message; -using Snap.Hutao.Model.Binding.SpiralAbyss; using Snap.Hutao.Model.Binding.User; using Snap.Hutao.Model.Entity; using Snap.Hutao.Model.Metadata; @@ -18,7 +17,7 @@ using Snap.Hutao.Web.Hutao; using Snap.Hutao.Web.Hutao.Model.Post; using System.Collections.ObjectModel; -namespace Snap.Hutao.ViewModel; +namespace Snap.Hutao.ViewModel.SpiralAbyss; /// /// 深渊记录视图模型 diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/SpiralAbyssView.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/SpiralAbyssView.cs similarity index 95% rename from src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/SpiralAbyssView.cs rename to src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/SpiralAbyssView.cs index 0cf9ff8f..5f4c672f 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Binding/SpiralAbyss/SpiralAbyssView.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/SpiralAbyss/SpiralAbyssView.cs @@ -3,7 +3,7 @@ using Snap.Hutao.Model.Primitive; -namespace Snap.Hutao.Model.Binding.SpiralAbyss; +namespace Snap.Hutao.ViewModel.SpiralAbyss; /// /// 深渊视图 @@ -16,7 +16,7 @@ internal sealed class SpiralAbyssView /// /// 深渊信息 /// Id角色映射 - public SpiralAbyssView(Web.Hoyolab.Takumi.GameRecord.SpiralAbyss.SpiralAbyss spiralAbyss, Dictionary idAvatarMap) + public SpiralAbyssView(Web.Hoyolab.Takumi.GameRecord.SpiralAbyss.SpiralAbyss spiralAbyss, Dictionary idAvatarMap) { Schedule = string.Format(SH.ModelEntitySpiralAbyssScheduleFormat, spiralAbyss.ScheduleId); TotalBattleTimes = spiralAbyss.TotalBattleTimes; diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/UserViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/UserViewModel.cs index 1d8164d1..d59490b1 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/UserViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/UserViewModel.cs @@ -194,10 +194,10 @@ internal sealed class UserViewModel : ObservableObject try { string cookieString = new StringBuilder() - .Append(user!.Stoken) - .AppendIf(user.Stoken != null, ';') - .Append(user.Ltoken) - .AppendIf(user.Ltoken != null, ';') + .Append(user!.SToken) + .AppendIf(user.SToken != null, ';') + .Append(user.LToken) + .AppendIf(user.LToken != null, ';') .Append(user.CookieToken) .ToString(); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSInterface.cs b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSInterface.cs index 70c2399b..298dbcc5 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSInterface.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSInterface.cs @@ -105,8 +105,8 @@ internal class MiHoYoJSInterface { Data = new() { - [Cookie.LTUID] = user.Ltoken![Cookie.LTUID], - [Cookie.LTOKEN] = user.Ltoken[Cookie.LTOKEN], + [Cookie.LTUID] = user.LToken![Cookie.LTUID], + [Cookie.LTOKEN] = user.LToken[Cookie.LTOKEN], [Cookie.LOGIN_TICKET] = string.Empty, }, }; @@ -203,7 +203,7 @@ internal class MiHoYoJSInterface } await ThreadHelper.SwitchToMainThreadAsync(); - webView.SetCookie(user.CookieToken, user.Ltoken); + webView.SetCookie(user.CookieToken, user.LToken); return new() { Data = new() { [Cookie.COOKIE_TOKEN] = user.CookieToken![Cookie.COOKIE_TOKEN] } }; } diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/App/Account/AccountClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/App/Account/AccountClient.cs index 52b5db2f..1ea0a8ae 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/App/Account/AccountClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/App/Account/AccountClient.cs @@ -43,11 +43,11 @@ internal sealed class AccountClient /// 提交数据 /// 取消令牌 /// 用户角色信息 - [ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.K2)] + [ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.K2)] public async Task> GenerateAuthenticationKeyAsync(User user, GenAuthKeyData data, CancellationToken token = default) { Response? resp = await httpClient - .SetUser(user, CookieType.Stoken) + .SetUser(user, CookieType.SToken) .SetReferer(ApiEndpoints.AppMihoyoReferer) .UseDynamicSecret(DynamicSecretVersion.Gen1, SaltType.K2, false) .TryCatchPostAsJsonAsync>(ApiEndpoints.AppAuthGenAuthKey, data, options, logger, token) diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Bbs/User/UserClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Bbs/User/UserClient.cs index 8c9f8e06..240c18bb 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Bbs/User/UserClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Bbs/User/UserClient.cs @@ -40,11 +40,11 @@ internal sealed class UserClient /// 用户 /// 取消令牌 /// 详细信息 - [ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.K2)] + [ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.K2)] public async Task> GetUserFullInfoAsync(Model.Entity.User user, CancellationToken token = default) { Response? resp = await httpClient - .SetUser(user, CookieType.Stoken) + .SetUser(user, CookieType.SToken) .SetReferer(ApiEndpoints.BbsReferer) .UseDynamicSecret(DynamicSecretVersion.Gen1, SaltType.K2, true) .TryCatchGetFromJsonAsync>(ApiEndpoints.UserFullInfoQuery(user.Aid!), options, logger, token) diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/CookieType.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/CookieType.cs index a5ee90a1..1fe84def 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/CookieType.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/CookieType.cs @@ -23,15 +23,15 @@ internal enum CookieType /// /// 需要 Ltoken /// - Ltoken = 0B0010, + LToken = 0B0010, /// - /// 需要 CookieToken 与 Ltoken + /// 需要 CookieToken 与 LToken /// - Cookie = CookieToken | Ltoken, + Cookie = CookieToken | LToken, /// - /// 需要 Stoken + /// 需要 SToken /// - Stoken = 0B0100, + SToken = 0B0100, } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyolabHttpClientExtension.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyolabHttpClientExtension.cs index 0527ae3a..43373f75 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyolabHttpClientExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyolabHttpClientExtension.cs @@ -30,14 +30,14 @@ internal static class HoyolabHttpClientExtension stringBuilder.Append(user.CookieToken).AppendIf(user.CookieToken != null, ';'); } - if (cookie.HasFlag(CookieType.Ltoken)) + if (cookie.HasFlag(CookieType.LToken)) { - stringBuilder.Append(user.Ltoken).AppendIf(user.Ltoken != null, ';'); + stringBuilder.Append(user.LToken).AppendIf(user.LToken != null, ';'); } - if (cookie.HasFlag(CookieType.Stoken)) + if (cookie.HasFlag(CookieType.SToken)) { - stringBuilder.Append(user.Stoken).AppendIf(user.Stoken != null, ';'); + stringBuilder.Append(user.SToken).AppendIf(user.SToken != null, ';'); } string result = stringBuilder.ToString(); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/PassportClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/PassportClient.cs index 73fe1c0c..bbed4295 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/PassportClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/PassportClient.cs @@ -39,11 +39,11 @@ internal sealed class PassportClient /// 用户 /// 取消令牌 /// 验证信息 - [ApiInformation(Cookie = CookieType.Ltoken)] + [ApiInformation(Cookie = CookieType.LToken)] public async Task> VerifyLtokenAsync(User user, CancellationToken token) { Response? response = await httpClient - .SetUser(user, CookieType.Ltoken) + .SetUser(user, CookieType.LToken) .TryCatchPostAsJsonAsync>(ApiEndpoints.AccountVerifyLtoken, new(), options, logger, token) .ConfigureAwait(false); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/PassportClient2.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/PassportClient2.cs index 8b8573fd..b9542300 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/PassportClient2.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Passport/PassportClient2.cs @@ -64,11 +64,11 @@ internal sealed class PassportClient2 /// 用户 /// 取消令牌 /// cookie token - [ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.PROD)] + [ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.PROD)] public async Task> GetCookieAccountInfoBySTokenAsync(User user, CancellationToken token = default) { Response? resp = await httpClient - .SetUser(user, CookieType.Stoken) + .SetUser(user, CookieType.SToken) .UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.PROD, true) .TryCatchGetFromJsonAsync>(ApiEndpoints.AccountGetCookieTokenBySToken, options, logger, token) .ConfigureAwait(false); @@ -82,11 +82,11 @@ internal sealed class PassportClient2 /// 用户 /// 取消令牌 /// uid 与 cookie token - [ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.PROD)] - public async Task> GetLtokenBySTokenAsync(User user, CancellationToken token) + [ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.PROD)] + public async Task> GetLTokenBySTokenAsync(User user, CancellationToken token) { Response? resp = await httpClient - .SetUser(user, CookieType.Stoken) + .SetUser(user, CookieType.SToken) .UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.PROD, true) .TryCatchGetFromJsonAsync>(ApiEndpoints.AccountGetLtokenByStoken, options, logger, token) .ConfigureAwait(false); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Auth/AuthClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Auth/AuthClient.cs index 18774c57..d67b4359 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Auth/AuthClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Auth/AuthClient.cs @@ -42,13 +42,13 @@ internal sealed class AuthClient /// 操作 /// 用户 /// 操作凭证 - [ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.K2)] + [ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.K2)] public async Task> GetActionTicketByStokenAsync(string action, User user) { Response? resp = await httpClient - .SetUser(user, CookieType.Stoken) + .SetUser(user, CookieType.SToken) .UseDynamicSecret(DynamicSecretVersion.Gen1, SaltType.K2, true) - .TryCatchGetFromJsonAsync>(ApiEndpoints.AuthActionTicket(action, user.Stoken?[Cookie.STOKEN] ?? string.Empty, user.Aid!), options, logger) + .TryCatchGetFromJsonAsync>(ApiEndpoints.AuthActionTicket(action, user.SToken?[Cookie.STOKEN] ?? string.Empty, user.Aid!), options, logger) .ConfigureAwait(false); return Response.Response.DefaultIfNull(resp); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Binding/BindingClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Binding/BindingClient.cs index e41972a0..a8c598fe 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Binding/BindingClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Binding/BindingClient.cs @@ -40,13 +40,13 @@ internal sealed class BindingClient /// 用户 /// 取消令牌 /// 用户角色信息 - [ApiInformation(Cookie = CookieType.Ltoken)] + [ApiInformation(Cookie = CookieType.LToken)] public async Task>> GetUserGameRolesByActionTicketAsync(string actionTicket, User user, CancellationToken token = default) { string url = ApiEndpoints.UserGameRolesByActionTicket(actionTicket); Response>? resp = await httpClient - .SetUser(user, CookieType.Ltoken) + .SetUser(user, CookieType.LToken) .TryCatchGetFromJsonAsync>>(url, options, logger, token) .ConfigureAwait(false); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Binding/BindingClient2.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Binding/BindingClient2.cs index 0351a4ea..a1c6ce14 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Binding/BindingClient2.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/Binding/BindingClient2.cs @@ -41,11 +41,11 @@ internal sealed class BindingClient2 /// 用户 /// 取消令牌 /// 用户角色信息 - [ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.LK2)] + [ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.LK2)] public async Task> GetUserGameRolesByStokenAsync(User user, CancellationToken token = default) { Response>? resp = await httpClient - .SetUser(user, CookieType.Stoken) + .SetUser(user, CookieType.SToken) .UseDynamicSecret(DynamicSecretVersion.Gen1, SaltType.LK2, true) .TryCatchGetFromJsonAsync>>(ApiEndpoints.UserGameRolesByStoken, options, logger, token) .ConfigureAwait(false); @@ -61,11 +61,11 @@ internal sealed class BindingClient2 /// 提交数据 /// 取消令牌 /// 用户角色信息 - [ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.LK2)] + [ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.LK2)] public async Task> GenerateAuthenticationKeyAsync(User user, GenAuthKeyData data, CancellationToken token = default) { Response? resp = await httpClient - .SetUser(user, CookieType.Stoken) + .SetUser(user, CookieType.SToken) .SetReferer(ApiEndpoints.AppMihoyoReferer) .UseDynamicSecret(DynamicSecretVersion.Gen1, SaltType.LK2, true) .TryCatchPostAsJsonAsync>(ApiEndpoints.BindingGenAuthKey, data, options, logger, token) diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/CardClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/CardClient.cs index 6ff0427b..601e8663 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/CardClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/CardClient.cs @@ -45,7 +45,7 @@ internal sealed class CardClient public async Task> CreateVerificationAsync(User user, CancellationToken token) { Response? resp = await httpClient - .SetUser(user, CookieType.Ltoken) + .SetUser(user, CookieType.LToken) .UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.X4, false) .TryCatchGetFromJsonAsync>(ApiEndpoints.CardCreateVerification, options, logger, token) .ConfigureAwait(false); @@ -77,11 +77,11 @@ internal sealed class CardClient /// 用户 /// 取消令牌 /// 桌面小组件数据 - [ApiInformation(Cookie = CookieType.Stoken, Salt = SaltType.X6)] + [ApiInformation(Cookie = CookieType.SToken, Salt = SaltType.X6)] public async Task>> GetWidgetDataAsync(User user, CancellationToken token) { Response>? resp = await httpClient - .SetUser(user, CookieType.Stoken) + .SetUser(user, CookieType.SToken) .UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.X6, false) .TryCatchGetFromJsonAsync>>(ApiEndpoints.CardWidgetData, options, logger, token) .ConfigureAwait(false); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClient.cs index ad0635bb..86f2cbf7 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClient.cs @@ -82,11 +82,11 @@ internal sealed class GameRecordClient /// 用户与角色 /// 取消令牌 /// 玩家的基础信息 - [ApiInformation(Cookie = CookieType.Ltoken, Salt = SaltType.X4)] + [ApiInformation(Cookie = CookieType.LToken, Salt = SaltType.X4)] public async Task> GetPlayerInfoAsync(UserAndUid userAndUid, CancellationToken token = default) { Response? resp = await httpClient - .SetUser(userAndUid.User, CookieType.Ltoken) + .SetUser(userAndUid.User, CookieType.LToken) .UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.X4, false) .TryCatchGetFromJsonAsync>(ApiEndpoints.GameRecordIndex(userAndUid.Uid), options, logger, token) .ConfigureAwait(false); @@ -119,11 +119,11 @@ internal sealed class GameRecordClient /// 用户与角色 /// 取消令牌 /// 角色基本信息 - [ApiInformation(Cookie = CookieType.Ltoken, Salt = SaltType.X4)] + [ApiInformation(Cookie = CookieType.LToken, Salt = SaltType.X4)] public async Task> GetRoleBasicInfoAsync(UserAndUid userAndUid, CancellationToken token = default) { Response? resp = await httpClient - .SetUser(userAndUid.User, CookieType.Ltoken) + .SetUser(userAndUid.User, CookieType.LToken) .UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.X4, false) .TryCatchGetFromJsonAsync>(ApiEndpoints.GameRecordRoleBasicInfo(userAndUid.Uid), options, logger, token) .ConfigureAwait(false); @@ -138,13 +138,13 @@ internal sealed class GameRecordClient /// 玩家的基础信息 /// 取消令牌 /// 角色列表 - [ApiInformation(Cookie = CookieType.Ltoken, Salt = SaltType.X4)] + [ApiInformation(Cookie = CookieType.LToken, Salt = SaltType.X4)] public async Task> GetCharactersAsync(UserAndUid userAndUid, PlayerInfo playerInfo, CancellationToken token = default) { CharacterData data = new(userAndUid.Uid, playerInfo.Avatars.Select(x => x.Id)); Response? resp = await httpClient - .SetUser(userAndUid.User, CookieType.Ltoken) + .SetUser(userAndUid.User, CookieType.LToken) .UseDynamicSecret(DynamicSecretVersion.Gen2, SaltType.X4, false) .TryCatchPostAsJsonAsync>(ApiEndpoints.GameRecordCharacter, data, options, logger, token) .ConfigureAwait(false);