From 639d6196881f0c861165d34605c03a44b76be093 Mon Sep 17 00:00:00 2001 From: syui Date: Mon, 2 Mar 2026 15:53:13 +0900 Subject: [PATCH] fix gpt memory dl --- src/commands/gpt.rs | 73 +++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/src/commands/gpt.rs b/src/commands/gpt.rs index 74dd1ef..f5692c6 100644 --- a/src/commands/gpt.rs +++ b/src/commands/gpt.rs @@ -51,33 +51,62 @@ pub async fn get_memory(download: bool) -> Result<()> { let pds = session.pds.as_deref().unwrap_or("bsky.social"); let client = XrpcClient::new_bot(pds); - let result: ListRecordsResponse = client - .query_auth( - &com_atproto_repo::LIST_RECORDS, - &[ + if download { + // Download all memory records + let mut cursor: Option = None; + let mut count = 0; + + loop { + let mut params: Vec<(&str, &str)> = vec![ ("repo", &session.did), ("collection", COLLECTION_MEMORY), - ("limit", "1"), - ("reverse", "true"), - ], - &session.access_jwt, - ) - .await?; + ("limit", "100"), + ]; + let cursor_val; + if let Some(ref c) = cursor { + cursor_val = c.clone(); + params.push(("cursor", &cursor_val)); + } - let record = result - .records - .first() - .context("No memory records found")?; + let result: ListRecordsResponse = client + .query_auth( + &com_atproto_repo::LIST_RECORDS, + ¶ms, + &session.access_jwt, + ) + .await?; - println!("{}", serde_json::to_string_pretty(&record.value)?); + let batch = result.records.len(); + for record in &result.records { + let rkey = record.uri.split('/').next_back().unwrap_or("unknown"); + save_record(&session.did, COLLECTION_MEMORY, rkey, record)?; + count += 1; + } - if download { - let rkey = record - .uri - .split('/') - .next_back() - .unwrap_or("unknown"); - save_record(&session.did, COLLECTION_MEMORY, rkey, record)?; + match result.cursor { + Some(c) if batch > 0 => cursor = Some(c), + _ => break, + } + } + + println!("Downloaded {} memory records", count); + } else { + // Show latest only + let result: ListRecordsResponse = client + .query_auth( + &com_atproto_repo::LIST_RECORDS, + &[ + ("repo", &session.did), + ("collection", COLLECTION_MEMORY), + ("limit", "1"), + ("reverse", "true"), + ], + &session.access_jwt, + ) + .await?; + + let record = result.records.first().context("No memory records found")?; + println!("{}", serde_json::to_string_pretty(&record.value)?); } Ok(())