diff --git a/rbx_asset/src/cloud.rs b/rbx_asset/src/cloud.rs index 2c8f659..dd7c2f2 100644 --- a/rbx_asset/src/cloud.rs +++ b/rbx_asset/src/cloud.rs @@ -178,6 +178,23 @@ impl std::fmt::Display for GetError{ } impl std::error::Error for GetError{} +#[derive(Debug,serde::Deserialize)] +#[allow(nonstandard_style,dead_code)] +pub struct AssetLocation{ + // this field is private so users cannot mutate it + location:String, + pub requestId:String, + pub IsHashDynamic:bool, + pub IsCopyrightProtected:bool, + pub isArchived:bool, + pub assetTypeId:u32, +} +impl AssetLocation{ + pub fn location(&self)->&str{ + &self.location + } +} + pub struct AssetVersionsRequest{ pub asset_id:u64, pub cursor:Option<String>, @@ -407,31 +424,33 @@ impl Context{ ).await.map_err(GetError::Response)? .json::<AssetResponse>().await.map_err(GetError::Reqwest) } - pub async fn get_asset(&self,config:GetAssetLatestRequest)->Result<Vec<u8>,GetError>{ + pub async fn get_asset_location(&self,config:GetAssetLatestRequest)->Result<AssetLocation,GetError>{ let raw_url=format!("https://apis.roblox.com/asset-delivery-api/v1/assetId/{}",config.asset_id); let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?; - let body=crate::response_ok( + crate::response_ok( self.get(url).await.map_err(GetError::Reqwest)? ).await.map_err(GetError::Response)? - .bytes().await.map_err(GetError::Reqwest)?; - - match maybe_gzip_decode(&mut std::io::Cursor::new(body)){ - Ok(ReaderType::GZip(readable))=>read_readable(readable), - Ok(ReaderType::Raw(readable))=>read_readable(readable), - Err(e)=>Err(e), - }.map_err(GetError::IO) + .json().await.map_err(GetError::Reqwest) } - pub async fn get_asset_version(&self,config:GetAssetVersionRequest)->Result<Vec<u8>,GetError>{ + pub async fn get_asset_version_location(&self,config:GetAssetVersionRequest)->Result<AssetLocation,GetError>{ let raw_url=format!("https://apis.roblox.com/asset-delivery-api/v1/assetId/{}/version/{}",config.asset_id,config.version); let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?; + crate::response_ok( + self.get(url).await.map_err(GetError::Reqwest)? + ).await.map_err(GetError::Response)? + .json().await.map_err(GetError::Reqwest) + } + pub async fn get_asset(&self,config:&AssetLocation)->Result<Vec<u8>,GetError>{ + let url=reqwest::Url::parse(config.location.as_str()).map_err(GetError::ParseError)?; + let body=crate::response_ok( self.get(url).await.map_err(GetError::Reqwest)? ).await.map_err(GetError::Response)? .bytes().await.map_err(GetError::Reqwest)?; - match maybe_gzip_decode(&mut std::io::Cursor::new(body)){ + match maybe_gzip_decode(std::io::Cursor::new(body)){ Ok(ReaderType::GZip(readable))=>read_readable(readable), Ok(ReaderType::Raw(readable))=>read_readable(readable), Err(e)=>Err(e),