1use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
6use serde::{ Deserialize, Serialize };
7
8#[derive(Debug, Clone, Deserialize, Serialize)]
10pub struct SpaceCover {
11 pub height: u32,
13 pub url: String,
15 pub width: u32,
17}
18
19#[derive(Debug, Clone, Deserialize, Serialize)]
21pub struct SpaceStat {
22 pub like: String,
24 pub view: Option<String>,
26}
27
28#[derive(Debug, Clone, Deserialize, Serialize)]
30pub struct SpaceItem {
31 pub content: String,
33 pub cover: Option<SpaceCover>,
35 pub jump_url: String,
37 pub opus_id: String,
39 pub stat: SpaceStat,
41}
42
43#[derive(Debug, Clone, Deserialize, Serialize)]
45pub struct SpaceData {
46 pub has_more: bool,
48 pub items: Vec<SpaceItem>,
50 pub offset: String,
52 pub update_num: u32,
54}
55
56impl BpiClient {
57 pub async fn opus_space_feed(
71 &self,
72 mid: u64,
73 page: Option<u32>,
74 offset: Option<&str>,
75 typ: Option<&str> ) -> Result<BpiResponse<SpaceData>, BpiError> {
77 let query = vec![
78 ("host_mid", mid.to_string()),
79 ("page", page.unwrap_or(0).to_string()),
80 ("offset", offset.unwrap_or("").to_string()),
81 ("type", typ.unwrap_or("all").to_string()),
82 ("web_location", "333.1387".to_string())
83 ];
84
85 self
86 .get("https://api.bilibili.com/x/polymer/web-dynamic/v1/opus/feed/space")
87 .query(&query)
88 .send_bpi("获取用户空间图文").await
89 }
90}
91
92#[cfg(test)]
93mod tests {
94 use super::*;
95 use tracing::info;
96
97 #[tokio::test]
98 async fn test_opus_space_feed() {
99 let bpi = BpiClient::new();
100 let resp = bpi.opus_space_feed(4279370, Some(1), None, None).await;
101 assert!(resp.is_ok());
102 if let Ok(r) = resp {
103 info!("空间图文返回: {:?}", r);
104 }
105 }
106}