From ae181fd40137bf7a82c8a1a712d220aa411dd566 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 25 Apr 2024 18:50:57 -0700 Subject: [PATCH] more options for create --- src/main.rs | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index a2b29fa..7d8506c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -79,9 +79,15 @@ struct CreateSubcommand{ #[arg(long)] model_name:String, #[arg(long)] + description:Option, + #[arg(long)] input_file:PathBuf, #[arg(long)] group:Option, + #[arg(long)] + free_model:Option, + #[arg(long)] + allow_comments:Option, } #[derive(Args)] struct UploadSubcommand{ @@ -247,12 +253,15 @@ async fn main()->AResult<()>{ subcommand.group, subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()), ).await, - Commands::Create(subcommand)=>create( - Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0, - subcommand.group, - subcommand.input_file, - subcommand.model_name, - ).await, + Commands::Create(subcommand)=>create(CreateConfig{ + cookie:Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0, + group:subcommand.group, + 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::Upload(subcommand)=>upload_list( Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0, subcommand.group, @@ -321,25 +330,38 @@ fn maybe_gzip_decode(input:R)->AResult>{ } } -async fn create(cookie:String,group:Option,file:PathBuf,model_name:String)->AResult<()>{ +struct CreateConfig{ + cookie:String, + model_name:String, + description:String, + input_file:PathBuf, + group:Option, + free_model:bool, + allow_comments:bool, +} + +async fn create(config:CreateConfig)->AResult<()>{ let client=reqwest::Client::new(); let client=&client; - let cookie=cookie.as_str(); - let group=&group; - let mut url=reqwest::Url::parse("https://data.roblox.com/Data/Upload.ashx?json=1&type=Model&genreTypeId=1&description&ispublic=False&allowComments=False")?; + let cookie=config.cookie.as_str(); + let group=&config.group; + let mut url=reqwest::Url::parse("https://data.roblox.com/Data/Upload.ashx?json=1&type=Model&genreTypeId=1")?; //url borrow scope { let mut query=url.query_pairs_mut();//borrow here //archaic roblox api uses 0 for new asset query.append_pair("assetid","0"); - query.append_pair("name",model_name.as_str()); + query.append_pair("name",config.model_name.as_str()); + query.append_pair("description",config.description.as_str()); + query.append_pair("ispublic",if config.free_model{"True"}else{"False"}); + query.append_pair("allowComments",if config.allow_comments{"True"}else{"False"}); match group{ Some(group_id)=>{query.append_pair("groupId",group_id.to_string().as_str());}, None=>(), } } - let body=tokio::fs::read(file).await?; + let body=tokio::fs::read(config.input_file).await?; let mut resp=client.post(url.clone()) .header("Cookie",cookie) .body(body.clone())