shrupl/src/main.rs

50 lines
1.1 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::{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::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-02 23:57:17 +00:00
if let Some(state) = AppState::try_resume(&args) {
info!("state: {state:?}");
}
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 {
2025-05-28 14:07:29 +00:00
let file = file.create(&agent, &alias, &share).unwrap();
2025-05-27 17:18:29 +00:00
info!("file: {file:?}");
for chunk in file.chunked(args.chunk_size * 1024 * 1024).seek(0) {
2025-06-03 00:07:44 +00:00
info!("chunk: {chunk:?}");
2025-05-27 17:18:29 +00:00
file.upload_chunk(&agent, &alias, &chunk)
.unwrap_or_else(|e| {
error!("error: {e}");
panic!("{e}");
});
2025-05-27 17:18:29 +00:00
}
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
}