use cloud api for get_asset in cloud api module

This commit is contained in:
Quaternions 2024-07-16 10:10:05 -07:00
parent 2d2ebcece0
commit 7063b20c20

View File

@ -279,16 +279,11 @@ impl CloudContext{
Ok(resp.json::<RobloxOperation>().await.map_err(UpdateError::Reqwest)?) Ok(resp.json::<RobloxOperation>().await.map_err(UpdateError::Reqwest)?)
} }
pub async fn get_asset(&self,config:GetAssetRequest)->Result<Vec<u8>,GetError>{ pub async fn get_asset(&self,config:GetAssetRequest)->Result<Vec<u8>,GetError>{
let mut url=reqwest::Url::parse("https://assetdelivery.roblox.com/v1/asset/").map_err(GetError::ParseError)?; let raw_url=match config.version{
//url borrow scope Some(version)=>format!("https://apis.roblox.com/assets/v1/assets/{}/versions/{version}",config.asset_id),
{ None=>format!("https://apis.roblox.com/assets/v1/assets/{}",config.asset_id),
let mut query=url.query_pairs_mut();//borrow here };
query.append_pair("ID",config.asset_id.to_string().as_str()); let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
if let Some(version)=config.version{
query.append_pair("version",version.to_string().as_str());
}
}
let resp=self.get(url).await.map_err(GetError::Reqwest)?;
let body=self.get(url).await.map_err(GetError::Reqwest)? let body=self.get(url).await.map_err(GetError::Reqwest)?
.error_for_status().map_err(GetError::Reqwest)? .error_for_status().map_err(GetError::Reqwest)?