forked from StrafesNET/asset-tool
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(author,version,about,long_about=None)]
|
||||||
#[command(propagate_version = true)]
|
#[command(propagate_version = true)]
|
||||||
struct Cli{
|
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(subcommand)]
|
||||||
command:Commands,
|
command:Commands,
|
||||||
}
|
}
|
||||||
@ -32,12 +42,43 @@ struct AssetIDList{
|
|||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main()->AResult<()>{
|
async fn main()->AResult<()>{
|
||||||
let cli=Cli::parse();
|
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{
|
match cli.command{
|
||||||
Commands::Download(asset_id_list)=>download_list(asset_id_list.asset_ids).await,
|
Commands::Download(asset_id_list)=>download_list(cookie,asset_id_list.asset_ids).await,
|
||||||
Commands::Upload{path,asset_id}=>upload_file(path,asset_id),
|
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>{
|
enum ReaderType<'a,R:Read+Seek>{
|
||||||
GZip(flate2::read::GzDecoder<&'a mut R>),
|
GZip(flate2::read::GzDecoder<&'a mut R>),
|
||||||
Raw(&'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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,8 +108,7 @@ fn read_readable(mut readable:impl Read)->AResult<Vec<u8>>{
|
|||||||
Ok(contents)
|
Ok(contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn download_list(asset_ids:Vec<AssetID>)->AResult<()>{
|
async fn download_list(cookie:String,asset_ids:Vec<AssetID>)->AResult<()>{
|
||||||
let cookie=format!(".ROBLOSECURITY={}",std::env::var("RBXCOOKIE_PROJECTSLIME")?);
|
|
||||||
let client=reqwest::Client::new();
|
let client=reqwest::Client::new();
|
||||||
futures::stream::iter(asset_ids)
|
futures::stream::iter(asset_ids)
|
||||||
.map(|asset_id|{
|
.map(|asset_id|{
|
||||||
|
Loading…
Reference in New Issue
Block a user