fixed upload complete

This commit is contained in:
Waradu 2024-10-20 17:48:28 +02:00
parent b6f0687ab0
commit eebcd9d7f8
No known key found for this signature in database
GPG key ID: F85AAC8BA8B8DAAD
3 changed files with 71 additions and 22 deletions

32
Cargo.lock generated
View file

@ -193,6 +193,19 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
[[package]]
name = "console"
version = "0.15.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb"
dependencies = [
"encode_unicode",
"lazy_static",
"libc",
"unicode-width",
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.4" version = "0.9.4"
@ -244,6 +257,12 @@ dependencies = [
"crypto-common", "crypto-common",
] ]
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.34" version = "0.8.34"
@ -639,6 +658,12 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.161" version = "0.2.161"
@ -1340,6 +1365,7 @@ name = "to-streamshare"
version = "0.5.0" version = "0.5.0"
dependencies = [ dependencies = [
"clap", "clap",
"console",
"kdam", "kdam",
"streamshare", "streamshare",
"tokio", "tokio",
@ -1502,6 +1528,12 @@ dependencies = [
"tinyvec", "tinyvec",
] ]
[[package]]
name = "unicode-width"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]] [[package]]
name = "untrusted" name = "untrusted"
version = "0.9.0" version = "0.9.0"

View file

@ -12,6 +12,7 @@ keywords = ["streamshare", "file-sharing", "upload"]
[dependencies] [dependencies]
clap = { version = "4.5.20", features = ["derive"] } clap = { version = "4.5.20", features = ["derive"] }
console = "0.15.8"
kdam = { version = "0.5.2", features = ["rich", "spinner"] } kdam = { version = "0.5.2", features = ["rich", "spinner"] }
streamshare = "4" streamshare = "4"
tokio = { version = "1.40.0", features = ["full"] } tokio = { version = "1.40.0", features = ["full"] }

View file

@ -1,4 +1,5 @@
use clap::{CommandFactory, Parser}; use clap::{CommandFactory, Parser};
use console::{measure_text_width, pad_str, Alignment};
use kdam::{term::Colorizer, tqdm, BarExt, Column, RichProgress, Spinner}; use kdam::{term::Colorizer, tqdm, BarExt, Column, RichProgress, Spinner};
use std::fs; use std::fs;
use std::io::{stderr, IsTerminal}; use std::io::{stderr, IsTerminal};
@ -126,33 +127,48 @@ async fn main() -> std::io::Result<()> {
pb.update_to(file_size as usize).unwrap(); pb.update_to(file_size as usize).unwrap();
pb.clear().unwrap(); pb.clear().unwrap();
println!("\n{}", "".to_owned() + &"".repeat(79) + ""); let url = format!(
println!("{:^90}", "Upload Complete!".colorize("bold green"));
println!("{}", "".repeat(79));
let download_url = format!(
"https://streamshare.wireway.ch/download/{}", "https://streamshare.wireway.ch/download/{}",
file_identifier 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!("{}", "".to_owned() + &"".repeat(79) + ""); let title = "Upload Complete!".colorize("bold green");
println!() let label_url = "URL:".colorize("bold yellow");
let label_file_id = "File ID:".colorize("bold yellow");
let label_deletion_token = "Deletion Token:".colorize("bold yellow");
let labels = vec![
(label_url, url),
(label_file_id, file_identifier),
(label_deletion_token, deletion_token),
];
let title_width = measure_text_width(&title);
let max_line_width = labels
.iter()
.map(|(label, content)| measure_text_width(&format!("{} {}", label, content)))
.max()
.unwrap_or(0);
let box_width = max_line_width.max(title_width) + 2;
println!("\n{}", format!("{}", "".repeat(box_width)));
let padded_title = pad_str(&title, box_width, Alignment::Center, None);
println!("{}", padded_title);
println!("{}", format!("{}", "".repeat(box_width)));
for (label, content) in labels {
let combined = format!("{} {}", label, content);
let line_padded = pad_str(&combined, box_width - 2, Alignment::Left, None);
println!("{}", line_padded);
}
println!("{}", format!("{}", "".repeat(box_width)));
println!();
} }
Err(e) => eprintln!("{}", format!("Error: {}", e).colorize("bold red")), Err(e) => eprintln!("{}", format!("Error: {}", e).colorize("bold red")),
} }