revert tokio, allow filenames from stdin

this is to support s0hv's foo_discord_rich fb2k plugin by the way
This commit is contained in:
minish 2024-01-07 00:34:59 -05:00
parent 90eb47c4f6
commit a25374e48c
Signed by: min
GPG Key ID: FEECFF24EF0CE9E9
3 changed files with 19 additions and 82 deletions

69
Cargo.lock generated
View File

@ -526,16 +526,6 @@ version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456"
[[package]]
name = "lock_api"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.20"
@ -661,29 +651,6 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-targets 0.48.5",
]
[[package]]
name = "percent-encoding"
version = "2.3.1"
@ -697,7 +664,6 @@ dependencies = [
"anyhow",
"clap",
"reqwest",
"tokio",
]
[[package]]
@ -820,12 +786,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "security-framework"
version = "2.9.2"
@ -892,15 +852,6 @@ dependencies = [
"serde",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
dependencies = [
"libc",
]
[[package]]
name = "slab"
version = "0.4.9"
@ -910,12 +861,6 @@ dependencies = [
"autocfg",
]
[[package]]
name = "smallvec"
version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
[[package]]
name = "socket2"
version = "0.5.5"
@ -1003,25 +948,11 @@ dependencies = [
"libc",
"mio",
"num_cpus",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.48.0",
]
[[package]]
name = "tokio-macros"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tokio-native-tls"
version = "0.3.1"

View File

@ -8,5 +8,4 @@ edition = "2021"
[dependencies]
anyhow = "1.0.79"
clap = { version = "4.4.13", features = ["derive"] }
reqwest = { version = "0.11.23", features = ["gzip", "stream"] }
tokio = { version = "1.35.1", features = ["full"] }
reqwest = { version = "0.11.23", features = ["gzip", "stream", "blocking"] }

View File

@ -1,9 +1,9 @@
use std::{ffi::OsStr, path::Path};
use std::{ffi::OsStr, path::PathBuf};
use anyhow::{anyhow, Result};
use clap::Parser;
use reqwest::StatusCode;
use tokio::fs::File;
use std::{fs::File, io};
#[derive(Parser, Debug)]
struct Args {
@ -17,33 +17,40 @@ struct Args {
key: String,
}
#[tokio::main]
async fn main() -> Result<()> {
fn main() -> Result<()> {
let args = Args::parse();
let path = Path::new(&args.path);
let path = if args.path == "-" {
let mut line = String::new();
io::stdin().read_line(&mut line)?;
line.trim().into()
} else {
args.path
};
let file = File::open(&path).await?;
let path = PathBuf::from(&path);
let client = reqwest::Client::new();
let file = File::open(&path)?;
let client = reqwest::blocking::Client::new();
let res = client
.post(args.url)
.query(&[(
"name".to_string(),
&path.file_name()
&path
.file_name()
.and_then(OsStr::to_str)
.unwrap_or_default()
.to_string(),
)])
.query(&[("key".to_string(), &args.key)])
.body(file)
.send()
.await?;
.send()?;
match res.status() {
StatusCode::OK => {
println!("{}", res.text().await?);
println!("{}", res.text()?);
Ok(())
}
StatusCode::FORBIDDEN => Err(anyhow!("failed: invalid upload key! (403)")),