#![allow(clippy::missing_errors_doc)]
use anyhow::Result;
use reqwest::{ Client, multipart::{ Form, Part } };
use crate::{ LITTER_API_URL, UASTRING, helper::{ file_name, file_stream } };
pub async fn upload<S: Into<String>>(file_path: S, time: u8) -> Result<String> {
let file_path = file_path.into();
let file = file_stream(&file_path).await?;
let file_name = file_name(&file_path);
let form = Form::new()
.text("reqtype", "fileupload")
.text("time", format!("{time}h"))
.part("fileToUpload", Part::stream(file).file_name(file_name));
Ok(
Client::builder()
.user_agent(UASTRING)
.build()
.unwrap_or_else(|_| Client::new())
.post(LITTER_API_URL)
.multipart(form)
.send().await?
.text().await?
)
}