more options for create

This commit is contained in:
Quaternions 2024-04-25 18:50:57 -07:00
parent 312c0e7cd9
commit ae181fd401

View File

@ -79,9 +79,15 @@ struct CreateSubcommand{
#[arg(long)] #[arg(long)]
model_name:String, model_name:String,
#[arg(long)] #[arg(long)]
description:Option<String>,
#[arg(long)]
input_file:PathBuf, input_file:PathBuf,
#[arg(long)] #[arg(long)]
group:Option<u64>, group:Option<u64>,
#[arg(long)]
free_model:Option<bool>,
#[arg(long)]
allow_comments:Option<bool>,
} }
#[derive(Args)] #[derive(Args)]
struct UploadSubcommand{ struct UploadSubcommand{
@ -247,12 +253,15 @@ async fn main()->AResult<()>{
subcommand.group, subcommand.group,
subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()), subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
).await, ).await,
Commands::Create(subcommand)=>create( Commands::Create(subcommand)=>create(CreateConfig{
Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0, cookie:Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
subcommand.group, group:subcommand.group,
subcommand.input_file, input_file:subcommand.input_file,
subcommand.model_name, model_name:subcommand.model_name,
).await, 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( Commands::Upload(subcommand)=>upload_list(
Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0, Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
subcommand.group, subcommand.group,
@ -321,25 +330,38 @@ fn maybe_gzip_decode<R:Read>(input:R)->AResult<ReaderType<R>>{
} }
} }
async fn create(cookie:String,group:Option<u64>,file:PathBuf,model_name:String)->AResult<()>{ struct CreateConfig{
cookie:String,
model_name:String,
description:String,
input_file:PathBuf,
group:Option<u64>,
free_model:bool,
allow_comments:bool,
}
async fn create(config:CreateConfig)->AResult<()>{
let client=reqwest::Client::new(); let client=reqwest::Client::new();
let client=&client; let client=&client;
let cookie=cookie.as_str(); let cookie=config.cookie.as_str();
let group=&group; let group=&config.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 mut url=reqwest::Url::parse("https://data.roblox.com/Data/Upload.ashx?json=1&type=Model&genreTypeId=1")?;
//url borrow scope //url borrow scope
{ {
let mut query=url.query_pairs_mut();//borrow here let mut query=url.query_pairs_mut();//borrow here
//archaic roblox api uses 0 for new asset //archaic roblox api uses 0 for new asset
query.append_pair("assetid","0"); 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{ match group{
Some(group_id)=>{query.append_pair("groupId",group_id.to_string().as_str());}, Some(group_id)=>{query.append_pair("groupId",group_id.to_string().as_str());},
None=>(), None=>(),
} }
} }
let body=tokio::fs::read(file).await?; let body=tokio::fs::read(config.input_file).await?;
let mut resp=client.post(url.clone()) let mut resp=client.post(url.clone())
.header("Cookie",cookie) .header("Cookie",cookie)
.body(body.clone()) .body(body.clone())