shrupl/src/main.rs

71 lines
1.7 KiB
Rust
Raw Normal View History

2025-06-02 23:57:17 +00:00
mod appstate;
2025-05-28 00:07:59 +00:00
mod cli;
2025-05-22 17:34:44 +00:00
mod sharry;
2025-05-27 14:01:09 +00:00
use clap::Parser;
use log::{debug, error, info};
2025-05-22 17:34:44 +00:00
use ureq::Agent;
2025-06-02 23:57:17 +00:00
use appstate::AppState;
2025-05-28 00:07:59 +00:00
use cli::Cli;
use sharry::{ChunkState, Share};
2025-05-27 14:01:09 +00:00
2025-05-17 23:57:52 +00:00
fn main() {
2025-05-22 17:34:44 +00:00
env_logger::init();
2025-05-28 00:07:59 +00:00
let args = Cli::parse();
info!("args: {args:?}");
2025-05-28 13:42:31 +00:00
info!("timeout: {:?}", args.get_timeout());
2025-05-28 00:07:59 +00:00
2025-05-22 17:34:44 +00:00
let agent: Agent = Agent::config_builder()
2025-05-28 13:42:31 +00:00
.timeout_global(args.get_timeout())
2025-05-22 17:34:44 +00:00
.build()
.into();
2025-06-04 21:02:35 +00:00
let state = AppState::try_resume(&args)
2025-06-04 21:23:21 +00:00
.map(|state| {
2025-06-04 21:02:35 +00:00
info!("loaded state: {state:?}");
2025-06-04 21:23:21 +00:00
state
2025-06-04 21:02:35 +00:00
})
2025-06-04 21:23:21 +00:00
.or_else(|| AppState::from_args(&args, &agent))
2025-06-04 21:02:35 +00:00
.unwrap_or_else(|| {
2025-06-04 21:23:21 +00:00
error!("could not create new state from cli arguments: {args:?}");
2025-06-04 21:02:35 +00:00
std::process::exit(1);
});
info!("continuing with state: {state:?}");
state.save().unwrap();
2025-06-04 21:23:21 +00:00
// state.clear().unwrap();
2025-06-04 21:02:35 +00:00
return;
2025-06-02 23:57:17 +00:00
let alias = args.get_alias();
let share = Share::create(&agent, &alias, args.get_share_request()).unwrap();
2025-05-26 23:56:31 +00:00
info!("share: {share:?}");
2025-05-22 21:07:49 +00:00
2025-05-28 12:35:35 +00:00
for file in args.files {
let mut file = file.start_upload(&agent, &alias, &share).unwrap();
2025-05-27 17:18:29 +00:00
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;
}
2025-06-04 16:54:03 +00:00
ChunkState::Finished(path) => {
info!("Finished {:?}!", path.display());
break;
}
}
debug!("file: {file:?}");
}
2025-05-26 20:31:22 +00:00
}
2025-05-28 14:07:29 +00:00
share.notify(&agent, &alias).unwrap();
2025-05-17 23:57:52 +00:00
}