1use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
5
6impl BpiClient {
7 pub async fn video_report_watch_progress(
19 &self,
20 aid: u64,
21 cid: u64,
22 progress: Option<u64>
23 ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
24 let csrf = self.csrf()?;
25
26 let mut form = reqwest::multipart::Form
27 ::new()
28 .text("aid", aid.to_string())
29 .text("cid", cid.to_string())
30 .text("csrf", csrf.to_string());
31
32 if let Some(p) = progress {
33 form = form.text("progress", p.to_string());
34 } else {
35 form = form.text("progress", "0");
36 }
37
38 self
39 .post("https://api.bilibili.com/x/v2/history/report")
40 .multipart(form)
41 .send_bpi("上报观看进度").await
42 }
43}
44
45#[cfg(test)]
48mod tests {
49 use super::*;
50 use tracing::info;
51
52 const TEST_AID: u64 = 10001;
53 const TEST_CID: u64 = 16546;
54
55 #[tokio::test]
56 async fn test_report_watch_progress() -> Result<(), BpiError> {
57 let bpi = BpiClient::new();
58 let resp = bpi.video_report_watch_progress(TEST_AID, TEST_CID, Some(120)).await?;
60
61 info!("上报观看进度结果: {:?}", resp);
62
63 Ok(())
64 }
65}