fix: get_people fetch all pages to include main characters
This commit is contained in:
@@ -147,31 +147,36 @@ async fn get_files(args: GetFilesArgs) -> Result<Vec<FileInfo>, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command(rename_all = "camelCase")]
|
#[tauri::command(rename_all = "camelCase")]
|
||||||
async fn get_people(page: usize, per_page: usize) -> Result<Vec<PersonInfo>, String> {
|
async fn get_people(_page: usize, _per_page: usize) -> Result<Vec<PersonInfo>, String> {
|
||||||
eprintln!("[get_people] page={} per_page={}", page, per_page);
|
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let url = format!("{}/api/v1/identities?api_key={}&page={}&per_page={}", CORE_API, API_KEY, page, per_page);
|
let mut all_people = Vec::new();
|
||||||
eprintln!("[get_people] url={}", url);
|
let mut page = 1;
|
||||||
|
|
||||||
let response = client.get(&url).send().await.map_err(|e| format!("Request failed: {}", e))?;
|
loop {
|
||||||
let json: serde_json::Value = response.json().await.map_err(|e| format!("Parse failed: {}", e))?;
|
let url = format!("{}/api/v1/identities?api_key={}&page={}&per_page=50", CORE_API, API_KEY, page);
|
||||||
eprintln!("[get_people] identities count: {}", json["identities"].as_array().map(|a| a.len()).unwrap_or(0));
|
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"]
|
eprintln!("[get_people] returning {} people from {} pages", all_people.len(), page);
|
||||||
.as_array()
|
Ok(all_people)
|
||||||
.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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command(rename_all = "camelCase")]
|
#[tauri::command(rename_all = "camelCase")]
|
||||||
|
|||||||
Reference in New Issue
Block a user