From 81f411272f9dbff407710d0703d2294e161dd359 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 13 Dec 2024 19:49:56 -0800 Subject: [PATCH] rbx_asset keep typed UploadResponse --- rbx_asset/src/cookie.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/rbx_asset/src/cookie.rs b/rbx_asset/src/cookie.rs index 6881c31..14c677f 100644 --- a/rbx_asset/src/cookie.rs +++ b/rbx_asset/src/cookie.rs @@ -58,7 +58,12 @@ impl std::fmt::Display for UploadError{ } } impl std::error::Error for UploadError{} -type UploadResponse=u64; +type RobloxUploadResponse=u64; +#[derive(Debug,serde::Deserialize,serde::Serialize)] +#[allow(nonstandard_style,dead_code)] +pub struct UploadResponse{ + pub AssetId:u64, +} #[allow(nonstandard_style,dead_code)] pub struct GetAssetRequest{ @@ -267,11 +272,14 @@ impl CookieContext{ query.append_pair("groupId",group_id.to_string().as_str()); } } - - crate::response_ok( + let asset_id=crate::response_ok( self.post(url,body).await.map_err(CreateError::PostError)? ).await.map_err(CreateError::Response)? - .json::().await.map_err(CreateError::Reqwest) + .json::().await.map_err(CreateError::Reqwest)?; + + Ok(UploadResponse{ + AssetId:asset_id, + }) } pub async fn upload(&self,config:UploadRequest,body:impl Into+Clone)->Result{ let mut url=reqwest::Url::parse("https://data.roblox.com/Data/Upload.ashx?json=1&type=Model&genreTypeId=1").map_err(UploadError::ParseError)?; @@ -299,11 +307,14 @@ impl CookieContext{ query.append_pair("groupId",group_id.to_string().as_str()); } } - - crate::response_ok( + let asset_id=crate::response_ok( self.post(url,body).await.map_err(UploadError::PostError)? ).await.map_err(UploadError::Response)? - .json::().await.map_err(UploadError::Reqwest) + .json::().await.map_err(UploadError::Reqwest)?; + + Ok(UploadResponse{ + AssetId:asset_id, + }) } pub async fn get_asset(&self,config:GetAssetRequest)->Result,GetError>{ let mut url=reqwest::Url::parse("https://assetdelivery.roblox.com/v1/asset/").map_err(GetError::ParseError)?;