added replace when downloading option

This commit is contained in:
Waradu 2024-10-20 21:17:30 +02:00
parent a452ff1631
commit 6fb6657332
No known key found for this signature in database
GPG key ID: F85AAC8BA8B8DAAD
4 changed files with 73 additions and 8 deletions

64
Cargo.lock generated
View file

@ -257,6 +257,27 @@ dependencies = [
"crypto-common", "crypto-common",
] ]
[[package]]
name = "dirs"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "encode_unicode" name = "encode_unicode"
version = "0.3.6" version = "0.3.6"
@ -670,6 +691,16 @@ version = "0.2.161"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"
[[package]]
name = "libredox"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags",
"libc",
]
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.4.14" version = "0.4.14"
@ -801,6 +832,12 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.3" version = "0.12.3"
@ -962,6 +999,17 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "redox_users"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
dependencies = [
"getrandom",
"libredox",
"thiserror",
]
[[package]] [[package]]
name = "reqwest" name = "reqwest"
version = "0.12.8" version = "0.12.8"
@ -1189,6 +1237,15 @@ dependencies = [
"digest", "digest",
] ]
[[package]]
name = "shellexpand"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da03fa3b94cc19e3ebfc88c4229c49d8f08cdbd1228870a45f0ffdf84988e14b"
dependencies = [
"dirs",
]
[[package]] [[package]]
name = "shlex" name = "shlex"
version = "1.3.0" version = "1.3.0"
@ -1237,14 +1294,15 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
[[package]] [[package]]
name = "streamshare" name = "streamshare"
version = "4.1.0" version = "5.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1960eb9ada032cacbd7b75b1255468a007459729009b76e508579bd49d97171" checksum = "b3738f5ec13f0df9b7b1f21701dde6b1edf0b6684a82e58a4fd61936377403ef"
dependencies = [ dependencies = [
"futures", "futures",
"reqwest", "reqwest",
"serde", "serde",
"serde_json", "serde_json",
"shellexpand",
"tokio", "tokio",
"tokio-tungstenite", "tokio-tungstenite",
] ]
@ -1362,7 +1420,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]] [[package]]
name = "to-streamshare" name = "to-streamshare"
version = "0.6.0" version = "0.7.0"
dependencies = [ dependencies = [
"clap", "clap",
"console", "console",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "to-streamshare" name = "to-streamshare"
version = "0.6.0" version = "0.7.0"
edition = "2021" edition = "2021"
description = "Upload to streamshare (to-ss > toss) from the terminal" description = "Upload to streamshare (to-ss > toss) from the terminal"
license = "MIT" license = "MIT"
@ -14,7 +14,7 @@ keywords = ["streamshare", "file-sharing", "upload"]
clap = { version = "4.5.20", features = ["derive"] } clap = { version = "4.5.20", features = ["derive"] }
console = "0.15.8" console = "0.15.8"
kdam = { version = "0.5.2", features = ["rich", "spinner"] } kdam = { version = "0.5.2", features = ["rich", "spinner"] }
streamshare = "4.1" streamshare = "5"
tokio = { version = "1.40.0", features = ["full"] } tokio = { version = "1.40.0", features = ["full"] }
[[bin]] [[bin]]

View file

@ -27,4 +27,5 @@ toss --delete "file_identifier/deletion_token"
```bash ```bash
toss --download "file_identifier" toss --download "file_identifier"
toss --download "file_identifier" --path "" # uses current path as default toss --download "file_identifier" --path "" # uses current path as default
toss --download "file_identifier" --replace # replace if file already exist
``` ```

View file

@ -46,12 +46,18 @@ struct Args {
download: Option<String>, download: Option<String>,
#[arg( #[arg(
short,
long, long,
value_name = "PATH", value_name = "PATH",
help = "Set the path to download the file to." help = "Set the path to download the file to."
)] )]
path: Option<String>, path: Option<String>,
#[arg(
long,
value_name = "REPLACE",
help = "Replace file when downloading if it already exists.",
)]
replace: bool,
} }
#[tokio::main] #[tokio::main]
@ -83,7 +89,7 @@ async fn main() -> std::io::Result<()> {
None => "".to_string() None => "".to_string()
}; };
match client.download(download.as_str(), path.as_str()).await { match client.download(download.as_str(), path.as_str(), args.replace).await {
Ok(_) => println!("File downloaded successfully"), Ok(_) => println!("File downloaded successfully"),
Err(e) => eprintln!("Error downloaded file: {}", e), Err(e) => eprintln!("Error downloaded file: {}", e),
} }