feat: prepare for 1.53 preview/login

This commit is contained in:
2026-01-09 01:33:18 +08:00
parent 15c6623ed8
commit e7b0bcbfed
5 changed files with 23 additions and 7 deletions

View File

@@ -6,11 +6,15 @@ use serde::{Deserialize, Serialize};
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct GetUserPreviewApi { pub struct GetUserPreviewApi {
pub user_id: u32, pub user_id: u32,
pub token: Option<String>,
} }
impl From<u32> for GetUserPreviewApi { impl From<u32> for GetUserPreviewApi {
fn from(user_id: u32) -> Self { fn from(user_id: u32) -> Self {
Self { user_id } Self {
user_id,
token: None,
}
} }
} }

View File

@@ -12,6 +12,10 @@ pub struct UserLoginApi {
pub acsess_code: String, pub acsess_code: String,
pub place_id: String, pub place_id: String,
pub client_id: String, pub client_id: String,
/// QR Login 结果的 Token
pub token: Option<String>,
/// false 的情况,二维码扫描后半小时可登录。 /// false 的情况,二维码扫描后半小时可登录。
/// ///
/// true 的情况,可延长至二维码扫描后的两小时可登录。 /// true 的情况,可延长至二维码扫描后的两小时可登录。
@@ -36,7 +40,7 @@ pub struct UserLoginApiResp {
} }
impl UserLoginApi { impl UserLoginApi {
pub fn new(user_id: u32, is_continue: bool) -> Self { pub fn new(user_id: u32, is_continue: bool, token: Option<String>) -> Self {
let date_time = SystemTime::now() let date_time = SystemTime::now()
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)
.map(|t| t.as_secs()) .map(|t| t.as_secs())
@@ -51,8 +55,10 @@ impl UserLoginApi {
region_id: 13, region_id: 13,
acsess_code: "".to_owned(), acsess_code: "".to_owned(),
place_id: 3223.to_string(), place_id: 3223.to_string(),
is_continue,
generic_flag: 0, generic_flag: 0,
token,
is_continue,
client_id: "A63E01E6170".into(), client_id: "A63E01E6170".into(),
} }
} }

View File

@@ -43,6 +43,8 @@ pub enum Commands {
Preview { Preview {
#[arg(short, long)] #[arg(short, long)]
user_id: u32, user_id: u32,
#[arg(short, long)]
token: Option<String>,
}, },
/// Get B35 + B15 play records /// Get B35 + B15 play records
Rating { Rating {
@@ -79,6 +81,8 @@ pub enum Commands {
user_id: u32, user_id: u32,
#[arg(long)] #[arg(long)]
skip_login: bool, skip_login: bool,
#[arg(short, long)]
token: Option<String>,
}, },
/// Scrape all user, read possible id from stdin /// Scrape all user, read possible id from stdin

View File

@@ -165,12 +165,12 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
json_display(logout)?; json_display(logout)?;
} }
} }
Commands::Preview { user_id } => { Commands::Preview { user_id, token } => {
let preview: GetUserPreviewApiResp = Sdgb1_50::request( let preview: GetUserPreviewApiResp = Sdgb1_50::request(
&client, &client,
APIMethod::GetUserPreviewApi, APIMethod::GetUserPreviewApi,
user_id, user_id,
GetUserPreviewApi { user_id }, GetUserPreviewApi { user_id, token },
) )
.await?; .await?;
@@ -430,6 +430,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
Commands::Userdata { Commands::Userdata {
user_id, user_id,
skip_login, skip_login,
token,
} => { } => {
let action = async |_| match Sdgb1_50::request::<_, GetUserDataApiResp>( let action = async |_| match Sdgb1_50::request::<_, GetUserDataApiResp>(
&client, &client,
@@ -450,7 +451,7 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
if skip_login { if skip_login {
action(UserLoginApiResp::default()).await; action(UserLoginApiResp::default()).await;
} else { } else {
login_action(&client, user_id, action).await?; login_action(&client, user_id, token, action).await?;
} }
} }
} }

View File

@@ -15,9 +15,10 @@ use spdlog::info;
pub async fn login_action<R>( pub async fn login_action<R>(
client: &AsyncClient, client: &AsyncClient,
user_id: u32, user_id: u32,
token: Option<String>,
action: impl AsyncFnOnce(UserLoginApiResp) -> R, action: impl AsyncFnOnce(UserLoginApiResp) -> R,
) -> Result<R, ApiError> { ) -> Result<R, ApiError> {
let login = UserLoginApi::new(user_id, true); let login = UserLoginApi::new(user_id, true, token);
let date_time = login.date_time; let date_time = login.date_time;
let login_resp: UserLoginApiResp = let login_resp: UserLoginApiResp =