implement cookie and group as arg (bad)

This commit is contained in:
Quaternions 2023-12-31 09:18:41 -08:00
parent dc4ec4547a
commit df62258608

View File

@ -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<u64>,
//idk how to do this better
#[arg(long)]
cookie_literal:Option<String>,
#[arg(long)]
cookie_env:Option<String>,
#[arg(long)]
cookie_file:Option<std::path::PathBuf>,
#[command(subcommand)]
command:Commands,
}
@ -33,10 +43,41 @@ struct AssetIDList{
#[tokio::main]
async fn main()->AResult<()>{
let cli=Cli::parse();
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),
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(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>{
@ -56,7 +97,7 @@ fn maybe_gzip_decode<R:Read+Seek>(input:&mut R)->AResult<ReaderType<R>>{
}
}
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<Vec<u8>>{
Ok(contents)
}
async fn download_list(asset_ids:Vec<AssetID>)->AResult<()>{
let cookie=format!(".ROBLOSECURITY={}",std::env::var("RBXCOOKIE_PROJECTSLIME")?);
async fn download_list(cookie:String,asset_ids:Vec<AssetID>)->AResult<()>{
let client=reqwest::Client::new();
futures::stream::iter(asset_ids)
.map(|asset_id|{