From 67c0a2b4a09a630f311c2328835df45d96991486 Mon Sep 17 00:00:00 2001 From: Momentry Studio Date: Sun, 14 Jun 2026 19:55:52 +0800 Subject: [PATCH] fix: get_people fetch all pages to include main characters --- src-tauri/src/main.rs | 49 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 912b610..f0b4ec4 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -147,31 +147,36 @@ async fn get_files(args: GetFilesArgs) -> Result, String> { } #[tauri::command(rename_all = "camelCase")] -async fn get_people(page: usize, per_page: usize) -> Result, String> { - eprintln!("[get_people] page={} per_page={}", page, per_page); +async fn get_people(_page: usize, _per_page: usize) -> Result, String> { let client = reqwest::Client::new(); - let url = format!("{}/api/v1/identities?api_key={}&page={}&per_page={}", CORE_API, API_KEY, page, per_page); - eprintln!("[get_people] url={}", url); + let mut all_people = Vec::new(); + let mut page = 1; - let response = client.get(&url).send().await.map_err(|e| format!("Request failed: {}", e))?; - let json: serde_json::Value = response.json().await.map_err(|e| format!("Parse failed: {}", e))?; - eprintln!("[get_people] identities count: {}", json["identities"].as_array().map(|a| a.len()).unwrap_or(0)); + loop { + let url = format!("{}/api/v1/identities?api_key={}&page={}&per_page=50", CORE_API, API_KEY, page); + let response = client.get(&url).send().await.map_err(|e| format!("Request failed: {}", e))?; + let json: serde_json::Value = response.json().await.map_err(|e| format!("Parse failed: {}", e))?; + + let identities = json["identities"].as_array(); + let identities = identities.as_ref().map(|v| v.as_slice()).unwrap_or(&[]); + if identities.is_empty() { break; } + + for i in identities { + if let (Some(uuid), Some(name)) = (i["identity_uuid"].as_str(), i["name"].as_str()) { + all_people.push(PersonInfo { + identity_uuid: uuid.to_string(), + name: name.to_string(), + starred: i["metadata"]["starred"].as_bool().unwrap_or(false), + }); + } + } + + if identities.len() < 50 { break; } + page += 1; + } - let people: Vec = json["identities"] - .as_array() - .unwrap_or(&vec![]) - .iter() - .filter_map(|i| { - Some(PersonInfo { - identity_uuid: i["identity_uuid"].as_str()?.to_string(), - name: i["name"].as_str()?.to_string(), - starred: i["metadata"]["starred"].as_bool().unwrap_or(false), - }) - }) - .collect(); - - eprintln!("[get_people] returning {} people", people.len()); - Ok(people) + eprintln!("[get_people] returning {} people from {} pages", all_people.len(), page); + Ok(all_people) } #[tauri::command(rename_all = "camelCase")]