Skip to main content

ncm_api_rs/api/
comment_info_list.rs

1use super::Query;
2use crate::error::Result;
3/// 评论统计数据
4/// 对应 Node.js module/comment_info_list.js
5use crate::request::{ApiClient, ApiResponse, CryptoType};
6use serde_json::json;
7
8impl ApiClient {
9    /// 评论统计数据
10    /// 对应 /comment/info/list
11    pub async fn comment_info_list(&self, query: &Query) -> Result<ApiResponse> {
12        let resource_type = query.get_or("type", "0");
13        let type_id = crate::util::config::RESOURCE_TYPE_MAP
14            .get(resource_type.as_str())
15            .map(|prefix| {
16                prefix
17                    .trim_end_matches('_')
18                    .rsplit('_')
19                    .next()
20                    .unwrap_or("0")
21                    .to_string()
22            })
23            .unwrap_or_else(|| "0".to_string());
24
25        let ids: Vec<String> = query
26            .get_or("ids", "")
27            .split(',')
28            .map(|s| s.trim().to_string())
29            .filter(|s| !s.is_empty())
30            .collect();
31        let data = json!({
32            "resourceType": type_id,
33            "resourceIds": serde_json::to_string(&ids).unwrap()
34        });
35        self.request(
36            "/api/resource/commentInfo/list",
37            data,
38            query.to_option(CryptoType::Weapi),
39        )
40        .await
41    }
42}