mod sharry; use std::{path::PathBuf, time::Duration}; use clap::Parser; use log::{error, info}; use ureq::Agent; use sharry::{Alias, File, NewShareRequest, Share, Uri}; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] struct Cli { /// Protocol for Sharry instance #[arg( short, long, default_value_t = String::from("https"), value_parser = clap::builder::PossibleValuesParser::new(["http", "https"]), )] proto: String, /// Name of the new share #[arg( short, long, default_value_t = String::from("shrupl upload"), )] name: String, /// Description of the new share #[arg(short, long)] desc: Option, /// Maximum number of views for the new share #[arg(short, long, default_value_t = 10)] views: u32, /// Chunk size for uploading, in MiB #[arg(short, long, default_value_t = 10)] chunk: usize, /// Base URL for Sharry Instance url: String, /// ID of a public alias to use alias: String, /// Files to upload to the new share #[arg(value_name = "FILE")] files: Vec, } fn main() { env_logger::init(); let agent: Agent = Agent::config_builder() .timeout_global(Some(Duration::from_secs(5))) .build() .into(); let args = Cli::parse(); let alias = Alias::new(Uri::with_protocol(args.proto, args.url), args.alias); let share = NewShareRequest::new(args.name, args.desc, 10); let share = Share::create(&agent, &alias, share).unwrap(); info!("share: {share:?}"); let file = File::new("/lib/x86_64-linux-gnu/liblldb-14.so.1") .unwrap() .create(&agent, &share) .unwrap(); info!("file: {file:?}"); for chunk in file.chunked(args.chunk * 1024 * 1024) { println!("chunk len: {}", chunk.bytes.len()); file.upload_chunk(&agent, &alias, &chunk) .inspect_err(|e| error!("error: {e}")) .unwrap(); } share.notify(&agent).unwrap(); }