diff --git a/src/main.rs b/src/main.rs index 0b24b92..9ac5d0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,16 @@ type AssetID=u64; #[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, } @@ -32,12 +42,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), @@ -55,7 +96,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(()) } @@ -67,8 +108,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|{