From 28bcf8005bdecf5cd43b5ac5c353c15a4c5f8981 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 1 Oct 2024 11:38:34 -0700 Subject: [PATCH] download_user_inventory_json --- src/main.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/main.rs b/src/main.rs index 418a9a4..12e2e84 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ enum Commands{ Download(DownloadSubcommand), DownloadDecompile(DownloadDecompileSubcommand), DownloadCreationsJson(DownloadCreationsJsonSubcommand), + DownloadUserInventoryJson(DownloadUserInventoryJsonSubcommand), CreateAsset(CreateAssetSubcommand), CreateAssetMedia(CreateAssetMediaSubcommand), CreateAssetMedias(CreateAssetMediasSubcommand), @@ -88,6 +89,20 @@ struct DownloadCreationsJsonSubcommand{ #[arg(long,group="owner",required=true)] user_id:Option, } +/// Download the list of asset ids (not the assets themselves) in a user's inventory. The output is written to `output_folder/versions.json` +#[derive(Args)] +struct DownloadUserInventoryJsonSubcommand{ + #[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)] + output_folder:Option, + #[arg(long)] + user_id:u64, +} /// Upload a (.rbxm, .rbxmx) model file, creating a new asset. Can be any type of model, including modulescripts. #[derive(Args)] struct CreateAssetSubcommand{ @@ -441,6 +456,15 @@ async fn main()->AResult<()>{ )?, subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()), ).await, + Commands::DownloadUserInventoryJson(subcommand)=>download_user_inventory_json( + cookie_from_args( + subcommand.cookie_literal, + subcommand.cookie_envvar, + subcommand.cookie_file, + ).await?, + subcommand.user_id, + 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, @@ -931,6 +955,34 @@ async fn download_creations_json(cookie:Cookie,owner:rbx_asset::cookie::Owner,ou Ok(()) } +async fn get_user_inventory_pages(context:&CookieContext,user_id:u64)->AResult>{ + let mut config=rbx_asset::cookie::UserInventoryPageRequest{ + user_id, + cursor:None, + }; + let mut asset_list=Vec::new(); + loop{ + let mut page=context.get_user_inventory_page(&config).await?; + asset_list.append(&mut page.data); + if page.nextPageCursor.is_none(){ + break; + } + config.cursor=page.nextPageCursor; + } + Ok(asset_list) +} + +async fn download_user_inventory_json(cookie:Cookie,user_id:u64,output_folder:PathBuf)->AResult<()>{ + let context=CookieContext::new(cookie); + let item_list=get_user_inventory_pages(&context,user_id).await?; + + let mut path=output_folder.clone(); + path.set_file_name("versions.json"); + tokio::fs::write(path,serde_json::to_string(&item_list)?).await?; + + Ok(()) +} + async fn get_version_history(context:&CookieContext,asset_id:AssetID)->AResult>{ let mut cursor:Option=None; let mut asset_list=Vec::new();