use crate::utils::create_reqwest_client; use crate::ErrorString; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] pub struct Search { pub result: SearchResult, } #[derive(Serialize, Deserialize, Debug)] pub struct SearchResult { pub songs: Vec, } #[derive(Serialize, Deserialize, Debug)] pub struct SearchResultSong { pub id: i64, pub name: String, pub artists: Vec, pub duration: u64, } #[derive(Serialize, Deserialize, Debug)] pub struct SearchResultSongArtist { pub name: String, } pub async fn search(keyword: String) -> Result, ErrorString> { let client = create_reqwest_client().await?; let resp = client .get(format!( "https://163.genshinmc.eu.org/search?keywords={}&limit=20", urlencoding::encode(keyword.as_str()) )) .send() .await .map_err(|e| format!("请求错误: {}", e))?; let json: Search = resp.json().await.map_err(|e| format!("解析错误: {}", e))?; Ok(json.result.songs) }