From df622586089805bd28e6e488d9838b12824b31e6 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sun, 31 Dec 2023 09:18:41 -0800 Subject: [PATCH] implement cookie and group as arg (bad) --- src/main.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4971f09..c4a462f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,16 @@ const CONCURRENT_REQUESTS:usize=8; #[command(author,version,about,long_about=None)] #[command(propagate_version = true)] struct Cli{ + #[arg(short,long)] + group:Option, + //idk how to do this better + #[arg(long)] + cookie_literal:Option, + #[arg(long)] + cookie_env:Option, + #[arg(long)] + cookie_file:Option, + #[command(subcommand)] command:Commands, } @@ -33,12 +43,43 @@ struct AssetIDList{ #[tokio::main] async fn main()->AResult<()>{ let cli=Cli::parse(); + + let cookie_enum={ + match (cli.cookie_literal,cli.cookie_env,cli.cookie_file){ + (Some(literal),None,None)=>Cookie::Literal(literal), + (None,Some(env_var),None)=>Cookie::Environment(env_var), + (None,None,Some(path))=>Cookie::File(path), + _=>return Err(anyhow::Error::msg("Cookie was not specified or was specified multiple times.")), + } + }; + let cookie=format!(".ROBLOSECURITY={}",match cookie_enum{ + Cookie::Literal(s)=>s, + Cookie::Environment(var)=>std::env::var(var)?, + Cookie::File(path)=>tokio::fs::read_to_string(path).await?, + }); + + let group=match cli.group{ + Some(group_id)=>Owner::Group(group_id), + None=>Owner::User, + }; + match cli.command{ - Commands::Download(asset_id_list)=>download_list(asset_id_list.asset_ids).await, - Commands::Upload{path,asset_id}=>upload_file(path,asset_id), + Commands::Download(asset_id_list)=>download_list(cookie,asset_id_list.asset_ids).await, + Commands::Upload{path,asset_id}=>upload_list(cookie,group,path,asset_id).await, } } +enum Owner{ + Group(u64), + User +} + +enum Cookie{ + Literal(String), + Environment(String), + File(std::path::PathBuf), +} + enum ReaderType<'a,R:Read+Seek>{ GZip(flate2::read::GzDecoder<&'a mut R>), Raw(&'a mut R), @@ -56,7 +97,7 @@ fn maybe_gzip_decode(input:&mut R)->AResult>{ } } -fn upload_file(_path:std::path::PathBuf,_asset_id:AssetID)->AResult<()>{ +async fn upload_list(_cookie:String,_owner:Owner,_path:std::path::PathBuf,_asset_id:AssetID)->AResult<()>{ Ok(()) } @@ -66,8 +107,7 @@ fn read_readable(mut readable:impl Read)->AResult>{ Ok(contents) } -async fn download_list(asset_ids:Vec)->AResult<()>{ - let cookie=format!(".ROBLOSECURITY={}",std::env::var("RBXCOOKIE_PROJECTSLIME")?); +async fn download_list(cookie:String,asset_ids:Vec)->AResult<()>{ let client=reqwest::Client::new(); futures::stream::iter(asset_ids) .map(|asset_id|{