Skip to main content

ncm_api_rs/api/
aidj_content_rcmd.rs

1use super::Query;
2use crate::error::Result;
3/// 私人 DJ
4/// 对应 Node.js module/aidj_content_rcmd.js
5use crate::request::{ApiClient, ApiResponse, CryptoType};
6use serde_json::json;
7use std::time::{SystemTime, UNIX_EPOCH};
8
9impl ApiClient {
10    /// 私人 DJ
11    /// 对应 /aidj/content/rcmd
12    pub async fn aidj_content_rcmd(&self, query: &Query) -> Result<ApiResponse> {
13        let now = SystemTime::now()
14            .duration_since(UNIX_EPOCH)
15            .unwrap_or_default();
16        let timestamp_ms = now.as_millis() as u64;
17        let timestamp_s = now.as_secs();
18
19        let mut ext_info = json!({
20            "noAidjToAidj": false,
21            "lastRequestTimestamp": timestamp_ms,
22            "listenedTs": false
23        });
24
25        if let Some(latitude) = query.get("latitude") {
26            if let Some(longitude) = query.get("longitude") {
27                ext_info["lbsInfoList"] = json!([{
28                    "lat": latitude,
29                    "lon": longitude,
30                    "time": timestamp_s
31                }]);
32            }
33        }
34
35        let data = json!({
36            "extInfo": ext_info.to_string()
37        });
38        self.request(
39            "/api/aidj/content/rcmd/info",
40            data,
41            query.to_option(CryptoType::Eapi),
42        )
43        .await
44    }
45}