use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
use serde::{ Deserialize, Serialize };
#[derive(Debug, Clone, Serialize)]
pub struct ClockInMakeupRequest {
pub r#type: i32,
pub date: String,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct PointInfo {
pub point: i32,
pub origin_point: i32,
pub is_activity: bool,
pub title: String,
}
#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct ClockInInfoData {
pub day_count: i32,
pub status: i32,
pub points: Vec<i32>,
pub credit_icon: String,
pub sign_before_icon: String,
pub sign_today_icon: String,
pub breathe_icon: String,
#[serde(default)]
pub new_credit_x_icon: String,
#[serde(default)]
pub coupon_pic: String,
pub point_infos: Vec<PointInfo>,
}
pub type ClockInInfoResponse = BpiResponse<ClockInInfoData>;
impl BpiClient {
pub async fn manga_clock_in(&self) -> Result<BpiResponse<serde_json::Value>, BpiError> {
let params = [("platform", "android")];
self
.post("https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn")
.form(¶ms)
.send_bpi("漫画签到").await
}
pub async fn manga_clock_in_makeup(
&self,
date: &str
) -> Result<BpiResponse<serde_json::Value>, BpiError> {
let params = ClockInMakeupRequest {
r#type: 0,
date: date.to_string(),
};
self
.post("https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn?platform=android")
.json(¶ms)
.send_bpi("漫画补签").await
}
pub async fn manga_clock_in_info(&self) -> Result<ClockInInfoResponse, BpiError> {
self
.post("https://manga.bilibili.com/twirp/activity.v1.Activity/GetClockInInfo")
.send_bpi("获取漫画签到信息").await
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_manga_clock_in() -> Result<(), Box<BpiError>> {
let bpi = BpiClient::new();
let result = bpi.manga_clock_in().await;
match result {
Ok(_) => tracing::info!("签到成功"),
Err(error) => tracing::error!("{:#?}", error),
}
Ok(())
}
#[tokio::test]
async fn test_get_manga_clock_in_info() -> Result<(), Box<BpiError>> {
let bpi = BpiClient::new();
let result = bpi.manga_clock_in_info().await?;
let data = result.into_data()?;
assert!(data.day_count >= 0);
assert!(data.status == 0 || data.status == 1);
assert_eq!(data.points.len(), 7); assert!(!data.point_infos.is_empty());
Ok(())
}
}