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