Skip to main content

bpi_rs/creativecenter/
opus.rs

1//! 创作中心作品管理 API
2//!
3//! [参考文档](https://github.com/Yuelioi/bilibili-API-collect/tree/cfc5fddcc8a94b74d91970bb5b4eaeb349addc47/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/Yuelioi/bilibili-API-collect/tree/cfc5fddcc8a94b74d91970bb5b4eaeb349addc47/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
25            .post("https://api.bilibili.com/x/dynamic/feed/operate/remove")
26            .query(&[("csrf", csrf)])
27            .json(&json!({
28              "dyn_id_str": dyn_id
29            }))
30            .send_bpi("删除动态").await
31    }
32
33    /// 删除专栏
34    ///
35    /// # 参数
36    /// | 名称 | 类型 | 说明 |
37    /// | ---- | ---- | ---- |
38    /// | `aid` | u64 | 专栏文章 ID |
39    ///
40    /// # 文档
41    /// [删除专栏](https://github.com/Yuelioi/bilibili-API-collect/tree/cfc5fddcc8a94b74d91970bb5b4eaeb349addc47/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
49            .post("https://member.bilibili.com/x/web/article/delete")
50            .form(
51                &[
52                    ("aid", aid.to_string()),
53                    ("csrf", csrf),
54                ]
55            )
56            .send_bpi("删除专栏").await
57    }
58}
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    const TEST_DYN_ID: &str = "951560312615600129";
65    const TEST_AID: u64 = 42997969;
66
67    #[ignore]
68    #[tokio::test]
69    async fn test_dynamic_delete() -> Result<(), Box<BpiError>> {
70        let bpi = BpiClient::new();
71
72        bpi.dynamic_delete(TEST_DYN_ID).await?;
73
74        Ok(())
75    }
76    #[ignore]
77    #[tokio::test]
78    async fn test_article_delete() -> Result<(), Box<BpiError>> {
79        let bpi = BpiClient::new();
80
81        bpi.article_delete(TEST_AID).await?;
82
83        Ok(())
84    }
85}