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;
|
2025-06-05 01:13:54 +00:00
|
|
|
use log::{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;
|
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-05 01:13:54 +00:00
|
|
|
let mut 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-05 01:13:54 +00:00
|
|
|
loop {
|
|
|
|
|
match state.upload_chunk(&agent, args.chunk_size * 1024 * 1024) {
|
|
|
|
|
Ok(None) => break,
|
|
|
|
|
Err(e) => error!("error: {e:?}"),
|
|
|
|
|
_ => (),
|
2025-06-04 16:44:16 +00:00
|
|
|
}
|
2025-06-05 01:13:54 +00:00
|
|
|
|
|
|
|
|
state.save().unwrap();
|
2025-05-26 20:31:22 +00:00
|
|
|
}
|
2025-06-05 01:13:54 +00:00
|
|
|
info!("uploads done");
|
2025-05-26 20:31:22 +00:00
|
|
|
|
2025-06-05 01:13:54 +00:00
|
|
|
state.clear().unwrap();
|
2025-05-17 23:57:52 +00:00
|
|
|
}
|