feat: introduce typed resp request
This commit is contained in:
@@ -13,7 +13,7 @@ use nyquest::{
|
||||
r#async::Request,
|
||||
header::{ACCEPT_ENCODING, CONTENT_ENCODING, EXPECT, USER_AGENT},
|
||||
};
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub trait MaiVersion {
|
||||
const AES_KEY: &[u8; 32];
|
||||
@@ -63,7 +63,7 @@ pub trait MaiVersionExt: MaiVersion {
|
||||
Ok(req)
|
||||
}
|
||||
|
||||
fn request<D>(
|
||||
fn request_raw<D>(
|
||||
client: &AsyncClient,
|
||||
api: APIMethod,
|
||||
agent_extra: impl Display,
|
||||
@@ -79,6 +79,22 @@ pub trait MaiVersionExt: MaiVersion {
|
||||
Ok(decoded)
|
||||
}
|
||||
}
|
||||
|
||||
fn request<D, R>(
|
||||
client: &AsyncClient,
|
||||
api: APIMethod,
|
||||
agent_extra: impl Display,
|
||||
data: D,
|
||||
) -> impl Future<Output = Result<R, ApiError>>
|
||||
where
|
||||
D: Serialize,
|
||||
R: for<'a> Deserialize<'a>,
|
||||
{
|
||||
async {
|
||||
let raw_data = Self::request_raw(client, api, agent_extra, data).await?;
|
||||
Ok(serde_json::from_slice(&raw_data)?)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Sdgb1_40;
|
||||
|
||||
@@ -5,3 +5,6 @@ pub struct Ping {}
|
||||
|
||||
mod get_user_preview_api;
|
||||
pub use get_user_preview_api::{GetUserPreviewApi, GetUserPreviewApiResp};
|
||||
|
||||
mod user_logout_api;
|
||||
pub use user_logout_api::{UserLogoutApi, UserLogoutApiResp};
|
||||
|
||||
45
sdgb-api/src/title/model/user_logout_api/mod.rs
Normal file
45
sdgb-api/src/title/model/user_logout_api/mod.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UserLogoutApi {
|
||||
pub user_id: u32,
|
||||
pub region_id: u64,
|
||||
pub place_id: u64,
|
||||
/// empty on SDGB
|
||||
pub access_code: &'static str,
|
||||
/// keychip without dash, 11 bytes
|
||||
pub client_id: String,
|
||||
/// Unix timestamp
|
||||
pub date_time: u64,
|
||||
#[serde(rename = "type")]
|
||||
pub type_: i64,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UserLogoutApiResp {
|
||||
pub result_code: i64,
|
||||
}
|
||||
|
||||
impl Default for UserLogoutApi {
|
||||
fn default() -> Self {
|
||||
let user_id = 0;
|
||||
let date_time = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.map(|t| t.as_secs())
|
||||
.unwrap_or_default();
|
||||
|
||||
Self {
|
||||
user_id,
|
||||
date_time,
|
||||
region_id: 22,
|
||||
place_id: 3490,
|
||||
client_id: "A63E01E9564".into(),
|
||||
type_: 1,
|
||||
access_code: "",
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user