use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
use serde::{ Deserialize, Serialize };
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LogoutData {
#[serde(rename = "redirectUrl")]
pub redirect_url: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LogoutResponse {
pub code: i32,
pub status: bool,
pub ts: u64,
pub message: Option<String>,
pub data: Option<LogoutData>,
}
impl BpiClient {
pub async fn logout_web(
&self,
gourl: Option<&str>
) -> Result<BpiResponse<LogoutData>, BpiError> {
let csrf = self.csrf()?;
let form = vec![
("biliCSRF", csrf),
("gourl", gourl.unwrap_or("javascript:history.go(-1)").to_string())
];
let result = self
.post("https://passport.bilibili.com/login/exit/v2")
.form(&form)
.send_bpi("退出登录 (Web端)").await?;
Ok(result)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_logout_web() -> Result<(), Box<BpiError>> {
Ok(())
}
}