fix gpt memory dl
This commit is contained in:
@@ -51,6 +51,47 @@ pub async fn get_memory(download: bool) -> Result<()> {
|
||||
let pds = session.pds.as_deref().unwrap_or("bsky.social");
|
||||
let client = XrpcClient::new_bot(pds);
|
||||
|
||||
if download {
|
||||
// Download all memory records
|
||||
let mut cursor: Option<String> = None;
|
||||
let mut count = 0;
|
||||
|
||||
loop {
|
||||
let mut params: Vec<(&str, &str)> = vec![
|
||||
("repo", &session.did),
|
||||
("collection", COLLECTION_MEMORY),
|
||||
("limit", "100"),
|
||||
];
|
||||
let cursor_val;
|
||||
if let Some(ref c) = cursor {
|
||||
cursor_val = c.clone();
|
||||
params.push(("cursor", &cursor_val));
|
||||
}
|
||||
|
||||
let result: ListRecordsResponse = client
|
||||
.query_auth(
|
||||
&com_atproto_repo::LIST_RECORDS,
|
||||
¶ms,
|
||||
&session.access_jwt,
|
||||
)
|
||||
.await?;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -64,20 +105,8 @@ pub async fn get_memory(download: bool) -> Result<()> {
|
||||
)
|
||||
.await?;
|
||||
|
||||
let record = result
|
||||
.records
|
||||
.first()
|
||||
.context("No memory records found")?;
|
||||
|
||||
let record = result.records.first().context("No memory records found")?;
|
||||
println!("{}", serde_json::to_string_pretty(&record.value)?);
|
||||
|
||||
if download {
|
||||
let rkey = record
|
||||
.uri
|
||||
.split('/')
|
||||
.next_back()
|
||||
.unwrap_or("unknown");
|
||||
save_record(&session.did, COLLECTION_MEMORY, rkey, record)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user