bpi_rs/creativecenter/
opus.rs

1//! 创作中心作品管理 API
2//!
3//! 参考文档:https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/creativecenter/opus.md
4
5use crate::{BilibiliRequest, BpiClient, BpiError, BpiResponse};
6use serde_json::json;
7
8impl BpiClient {
9    /// 删除动态
10    ///
11    /// # 参数
12    /// | 名称 | 类型 | 说明 |
13    /// | ---- | ---- | ---- |
14    /// | `dyn_id` | &str | 动态 ID |
15    ///
16    /// # 文档
17    /// [删除动态](https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/creativecenter/opus.md#删除动态)
18    pub async fn dynamic_delete(
19        &self,
20        dyn_id: &str,
21    ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
22        let csrf = self.csrf()?;
23
24        self.post("https://api.bilibili.com/x/dynamic/feed/operate/remove")
25            .query(&[("csrf", csrf)])
26            .json(&json!({
27              "dyn_id_str": dyn_id
28            }))
29            .send_bpi("删除动态")
30            .await
31    }
32
33    /// 删除专栏
34    ///
35    /// # 参数
36    /// | 名称 | 类型 | 说明 |
37    /// | ---- | ---- | ---- |
38    /// | `aid` | u64 | 专栏文章 ID |
39    ///
40    /// # 文档
41    /// [删除专栏](https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/creativecenter/opus.md#删除专栏)
42    pub async fn article_delete(
43        &self,
44        aid: u64,
45    ) -> Result<BpiResponse<serde_json::Value>, BpiError> {
46        let csrf = self.csrf()?;
47
48        self.post("https://member.bilibili.com/x/web/article/delete")
49            .form(&[("aid", aid.to_string()), ("csrf", csrf)])
50            .send_bpi("删除专栏")
51            .await
52    }
53}
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    const TEST_DYN_ID: &str = "951560312615600129";
60    const TEST_AID: u64 = 42997969;
61
62    #[ignore]
63    #[tokio::test]
64    async fn test_dynamic_delete() -> Result<(), Box<BpiError>> {
65        let bpi = BpiClient::new();
66
67        bpi.dynamic_delete(TEST_DYN_ID).await?;
68
69        Ok(())
70    }
71    #[ignore]
72    #[tokio::test]
73    async fn test_article_delete() -> Result<(), Box<BpiError>> {
74        let bpi = BpiClient::new();
75
76        bpi.article_delete(TEST_AID).await?;
77
78        Ok(())
79    }
80}