shrupl/src/main.rs

83 lines
2 KiB
Rust
Raw Normal View History

2025-05-22 17:34:44 +00:00
mod sharry;
2025-05-27 14:01:09 +00:00
use std::{path::PathBuf, time::Duration};
use clap::Parser;
use log::{error, info};
2025-05-22 17:34:44 +00:00
use ureq::Agent;
2025-05-27 14:01:09 +00:00
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<String>,
/// 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<PathBuf>,
}
2025-05-17 23:57:52 +00:00
fn main() {
2025-05-22 17:34:44 +00:00
env_logger::init();
let agent: Agent = Agent::config_builder()
.timeout_global(Some(Duration::from_secs(5)))
.build()
.into();
2025-05-27 14:01:09 +00:00
let args = Cli::parse();
let alias = Alias::new(Uri::with_protocol(args.proto, args.url), args.alias);
2025-05-22 17:34:44 +00:00
2025-05-27 14:01:09 +00:00
let share = NewShareRequest::new(args.name, args.desc, 10);
2025-05-24 00:22:24 +00:00
let share = Share::create(&agent, &alias, share).unwrap();
2025-05-26 23:56:31 +00:00
info!("share: {share:?}");
2025-05-22 21:07:49 +00:00
2025-05-27 10:44:06 +00:00
let file = File::new("/lib/x86_64-linux-gnu/liblldb-14.so.1")
.unwrap()
.create(&agent, &share)
.unwrap();
2025-05-26 23:56:31 +00:00
info!("file: {file:?}");
2025-05-23 01:11:11 +00:00
2025-05-27 14:01:09 +00:00
for chunk in file.chunked(args.chunk * 1024 * 1024) {
println!("chunk len: {}", chunk.bytes.len());
2025-05-27 10:44:06 +00:00
file.upload_chunk(&agent, &alias, &chunk)
2025-05-26 23:56:31 +00:00
.inspect_err(|e| error!("error: {e}"))
.unwrap();
2025-05-26 20:31:22 +00:00
}
2025-05-22 21:07:49 +00:00
share.notify(&agent).unwrap();
2025-05-17 23:57:52 +00:00
}