This commit is contained in:
parent
8222cb3457
commit
b1a118c29e
120
src/main.rs
120
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<String>,
|
||||
#[arg(long,group="cookie",required=true)]
|
||||
cookie_envvar:Option<String>,
|
||||
#[arg(long,group="cookie",required=true)]
|
||||
cookie_file:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
group_id:Option<u64>,
|
||||
#[arg(long)]
|
||||
input_file:PathBuf,
|
||||
#[arg(long)]
|
||||
model_name:String,
|
||||
#[arg(long)]
|
||||
description:Option<String>,
|
||||
#[arg(long)]
|
||||
free_model:Option<bool>,
|
||||
#[arg(long)]
|
||||
allow_comments:Option<bool>,
|
||||
}
|
||||
#[derive(Args)]
|
||||
struct CreateAssetMediaSubcommand{
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_literal:Option<String>,
|
||||
@ -105,6 +128,29 @@ struct CreateAssetMediaSubcommand{
|
||||
expected_price:Option<u64>,
|
||||
}
|
||||
#[derive(Args)]
|
||||
struct UpdateAssetSubcommand{
|
||||
#[arg(long)]
|
||||
asset_id:AssetID,
|
||||
#[arg(long,group="cookie",required=true)]
|
||||
cookie_literal:Option<String>,
|
||||
#[arg(long,group="cookie",required=true)]
|
||||
cookie_envvar:Option<String>,
|
||||
#[arg(long,group="cookie",required=true)]
|
||||
cookie_file:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
group_id:Option<u64>,
|
||||
#[arg(long)]
|
||||
input_file:PathBuf,
|
||||
#[arg(long)]
|
||||
change_name:Option<String>,
|
||||
#[arg(long)]
|
||||
change_description:Option<String>,
|
||||
#[arg(long)]
|
||||
change_free_model:Option<bool>,
|
||||
#[arg(long)]
|
||||
change_allow_comments:Option<bool>,
|
||||
}
|
||||
#[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<String>,environment:Option<String>,fil
|
||||
Ok(ApiKey::new(api_key))
|
||||
}
|
||||
|
||||
struct CreateAssetConfig{
|
||||
cookie:Cookie,
|
||||
model_name:String,
|
||||
description:String,
|
||||
input_file:PathBuf,
|
||||
group:Option<u64>,
|
||||
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<String>,
|
||||
change_description:Option<String>,
|
||||
change_free_model:Option<bool>,
|
||||
change_allow_comments:Option<bool>,
|
||||
group_id:Option<u64>,
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user