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

6
Cargo.lock generated
View file

@ -1191,9 +1191,9 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
[[package]]
name = "streamshare"
version = "1.0.0"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef90535ebe65d462a94bb3c3ab55f0b1ac2f500124724948c28527c219069117"
checksum = "b858ea2a485166fdb9850afa3016d4bd1cd131fd13bab39b74c1e860cfd93a4b"
dependencies = [
"futures",
"reqwest",
@ -1306,7 +1306,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "to-streamshare"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"clap",
"streamshare",

View file

@ -1,6 +1,6 @@
[package]
name = "to-streamshare"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
description = "Upload to streamshare (to-ss > toss) from the terminal"
license = "MIT"
@ -12,7 +12,7 @@ keywords = ["streamshare","file-sharing","upload"]
[dependencies]
clap = { version = "4.5.20", features = ["derive"] }
streamshare = "1.0.0"
streamshare = "1.1.0"
tokio = { version = "1.40.0", features = ["full"] }
[[bin]]

View file

@ -2,4 +2,5 @@
Upload files to [streamshare](https://streamshare.wireway.ch) with the terminal.
Run `cargo install to-streamshare` to install it and use it with `toss "filepath"`
Run `cargo install to-streamshare` to install it and use it with `toss "filepath"`.
Delete a file with `toss --delete file_identifier/deletion_token`

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
}
}

View file

@ -1 +1 @@
hello
Thanks to wireway.ch!