Skip to content

Commit

Permalink
added download
Browse files Browse the repository at this point in the history
  • Loading branch information
Waradu committed Oct 20, 2024
1 parent 27c765b commit a452ff1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "to-streamshare"
version = "0.5.0"
version = "0.6.0"
edition = "2021"
description = "Upload to streamshare (to-ss > toss) from the terminal"
license = "MIT"
Expand All @@ -14,9 +14,9 @@ keywords = ["streamshare", "file-sharing", "upload"]
clap = { version = "4.5.20", features = ["derive"] }
console = "0.15.8"
kdam = { version = "0.5.2", features = ["rich", "spinner"] }
streamshare = "4"
streamshare = "4.1"
tokio = { version = "1.40.0", features = ["full"] }

[[bin]]
name = "toss"
path = "src/main.rs"
path = "src/main.rs"
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ cargo install to-streamshare

```bash
toss "filepath"
toss "filepath" --chunk-size 100 # set chunk_size to 100
toss "filepath" --server "streamshare.myserver.com" # set server to your server
toss --chunk-size 100 "filepath" # set chunk_size to 100
toss --server "streamshare.myserver.com" "filepath" # set server to your server
```

### Delete

```bash
toss --delete file_identifier/deletion_token
toss --delete "file_identifier/deletion_token"
```

### Download

```bash
toss --download "file_identifier"
toss --download "file_identifier" --path "" # uses current path as default
```
44 changes: 34 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,45 @@ use streamshare::StreamShare;
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>,

#[arg(
short,
long,
value_name = "SERVER",
help = "Specify a server",
help = "Specify a server.",
default_value = "streamshare.wireway.ch"
)]
server: Option<String>,

#[arg(
short,
long,
value_name = "CHUNK-SIZE",
value_name = "CHUNK_SIZE",
help = "Specify a chunk size",
default_value = "1048576"
)]
chunk_size: Option<String>,

#[arg(
long,
value_name = "DELETE",
help = "Delete a file. Format: 'file_identifier/deletion_token'"
)]
delete: Option<String>,

#[arg(
long,
value_name = "DOWNLOAD",
help = "Download a file. Format: 'file_identifier'"
)]
download: Option<String>,

#[arg(
short,
long,
value_name = "PATH",
help = "Set the path to download the file to."
)]
path: Option<String>,
}

#[tokio::main]
Expand All @@ -63,6 +77,16 @@ async fn main() -> std::io::Result<()> {
} else {
eprintln!("Invalid format for --delete. Use 'file_identifier/deletion_token' (e.g., 'abc123/def456')");
}
} else if let Some(download) = args.download {
let path = match args.path {
Some(p) => p,
None => "".to_string()
};

match client.download(download.as_str(), path.as_str()).await {
Ok(_) => println!("File downloaded successfully"),
Err(e) => eprintln!("Error downloaded file: {}", e),
}
} else if let Some(file_path) = args.file {
kdam::term::init(stderr().is_terminal());
kdam::term::hide_cursor()?;
Expand Down

0 comments on commit a452ff1

Please sign in to comment.