mirror of
https://github.com/Waradu/to-streamshare.git
synced 2025-04-22 04:14:06 +02:00
updated to streamshare v4 and added chunk-size + server arguments
This commit is contained in:
parent
7a101fde14
commit
194a74b958
3 changed files with 80 additions and 31 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -1212,9 +1212,9 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
|||
|
||||
[[package]]
|
||||
name = "streamshare"
|
||||
version = "3.0.0"
|
||||
version = "4.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8a66009b98588531c068a6b1fc2345a05292dd279c73554d514fd47f926b2e7"
|
||||
checksum = "0d8642382451166982e9ca79fa523c65350c72b113b5c4a89887a1181a16ac44"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"reqwest",
|
||||
|
@ -1337,7 +1337,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|||
|
||||
[[package]]
|
||||
name = "to-streamshare"
|
||||
version = "0.4.0"
|
||||
version = "0.5.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"kdam",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "to-streamshare"
|
||||
version = "0.4.0"
|
||||
version = "0.5.0"
|
||||
edition = "2021"
|
||||
description = "Upload to streamshare (to-ss > toss) from the terminal"
|
||||
license = "MIT"
|
||||
|
@ -13,7 +13,7 @@ keywords = ["streamshare", "file-sharing", "upload"]
|
|||
[dependencies]
|
||||
clap = { version = "4.5.20", features = ["derive"] }
|
||||
kdam = { version = "0.5.2", features = ["rich", "spinner"] }
|
||||
streamshare = "3"
|
||||
streamshare = "4"
|
||||
tokio = { version = "1.40.0", features = ["full"] }
|
||||
|
||||
[[bin]]
|
||||
|
|
83
src/main.rs
83
src/main.rs
|
@ -1,11 +1,11 @@
|
|||
use clap::{CommandFactory, Parser};
|
||||
use kdam::{tqdm, BarExt, Column, RichProgress, Spinner, term::Colorizer};
|
||||
use streamshare::{delete, upload};
|
||||
use std::io::{stderr, IsTerminal};
|
||||
use kdam::{term::Colorizer, tqdm, BarExt, Column, RichProgress, Spinner};
|
||||
use std::fs;
|
||||
use std::time::Duration;
|
||||
use std::io::{stderr, IsTerminal};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use streamshare::StreamShare;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(name = "toss", version, about, long_about = None)]
|
||||
|
@ -19,15 +19,43 @@ struct Args {
|
|||
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",
|
||||
default_value = "streamshare.wireway.ch"
|
||||
)]
|
||||
server: Option<String>,
|
||||
|
||||
#[arg(
|
||||
short,
|
||||
long,
|
||||
value_name = "CHUNK-SIZE",
|
||||
help = "Specify a chunk size",
|
||||
default_value = "1048576"
|
||||
)]
|
||||
chunk_size: Option<String>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let args = Args::parse();
|
||||
let server = args.server.unwrap();
|
||||
let chunk_size = match args.chunk_size.unwrap().parse::<usize>() {
|
||||
Ok(c) => c,
|
||||
Err(_) => {
|
||||
eprintln!("Error: The provided chunk size is not a valid integer.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(delete_param) = args.delete {
|
||||
if let Some((file_identifier, deletion_token)) = parse_delete_param(&delete_param) {
|
||||
match delete(file_identifier, deletion_token).await {
|
||||
let client = StreamShare::new(server.clone(), chunk_size);
|
||||
|
||||
if let Some(delete) = args.delete {
|
||||
if let Some((file_identifier, deletion_token)) = parse_delete_param(&delete) {
|
||||
match client.delete(file_identifier, deletion_token).await {
|
||||
Ok(_) => println!("File deleted successfully"),
|
||||
Err(e) => eprintln!("Error deleting file: {}", e),
|
||||
}
|
||||
|
@ -51,7 +79,11 @@ async fn main() -> std::io::Result<()> {
|
|||
colour = "green"
|
||||
),
|
||||
vec![
|
||||
Column::Spinner(Spinner::new(&["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"], 80.0, 1.0)),
|
||||
Column::Spinner(Spinner::new(
|
||||
&["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
|
||||
80.0,
|
||||
1.0,
|
||||
)),
|
||||
Column::Percentage(1),
|
||||
Column::Text("•".to_owned()),
|
||||
Column::Animation,
|
||||
|
@ -70,20 +102,25 @@ async fn main() -> std::io::Result<()> {
|
|||
let pb_arc_clone = pb_arc.clone();
|
||||
let current_progress_clone = current_progress.clone();
|
||||
|
||||
let update_thread = thread::spawn(move || {
|
||||
loop {
|
||||
let update_thread = thread::spawn(move || loop {
|
||||
thread::sleep(Duration::from_millis(50));
|
||||
let progress = *current_progress_clone.lock().unwrap();
|
||||
if progress >= file_size {
|
||||
break;
|
||||
}
|
||||
pb_arc_clone.lock().unwrap().update_to(progress as usize).unwrap();
|
||||
}
|
||||
pb_arc_clone
|
||||
.lock()
|
||||
.unwrap()
|
||||
.update_to(progress as usize)
|
||||
.unwrap();
|
||||
});
|
||||
|
||||
match upload(&file_path, move |current, _total| {
|
||||
match client
|
||||
.upload(&file_path, move |current, _total| {
|
||||
*current_progress.lock().unwrap() = current;
|
||||
}).await {
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok((file_identifier, deletion_token)) => {
|
||||
let mut pb = pb_arc.lock().unwrap();
|
||||
pb.update_to(file_size as usize).unwrap();
|
||||
|
@ -96,9 +133,21 @@ async fn main() -> std::io::Result<()> {
|
|||
"https://streamshare.wireway.ch/download/{}",
|
||||
file_identifier
|
||||
);
|
||||
println!("│ {:<15} {:<31} │", "URL:".colorize("bold yellow"), download_url);
|
||||
println!("│ {:<15} {:<68} │", "File ID:".colorize("bold yellow"), file_identifier);
|
||||
println!("│ {:<15} {:<61} │", "Deletion Token:".colorize("bold yellow"), deletion_token);
|
||||
println!(
|
||||
"│ {:<15} {:<31} │",
|
||||
"URL:".colorize("bold yellow"),
|
||||
download_url
|
||||
);
|
||||
println!(
|
||||
"│ {:<15} {:<68} │",
|
||||
"File ID:".colorize("bold yellow"),
|
||||
file_identifier
|
||||
);
|
||||
println!(
|
||||
"│ {:<15} {:<61} │",
|
||||
"Deletion Token:".colorize("bold yellow"),
|
||||
deletion_token
|
||||
);
|
||||
|
||||
println!("{}", "└".to_owned() + &"─".repeat(79) + "┘");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue