added --delete option to delete files

This commit is contained in:
Waradu 2024-10-19 22:57:32 +02:00
parent 27ac40966f
commit 72957f779a
No known key found for this signature in database
GPG key ID: F85AAC8BA8B8DAAD
5 changed files with 39 additions and 10 deletions

View file

@ -5,15 +5,32 @@ use streamshare::upload;
#[command(version, about, long_about = None)]
struct Args {
file: Option<String>,
#[arg(
short,
long,
value_name = "DELETE",
help = "Specify a file to delete in the format 'file_identifier/deletion_token' (e.g., 'abc123/def456')"
)]
delete: Option<String>,
}
#[tokio::main]
async fn main() {
let args = Args::parse();
if let Some(file_path) = args.file {
if let Some(delete_param) = args.delete {
if let Some((identifier, deltoken)) = parse_delete_param(&delete_param) {
match streamshare::delete(identifier, deltoken).await {
Ok(_) => println!("File deleted successfully"),
Err(e) => eprintln!("Error deleting file: {}", e),
}
} else {
eprintln!("Invalid format for --delete. Use 'file_identifier/deletion_token' (e.g., 'abc123/def456')");
}
} else if let Some(file_path) = args.file {
match upload(&file_path).await {
Ok((file_identifier, _deletion_token)) => {
Ok((file_identifier, deletion_token)) => {
let download_url = format!(
"https://streamshare.wireway.ch/download/{}",
file_identifier
@ -21,10 +38,21 @@ async fn main() {
println!("File uploaded successfully");
println!("Download URL: {}", download_url);
println!("File Identifier: {}", file_identifier);
println!("Deletion Token: {}", deletion_token);
}
Err(e) => eprintln!("Error: {}", e),
}
} else {
eprintln!("Please provide a file path");
eprintln!("Please provide a file path or use --delete");
}
}
fn parse_delete_param(param: &str) -> Option<(&str, &str)> {
let parts: Vec<&str> = param.splitn(2, '/').collect();
if parts.len() == 2 {
Some((parts[0], parts[1]))
} else {
None
}
}