implement cookie and group as arg (bad)
This commit is contained in:
parent
9673bbbe8c
commit
edb58b16b5
50
src/main.rs
50
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<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,
|
||||
}
|
||||
@ -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<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(())
|
||||
}
|
||||
|
||||
@ -67,8 +108,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|{
|
||||
|
Loading…
Reference in New Issue
Block a user