don't hard code asset type, expected price

This commit is contained in:
Quaternions 2024-07-10 09:24:18 -07:00
parent 04d092c76f
commit 8222cb3457

View File

@ -95,9 +95,14 @@ struct CreateAssetMediaSubcommand{
#[arg(long)]
input_file:PathBuf,
#[arg(long)]
asset_type:AssetType,
#[arg(long)]
creator_user_id:u64,
#[arg(long)]
creator_group_id:Option<u64>,
/// Expected price limits how much robux can be spent to create the asset (defaults to 0)
#[arg(long)]
expected_price:Option<u64>,
}
#[derive(Args)]
struct UpdateAssetMediaSubcommand{
@ -270,6 +275,21 @@ impl Style{
}
}
}
#[derive(Clone,Copy,Debug,clap::ValueEnum)]
enum AssetType{
Audio,
Decal,
Model,
}
impl AssetType{
fn cloud(&self)->rbx_asset::cloud::AssetType{
match self{
AssetType::Audio=>rbx_asset::cloud::AssetType::Audio,
AssetType::Decal=>rbx_asset::cloud::AssetType::Decal,
AssetType::Model=>rbx_asset::cloud::AssetType::Model,
}
}
}
#[tokio::main]
async fn main()->AResult<()>{
@ -335,8 +355,10 @@ async fn main()->AResult<()>{
creator_user_id:subcommand.creator_user_id,
creator_group_id:subcommand.creator_group_id,
input_file:subcommand.input_file,
asset_type:subcommand.asset_type.cloud(),
model_name:subcommand.model_name,
description:subcommand.description.unwrap_or_else(||String::with_capacity(0)),
expected_price:subcommand.expected_price,
}).await,
Commands::UploadAssetMedia(subcommand)=>upload_asset_media(UploadAssetMediaConfig{
api_key:api_key_from_args(
@ -443,18 +465,19 @@ async fn api_key_from_args(literal:Option<String>,environment:Option<String>,fil
struct CreateAssetMediaConfig{
api_key:ApiKey,
asset_type:rbx_asset::cloud::AssetType,
model_name:String,
description:String,
input_file:PathBuf,
creator_user_id:u64,
creator_group_id:Option<u64>,
expected_price:Option<u64>,
}
///This is hardcoded to create models atm
async fn create_asset_media(config:CreateAssetMediaConfig)->AResult<()>{
let resp=CloudContext::new(config.api_key)
.create_asset(rbx_asset::cloud::CreateAssetRequest{
assetType:rbx_asset::cloud::AssetType::Model,
assetType:config.asset_type,
displayName:config.model_name,
description:config.description,
creationContext:rbx_asset::cloud::CreationContext{
@ -462,7 +485,7 @@ async fn create_asset_media(config:CreateAssetMediaConfig)->AResult<()>{
userId:config.creator_user_id,
groupId:config.creator_group_id.unwrap_or(0),
},
expectedPrice:0,
expectedPrice:config.expected_price.unwrap_or(0),
}
},tokio::fs::read(config.input_file).await?).await?;
println!("CreateResponse={:?}",resp);