shrupl/src/main.rs

70 lines
1.7 KiB
Rust

mod appstate;
mod cli;
mod sharry;
use clap::Parser;
use log::{debug, error, info};
use ureq::Agent;
use appstate::AppState;
use cli::Cli;
use sharry::{ChunkState, Share};
fn main() {
env_logger::init();
let args = Cli::parse();
info!("args: {args:?}");
info!("timeout: {:?}", args.get_timeout());
let agent: Agent = Agent::config_builder()
.timeout_global(args.get_timeout())
.build()
.into();
let state = AppState::try_resume(&args)
.map(|state| {
info!("loaded state: {state:?}");
state
})
.or_else(|| AppState::from_args(&args, &agent))
.unwrap_or_else(|| {
error!("could not create new state from cli arguments: {args:?}");
std::process::exit(1);
});
info!("continuing with state: {state:?}");
state.save().unwrap();
// state.clear().unwrap();
return;
let alias = args.get_alias();
let share = Share::create(&agent, &alias, args.get_share_request()).unwrap();
info!("share: {share:?}");
for file in args.files {
let mut file = file.start_upload(&agent, &alias, &share).unwrap();
info!("file: {file:?}");
loop {
match file.upload_chunk(&agent, &alias, args.chunk_size * 1024 * 1024) {
ChunkState::Ok(upl) => file = upl,
ChunkState::Err(upl, e) => {
error!("error: {e:?}");
file = upl;
}
ChunkState::Finished(path) => {
info!("Finished {:?}!", path.display());
break;
}
}
debug!("file: {file:?}");
}
}
share.notify(&agent, &alias).unwrap();
}