Skip to main content

ncm_api_rs/api/
resource_like.rs

1use super::Query;
2use crate::error::Result;
3/// 点赞与取消点赞资源
4/// 对应 Node.js module/resource_like.js
5use crate::request::{ApiClient, ApiResponse, CryptoType};
6use serde_json::json;
7
8impl ApiClient {
9    /// 点赞与取消点赞资源
10    /// 对应 /resource/like
11    pub async fn resource_like(&self, query: &Query) -> Result<ApiResponse> {
12        let t = if query.get_or("t", "0") == "1" {
13            "like"
14        } else {
15            "unlike"
16        };
17
18        let resource_type_prefix = match query.get_or("type", "0").as_str() {
19            "0" => "R_SO_4_",
20            "1" => "R_MV_5_",
21            "2" => "A_PL_0_",
22            "3" => "R_AL_3_",
23            "4" => "A_DJ_1_",
24            "5" => "R_VI_62_",
25            "6" => "A_EV_2_",
26            "7" => "A_DR_14_",
27            _ => "R_SO_4_",
28        };
29
30        let thread_id = if resource_type_prefix == "A_EV_2_" {
31            query.get_or("threadId", "").to_string()
32        } else {
33            format!("{}{}", resource_type_prefix, query.get_or("id", "0"))
34        };
35
36        let data = json!({
37            "threadId": thread_id
38        });
39        self.request(
40            &format!("/api/resource/{}", t),
41            data,
42            query.to_option(CryptoType::Weapi),
43        )
44        .await
45    }
46}