1use serde_json::json;
2
3use crate::{BilibiliRequest, BpiClient, BpiError, BpiResponse};
4
5impl BpiClient {
6 pub async fn dynamic_like(
18 &self,
19 dyn_id_str: &str,
20 up: u8,
21 ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
22 let csrf = self.csrf()?;
23
24 let json_body = json!({
25 "dyn_id_str": dyn_id_str,
26 "up": up ,
27 "spmid":"333.1369.0.0",
28 "from_spmid":"333.999.0.0"
29
30 });
31
32 self.post("https://api.bilibili.com/x/dynamic/feed/dyn/thumb")
33 .query(&[("csrf", csrf)])
34 .json(&json_body)
35 .send_bpi("点赞动态")
36 .await
37 }
38
39 pub async fn dynamic_remove_draft(
49 &self,
50 draft_id: &str,
51 ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
52 let csrf = self.csrf()?;
53
54 self.post("https://api.vc.bilibili.com/dynamic_draft/v1/dynamic_draft/rm_draft")
55 .form(&[("draft_id", draft_id), ("csrf", csrf.as_str())])
56 .send_bpi("删除定时发布动态")
57 .await
58 }
59
60 pub async fn dynamic_set_top(
70 &self,
71 dyn_str: &str,
72 ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
73 let csrf = self.csrf()?;
74 let json_body = json!({
75 "dyn_str": dyn_str,
76 });
77
78 self.post("https://api.bilibili.com/x/dynamic/feed/space/set_top")
79 .query(&[("csrf", csrf)])
80 .json(&json_body)
81 .send_bpi("设置置顶动态")
82 .await
83 }
84
85 pub async fn dynamic_remove_top(
96 &self,
97 dyn_str: &str,
98 ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
99 let csrf = self.csrf()?;
100 let json_body = json!({
101 "dyn_str": dyn_str,
102 });
103
104 self.post("https://api.bilibili.com/x/dynamic/feed/space/rm_top")
105 .query(&[("csrf", csrf)])
106 .json(&json_body)
107 .send_bpi("取消置顶动态")
108 .await
109 }
110}
111
112#[cfg(test)]
113mod tests {
114 use super::*;
115
116 #[tokio::test]
117
118 async fn test_dynamic_like() {
119 let bpi = BpiClient::new();
120 let dynamic_id = "1099138163191840776";
121
122 let resp_new = bpi.dynamic_like(dynamic_id, 1).await;
124 assert!(resp_new.is_ok());
125 }
126
127 #[tokio::test]
128 #[ignore]
129 async fn test_dynamic_top() {
130 let bpi = BpiClient::new();
131 let dynamic_id = "1099138163191840776";
133
134 let resp_set_top = bpi.dynamic_set_top(dynamic_id).await;
136 assert!(resp_set_top.is_ok());
137
138 let resp_rm_top = bpi.dynamic_remove_top(dynamic_id).await;
140 if resp_rm_top.is_err() {
141 tracing::info!("取消置顶失败: {}", resp_rm_top.err().unwrap());
142 }
143 }
144}