From b1a118c29e37495bd6bed4be9b288a2a3effbbe1 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 10 Jul 2024 09:08:16 -0700 Subject: [PATCH] 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,