Skip to main content

bpi_rs/web_widget/
zone_upload.rs

1use serde::Deserialize;
2use std::collections::HashMap;
3
4use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
5
6/// 分区当日投稿稿件数信息
7/// 使用 `HashMap<u64, u64>` 存储,键为分区 ID,值为当日投稿数。
8#[derive(Debug, Clone, Deserialize)]
9pub struct OnlineRegionCount(pub HashMap<String, u64>);
10
11/// 分区当日投稿数数据
12#[derive(Debug, Clone, Deserialize)]
13pub struct OnlineData {
14    pub region_count: OnlineRegionCount,
15}
16
17impl BpiClient {
18    /// 获取分区当日投稿稿件数
19
20    pub async fn web_widget_online(&self) -> Result<BpiResponse<OnlineData>, BpiError> {
21        self
22            .get("https://api.bilibili.com/x/web-interface/online")
23            .send_bpi("获取分区当日投稿数").await
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30    use tracing::info;
31
32    #[tokio::test]
33    async fn test_get_online() {
34        let bpi = BpiClient::new();
35        let resp = bpi.web_widget_online().await;
36        info!("响应: {:?}", resp);
37        assert!(resp.is_ok());
38
39        if let Ok(data) = resp {
40            if let Some(counts) = data.data {
41                for (region_id, count) in counts.region_count.0 {
42                    info!("分区ID: {}, 投稿数: {}", region_id, count);
43                }
44            }
45        }
46    }
47}