Create multiple assets concurrently #5
@ -88,7 +88,9 @@ impl std::fmt::Display for UpdateError{
|
|||||||
}
|
}
|
||||||
impl std::error::Error for UpdateError{}
|
impl std::error::Error for UpdateError{}
|
||||||
|
|
||||||
#[allow(nonstandard_style,dead_code)]
|
pub struct GetAssetOperationRequest{
|
||||||
|
pub operation_id:String,
|
||||||
|
}
|
||||||
pub struct GetAssetInfoRequest{
|
pub struct GetAssetInfoRequest{
|
||||||
pub asset_id:u64,
|
pub asset_id:u64,
|
||||||
}
|
}
|
||||||
@ -221,14 +223,46 @@ impl std::fmt::Display for InventoryPageError{
|
|||||||
}
|
}
|
||||||
impl std::error::Error for InventoryPageError{}
|
impl std::error::Error for InventoryPageError{}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum OperationError{
|
||||||
|
Get(GetError),
|
||||||
|
NoOperationId,
|
||||||
|
NotDone,
|
||||||
|
}
|
||||||
|
impl std::fmt::Display for OperationError{
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f,"{self:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl std::error::Error for OperationError{}
|
||||||
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||||
#[allow(nonstandard_style,dead_code)]
|
#[allow(nonstandard_style,dead_code)]
|
||||||
pub struct RobloxOperation{
|
pub struct RobloxOperation{
|
||||||
pub path:Option<std::path::PathBuf>,
|
pub path:Option<String>,
|
||||||
pub metadata:Option<String>,
|
pub metadata:Option<String>,
|
||||||
pub done:Option<bool>,
|
pub done:Option<bool>,
|
||||||
pub error:Option<String>,
|
pub error:Option<String>,
|
||||||
pub response:Option<String>,
|
pub response:Option<serde_json::Value>,
|
||||||
|
pub operationId:Option<String>,
|
||||||
|
}
|
||||||
|
impl RobloxOperation{
|
||||||
|
pub fn operation_id(&self)->Option<&str>{
|
||||||
|
match self.operationId.as_deref(){
|
||||||
|
//try getting it from undocumented operationId first
|
||||||
|
Some(operation_id)=>Some(operation_id),
|
||||||
|
//skip the first 11 characters
|
||||||
|
//operations/[uuid]
|
||||||
|
None=>self.path.as_deref()?.get(11..),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub async fn try_get_reponse(&self,context:&CloudContext)->Result<serde_json::Value,OperationError>{
|
||||||
|
context.get_asset_operation(GetAssetOperationRequest{
|
||||||
|
operation_id:self.operation_id()
|
||||||
|
.ok_or(OperationError::NoOperationId)?
|
||||||
|
.to_owned(),
|
||||||
|
}).await.map_err(OperationError::Get)?
|
||||||
|
.response.ok_or(OperationError::NotDone)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//idk how to do this better
|
//idk how to do this better
|
||||||
@ -330,6 +364,14 @@ impl CloudContext{
|
|||||||
.error_for_status().map_err(UpdateError::Reqwest)?
|
.error_for_status().map_err(UpdateError::Reqwest)?
|
||||||
.json::<RobloxOperation>().await.map_err(UpdateError::Reqwest)
|
.json::<RobloxOperation>().await.map_err(UpdateError::Reqwest)
|
||||||
}
|
}
|
||||||
|
pub async fn get_asset_operation(&self,config:GetAssetOperationRequest)->Result<RobloxOperation,GetError>{
|
||||||
|
let raw_url=format!("https://apis.roblox.com/assets/v1/operations/{}",config.operation_id);
|
||||||
|
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
||||||
|
|
||||||
|
self.get(url).await.map_err(GetError::Reqwest)?
|
||||||
|
.error_for_status().map_err(GetError::Reqwest)?
|
||||||
|
.json::<RobloxOperation>().await.map_err(GetError::Reqwest)
|
||||||
|
}
|
||||||
pub async fn get_asset_info(&self,config:GetAssetInfoRequest)->Result<AssetResponse,GetError>{
|
pub async fn get_asset_info(&self,config:GetAssetInfoRequest)->Result<AssetResponse,GetError>{
|
||||||
let raw_url=format!("https://apis.roblox.com/assets/v1/assets/{}",config.asset_id);
|
let raw_url=format!("https://apis.roblox.com/assets/v1/assets/{}",config.asset_id);
|
||||||
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user