#![allow(clippy::missing_errors_doc)]
use anyhow::Result;
use reqwest::Client;
use super::{ CATBOX_API_URL, UASTRING };
pub async fn create<S: Into<String>>(
title: S,
desc: S,
user_hash: S,
files: Vec<S>
) -> Result<String> {
let files: Vec<_> = files.into_iter().map(Into::into).collect();
let form = [
("reqtype", "createalbum"),
("userhash", &user_hash.into()),
("title", &title.into()),
("desc", &desc.into()),
("files", &files.join(" ")),
];
Ok(
Client::builder()
.user_agent(UASTRING)
.build()
.unwrap_or_else(|_| Client::new())
.post(CATBOX_API_URL)
.form(&form)
.send().await?
.text().await?
)
}
pub async fn edit<S: Into<String>>(
short: S,
title: S,
desc: S,
user_hash: S,
files: Vec<S>
) -> Result<String> {
let files: Vec<_> = files.into_iter().map(Into::into).collect();
let form = [
("reqtype", "editalbum"),
("userhash", &user_hash.into()),
("short", &short.into()),
("title", &title.into()),
("desc", &desc.into()),
("files", &files.join(" ")),
];
Ok(
Client::builder()
.user_agent(UASTRING)
.build()
.unwrap_or_else(|_| Client::new())
.post(CATBOX_API_URL)
.form(&form)
.send().await?
.text().await?
)
}
pub async fn add_files<S: Into<String>>(short: S, user_hash: S, files: Vec<S>) -> Result<String> {
let files: Vec<_> = files.into_iter().map(Into::into).collect();
let form = [
("reqtype", "addtoalbum"),
("short", &short.into()),
("userhash", &user_hash.into()),
("files", &files.join(" ")),
];
Ok(
Client::builder()
.user_agent(UASTRING)
.build()
.unwrap_or_else(|_| Client::new())
.post(CATBOX_API_URL)
.form(&form)
.send().await?
.text().await?
)
}
pub async fn remove_files<S: Into<String>>(
short: S,
user_hash: S,
files: Vec<S>
) -> Result<String> {
let files: Vec<_> = files.into_iter().map(Into::into).collect();
let form = [
("reqtype", "removefromalbum"),
("userhash", &user_hash.into()),
("short", &short.into()),
("files", &files.join(" ")),
];
Ok(
Client::builder()
.user_agent(UASTRING)
.build()
.unwrap_or_else(|_| Client::new())
.post(CATBOX_API_URL)
.form(&form)
.send().await?
.text().await?
)
}
pub async fn delete<S: Into<String>>(short: S, user_hash: S) -> Result<String> {
let form = [
("reqtype", "deletealbum"),
("userhash", &user_hash.into()),
("short", &short.into()),
];
Ok(
Client::builder()
.user_agent(UASTRING)
.build()
.unwrap_or_else(|_| Client::new())
.post(CATBOX_API_URL)
.form(&form)
.send().await?
.text().await?
)
}