fix: get_people fetch all pages to include main characters

This commit is contained in:
2026-06-14 19:55:52 +08:00
parent aab35874e0
commit 67c0a2b4a0

View File

@@ -147,31 +147,36 @@ async fn get_files(args: GetFilesArgs) -> Result<Vec<FileInfo>, String> {
}
#[tauri::command(rename_all = "camelCase")]
async fn get_people(page: usize, per_page: usize) -> Result<Vec<PersonInfo>, String> {
eprintln!("[get_people] page={} per_page={}", page, per_page);
async fn get_people(_page: usize, _per_page: usize) -> Result<Vec<PersonInfo>, 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<PersonInfo> = 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")]