From 04d092c76fc5fc68a93dea92c300a0302de5c995 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 10 Jul 2024 08:35:13 -0700 Subject: [PATCH 1/4] rename limited commands --- src/main.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index e356e80..eb925da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,8 +24,8 @@ enum Commands{ Download(DownloadSubcommand), DownloadDecompile(DownloadDecompileSubcommand), DownloadGroupInventoryJson(DownloadGroupInventoryJsonSubcommand), - CreateAsset(CreateAssetSubcommand), - UploadAsset(UpdateAssetSubcommand), + CreateAssetMedia(CreateAssetMediaSubcommand), + UploadAssetMedia(UpdateAssetMediaSubcommand), UploadPlace(UpdatePlaceSubcommand), Compile(CompileSubcommand), CompileUploadAsset(CompileUploadAssetSubcommand), @@ -81,7 +81,7 @@ struct DownloadGroupInventoryJsonSubcommand{ group:u64, } #[derive(Args)] -struct CreateAssetSubcommand{ +struct CreateAssetMediaSubcommand{ #[arg(long,group="api_key",required=true)] api_key_literal:Option, #[arg(long,group="api_key",required=true)] @@ -100,7 +100,7 @@ struct CreateAssetSubcommand{ creator_group_id:Option, } #[derive(Args)] -struct UpdateAssetSubcommand{ +struct UpdateAssetMediaSubcommand{ #[arg(long)] asset_id:AssetID, #[arg(long,group="api_key",required=true)] @@ -326,7 +326,7 @@ async fn main()->AResult<()>{ subcommand.group, subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()), ).await, - Commands::CreateAsset(subcommand)=>create(CreateConfig{ + Commands::CreateAssetMedia(subcommand)=>create_asset_media(CreateAssetMediaConfig{ api_key:api_key_from_args( subcommand.api_key_literal, subcommand.api_key_envvar, @@ -338,7 +338,7 @@ async fn main()->AResult<()>{ model_name:subcommand.model_name, description:subcommand.description.unwrap_or_else(||String::with_capacity(0)), }).await, - Commands::UploadAsset(subcommand)=>upload_asset(UploadAssetConfig{ + Commands::UploadAssetMedia(subcommand)=>upload_asset_media(UploadAssetMediaConfig{ api_key:api_key_from_args( subcommand.api_key_literal, subcommand.api_key_envvar, @@ -441,7 +441,7 @@ async fn api_key_from_args(literal:Option,environment:Option,fil Ok(ApiKey::new(api_key)) } -struct CreateConfig{ +struct CreateAssetMediaConfig{ api_key:ApiKey, model_name:String, description:String, @@ -451,7 +451,7 @@ struct CreateConfig{ } ///This is hardcoded to create models atm -async fn create(config:CreateConfig)->AResult<()>{ +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, @@ -469,12 +469,12 @@ async fn create(config:CreateConfig)->AResult<()>{ Ok(()) } -struct UploadAssetConfig{ +struct UploadAssetMediaConfig{ api_key:ApiKey, asset_id:u64, input_file:PathBuf, } -async fn upload_asset(config:UploadAssetConfig)->AResult<()>{ +async fn upload_asset_media(config:UploadAssetMediaConfig)->AResult<()>{ let context=CloudContext::new(config.api_key); let resp=context.update_asset(rbx_asset::cloud::UpdateAssetRequest{ assetId:config.asset_id, From 8222cb34579a5becfa0e9cd18b33ae85cb1bc02c Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 10 Jul 2024 09:24:18 -0700 Subject: [PATCH 2/4] don't hard code asset type, expected price --- src/main.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index eb925da..d6a0d48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, + /// Expected price limits how much robux can be spent to create the asset (defaults to 0) + #[arg(long)] + expected_price:Option, } #[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,environment:Option,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, + expected_price:Option, } -///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); From b1a118c29e37495bd6bed4be9b288a2a3effbbe1 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 10 Jul 2024 09:08:16 -0700 Subject: [PATCH 3/4] add old asset api --- src/main.rs | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/src/main.rs b/src/main.rs index d6a0d48..7e7b636 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,9 @@ enum Commands{ Download(DownloadSubcommand), DownloadDecompile(DownloadDecompileSubcommand), DownloadGroupInventoryJson(DownloadGroupInventoryJsonSubcommand), + CreateAsset(CreateAssetSubcommand), CreateAssetMedia(CreateAssetMediaSubcommand), + UploadAsset(UpdateAssetSubcommand), UploadAssetMedia(UpdateAssetMediaSubcommand), UploadPlace(UpdatePlaceSubcommand), Compile(CompileSubcommand), @@ -81,6 +83,27 @@ struct DownloadGroupInventoryJsonSubcommand{ group:u64, } #[derive(Args)] +struct CreateAssetSubcommand{ + #[arg(long,group="cookie",required=true)] + cookie_literal:Option, + #[arg(long,group="cookie",required=true)] + cookie_envvar:Option, + #[arg(long,group="cookie",required=true)] + cookie_file:Option, + #[arg(long)] + group_id:Option, + #[arg(long)] + input_file:PathBuf, + #[arg(long)] + model_name:String, + #[arg(long)] + description:Option, + #[arg(long)] + free_model:Option, + #[arg(long)] + allow_comments:Option, +} +#[derive(Args)] struct CreateAssetMediaSubcommand{ #[arg(long,group="api_key",required=true)] api_key_literal:Option, @@ -105,6 +128,29 @@ struct CreateAssetMediaSubcommand{ expected_price:Option, } #[derive(Args)] +struct UpdateAssetSubcommand{ + #[arg(long)] + asset_id:AssetID, + #[arg(long,group="cookie",required=true)] + cookie_literal:Option, + #[arg(long,group="cookie",required=true)] + cookie_envvar:Option, + #[arg(long,group="cookie",required=true)] + cookie_file:Option, + #[arg(long)] + group_id:Option, + #[arg(long)] + input_file:PathBuf, + #[arg(long)] + change_name:Option, + #[arg(long)] + change_description:Option, + #[arg(long)] + change_free_model:Option, + #[arg(long)] + change_allow_comments:Option, +} +#[derive(Args)] struct UpdateAssetMediaSubcommand{ #[arg(long)] asset_id:AssetID, @@ -346,6 +392,19 @@ async fn main()->AResult<()>{ subcommand.group, subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()), ).await, + Commands::CreateAsset(subcommand)=>create_asset(CreateAssetConfig{ + cookie:cookie_from_args( + subcommand.cookie_literal, + subcommand.cookie_envvar, + subcommand.cookie_file, + ).await?, + group:subcommand.group_id, + input_file:subcommand.input_file, + model_name:subcommand.model_name, + description:subcommand.description.unwrap_or_else(||String::with_capacity(0)), + free_model:subcommand.free_model.unwrap_or(false), + allow_comments:subcommand.allow_comments.unwrap_or(false), + }).await, Commands::CreateAssetMedia(subcommand)=>create_asset_media(CreateAssetMediaConfig{ api_key:api_key_from_args( subcommand.api_key_literal, @@ -360,6 +419,20 @@ async fn main()->AResult<()>{ description:subcommand.description.unwrap_or_else(||String::with_capacity(0)), expected_price:subcommand.expected_price, }).await, + Commands::UploadAsset(subcommand)=>upload_asset(UploadAssetConfig{ + cookie:cookie_from_args( + subcommand.cookie_literal, + subcommand.cookie_envvar, + subcommand.cookie_file, + ).await?, + asset_id:subcommand.asset_id, + group_id:subcommand.group_id, + input_file:subcommand.input_file, + change_name:subcommand.change_name, + change_description:subcommand.change_description, + change_free_model:subcommand.change_free_model, + change_allow_comments:subcommand.change_allow_comments, + }).await, Commands::UploadAssetMedia(subcommand)=>upload_asset_media(UploadAssetMediaConfig{ api_key:api_key_from_args( subcommand.api_key_literal, @@ -463,6 +536,29 @@ async fn api_key_from_args(literal:Option,environment:Option,fil Ok(ApiKey::new(api_key)) } +struct CreateAssetConfig{ + cookie:Cookie, + model_name:String, + description:String, + input_file:PathBuf, + group:Option, + free_model:bool, + allow_comments:bool, +} + +async fn create_asset(config:CreateAssetConfig)->AResult<()>{ + let resp=CookieContext::new(config.cookie) + .create(rbx_asset::cookie::CreateRequest{ + name:config.model_name, + description:config.description, + ispublic:config.free_model, + allowComments:config.allow_comments, + groupId:config.group, + },tokio::fs::read(config.input_file).await?).await?; + println!("UploadResponse={:?}",resp); + Ok(()) +} + struct CreateAssetMediaConfig{ api_key:ApiKey, asset_type:rbx_asset::cloud::AssetType, @@ -492,6 +588,30 @@ async fn create_asset_media(config:CreateAssetMediaConfig)->AResult<()>{ Ok(()) } +struct UploadAssetConfig{ + cookie:Cookie, + asset_id:AssetID, + change_name:Option, + change_description:Option, + change_free_model:Option, + change_allow_comments:Option, + group_id:Option, + input_file:PathBuf, +} +async fn upload_asset(config:UploadAssetConfig)->AResult<()>{ + let context=CookieContext::new(config.cookie); + let resp=context.upload(rbx_asset::cookie::UploadRequest{ + assetid:config.asset_id, + name:config.change_name, + description:config.change_description, + ispublic:config.change_free_model, + allowComments:config.change_allow_comments, + groupId:config.group_id, + },tokio::fs::read(config.input_file).await?).await?; + println!("UploadResponse={:?}",resp); + Ok(()) +} + struct UploadAssetMediaConfig{ api_key:ApiKey, asset_id:u64, From 6111ebd0fef43fa364873b4b7f1847c7dc0d40c8 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 10 Jul 2024 09:38:31 -0700 Subject: [PATCH 4/4] v0.4.2 old asset api --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45cbe51..7f5bcaf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,7 +110,7 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "asset-tool" -version = "0.4.1" +version = "0.4.2" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 131bdda..a51cd1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ workspace = { members = ["rbx_asset", "rox_compiler"] } [package] name = "asset-tool" -version = "0.4.1" +version = "0.4.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html