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 =
25 json!({
26 "dyn_id_str": dyn_id_str,
27 "up": up ,
28 "spmid":"333.1369.0.0",
29 "from_spmid":"333.999.0.0"
30
31 });
32
33 self
34 .post("https://api.bilibili.com/x/dynamic/feed/dyn/thumb")
35 .query(&[("csrf", csrf)])
36 .json(&json_body)
37 .send_bpi("点赞动态").await
38 }
39
40 pub async fn dynamic_remove_draft(
51 &self,
52 draft_id: &str
53 ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
54 let csrf = self.csrf()?;
55
56 self
57 .post("https://api.vc.bilibili.com/dynamic_draft/v1/dynamic_draft/rm_draft")
58 .form(
59 &[
60 ("draft_id", draft_id),
61 ("csrf", csrf.as_str()),
62 ]
63 )
64 .send_bpi("删除定时发布动态").await
65 }
66
67 pub async fn dynamic_set_top(
78 &self,
79 dyn_str: &str
80 ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
81 let csrf = self.csrf()?;
82 let json_body = json!({
83 "dyn_str": dyn_str,
84 });
85
86 self
87 .post("https://api.bilibili.com/x/dynamic/feed/space/set_top")
88 .query(&[("csrf", csrf)])
89 .json(&json_body)
90 .send_bpi("设置置顶动态").await
91 }
92
93 pub async fn dynamic_remove_top(
104 &self,
105 dyn_str: &str
106 ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
107 let csrf = self.csrf()?;
108 let json_body = json!({
109 "dyn_str": dyn_str,
110 });
111
112 self
113 .post("https://api.bilibili.com/x/dynamic/feed/space/rm_top")
114 .query(&[("csrf", csrf)])
115 .json(&json_body)
116 .send_bpi("取消置顶动态").await
117 }
118}
119
120#[cfg(test)]
121mod tests {
122 use super::*;
123
124 #[tokio::test]
125 async fn test_dynamic_like() {
126 let bpi = BpiClient::new();
127 let dynamic_id = "1099138163191840776";
128
129 let resp_new = bpi.dynamic_like(dynamic_id, 1).await;
131 assert!(resp_new.is_ok());
132 }
133
134 #[tokio::test]
135 #[ignore]
136 async fn test_dynamic_top() {
137 let bpi = BpiClient::new();
138 let dynamic_id = "1099138163191840776";
140
141 let resp_set_top = bpi.dynamic_set_top(dynamic_id).await;
143 assert!(resp_set_top.is_ok());
144
145 let resp_rm_top = bpi.dynamic_remove_top(dynamic_id).await;
147 if resp_rm_top.is_err() {
148 tracing::info!("取消置顶失败: {}", resp_rm_top.err().unwrap());
149 }
150 }
151}