initial commit

This commit is contained in:
minish 2024-01-07 00:00:56 -05:00
commit 90eb47c4f6
Signed by: min
GPG Key ID: FEECFF24EF0CE9E9
5 changed files with 1457 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

1368
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

12
Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "picup"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[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"] }

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 minish
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

55
src/main.rs Normal file
View File

@ -0,0 +1,55 @@
use std::{ffi::OsStr, path::Path};
use anyhow::{anyhow, Result};
use clap::Parser;
use reqwest::StatusCode;
use tokio::fs::File;
#[derive(Parser, Debug)]
struct Args {
#[arg(short, long)]
url: String,
#[arg(short, long)]
path: String,
#[arg(short, long, default_value = "")]
key: String,
}
#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();
let path = Path::new(&args.path);
let file = File::open(&path).await?;
let client = reqwest::Client::new();
let res = client
.post(args.url)
.query(&[(
"name".to_string(),
&path.file_name()
.and_then(OsStr::to_str)
.unwrap_or_default()
.to_string(),
)])
.query(&[("key".to_string(), &args.key)])
.body(file)
.send()
.await?;
match res.status() {
StatusCode::OK => {
println!("{}", res.text().await?);
Ok(())
}
StatusCode::FORBIDDEN => Err(anyhow!("failed: invalid upload key! (403)")),
StatusCode::BAD_REQUEST => Err(anyhow!(
"failed: invalid request! (400) make sure all required params are present"
)),
_ => Err(anyhow!("failed: non-success status code")),
}
}