From 136dbb30548402ace90d81493b9f3ce62b786eef Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 16 Aug 2024 23:48:17 -0700 Subject: [PATCH] plumb path to the end in an ugly way (patches welcome) --- src/main.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0dacec2..ab0a9b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -727,6 +727,7 @@ async fn create_asset_medias(config:CreateAssetMediasConfig)->AResult<()>{ let description=&config.description; let creator=&config.creator; let context=&context; + async move{(path.clone(), async move{ let model_name=path.file_stem() .and_then(std::ffi::OsStr::to_str) @@ -752,20 +753,24 @@ async fn create_asset_medias(config:CreateAssetMediasConfig)->AResult<()>{ } },file).await.map_err(CreateAssetMediasError::Create) } + .await)} })) //parallel requests .buffer_unordered(CONCURRENT_REQUESTS) //step 2: poll operation until it completes - .then(|create_result|{ + .then(|(path,create_result)|{ let context=&context; + async{(path, async{ let create_asset_response=create_result.map_err(PollOperationError::CreateAssetMedias)?; get_asset_exp_backoff(context,&create_asset_response).await.map_err(PollOperationError::CreateAssetResponseGetAsset) } + .await)} }) //step 3: read decal id from operation and download it, decode it as a roblox file and extract the texture content url - .then(|asset_response_result|{ + .then(|(path,asset_response_result)|{ let cookie_context=&cookie_context; + async move{(path, async move{ let asset_response=asset_response_result.map_err(DownloadDecalError::PollOperation)?; let file=cookie_context.get_asset(rbx_asset::cookie::GetAssetRequest{ @@ -783,11 +788,12 @@ async fn create_asset_medias(config:CreateAssetMediasConfig)->AResult<()>{ }; Ok::<_,DownloadDecalError>((asset_response.displayName,asset_url)) } + .await)} }) - .for_each(|download_decal_result|async{ + .for_each(|(path,download_decal_result)|async move{ match download_decal_result{ Ok((file_name,asset_url))=>println!("{}={}",file_name,asset_url), - Err(e)=>eprintln!("ERROR error={e}"), + Err(e)=>eprintln!("ERROR file={:?} error={e}",path), } }).await; Ok(())