CLI tool for migrating PDS

Fix blob migration

+59 -26
+59 -26
src/main.rs
··· 2 2 agent::atp_agent::{store::MemorySessionStore, AtpAgent}, 3 3 app::bsky::actor::{get_preferences, put_preferences}, 4 4 com::atproto::{ 5 + repo::list_missing_blobs, 5 6 server::{create_account, get_service_auth}, 6 7 sync::{get_blob, get_repo, list_blobs}, 7 8 }, ··· 9 10 }; 10 11 use atrium_xrpc_client::reqwest::ReqwestClient; 11 12 use std::{ 12 - io::{self, Write}, 13 - sync::Arc, 13 + io::{self, Write}, sync::Arc 14 14 }; 15 15 16 16 mod jwt; ··· 246 246 } 247 247 }; 248 248 249 - while listed_blobs.cursor.is_some() { 249 + for cid in listed_blobs.cids.iter() { 250 + let blob = match old_agent 251 + .api 252 + .com 253 + .atproto 254 + .sync 255 + .get_blob( 256 + get_blob::ParametersData { 257 + cid: cid.to_owned(), 258 + did: old_agent.did().await.unwrap(), 259 + } 260 + .into(), 261 + ) 262 + .await 263 + { 264 + Ok(response) => response, 265 + Err(err) => { 266 + println!("com.atproto.sync.getBlob at current PDS failed due to error: {err}"); 267 + return; 268 + } 269 + }; 270 + 271 + match new_agent.api.com.atproto.repo.upload_blob(blob).await { 272 + Ok(_) => (), 273 + Err(err) => { 274 + println!("com.atproto.repo.uploadBlob at new PDS failed due to error: {err}"); 275 + return; 276 + } 277 + }; 278 + } 279 + 280 + let mut cursor = listed_blobs.cursor.clone(); 281 + while cursor.is_some() { 282 + listed_blobs = match old_agent 283 + .api 284 + .com 285 + .atproto 286 + .sync 287 + .list_blobs( 288 + list_blobs::ParametersData { 289 + cursor: cursor.clone(), 290 + did: old_agent.did().await.unwrap(), 291 + limit: None, 292 + since: None, 293 + } 294 + .into(), 295 + ) 296 + .await 297 + { 298 + Ok(response) => response, 299 + Err(err) => { 300 + println!("com.atproto.sync.listBlobs at old PDS failed due to error: {err}"); 301 + return; 302 + } 303 + }; 304 + 250 305 for cid in listed_blobs.cids.iter() { 251 306 let blob = match old_agent 252 307 .api ··· 277 332 } 278 333 }; 279 334 } 280 - 281 - listed_blobs = match old_agent 282 - .api 283 - .com 284 - .atproto 285 - .sync 286 - .list_blobs( 287 - list_blobs::ParametersData { 288 - cursor: listed_blobs.cursor.clone(), 289 - did: old_agent.did().await.unwrap(), 290 - limit: None, 291 - since: None, 292 - } 293 - .into(), 294 - ) 295 - .await 296 - { 297 - Ok(response) => response, 298 - Err(err) => { 299 - println!("com.atproto.sync.listBlobs at old PDS failed due to error: {err}"); 300 - return; 301 - } 302 - }; 335 + cursor = listed_blobs.cursor.clone(); 303 336 } 304 337 println!("Blobs successfully migrated!"); 305 338