sal/rfs-client/openapi/src/apis/block_management_api.rs
2025-06-24 16:10:39 +03:00

386 lines
17 KiB
Rust

/*
* rfs
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.2.0
*
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
/// struct for typed errors of method [`check_block_handler`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CheckBlockHandlerError {
Status404(models::ResponseError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_block_downloads_handler`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetBlockDownloadsHandlerError {
Status404(),
Status500(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_block_handler`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetBlockHandlerError {
Status404(models::ResponseError),
Status500(models::ResponseError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_blocks_by_hash_handler`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetBlocksByHashHandlerError {
Status404(models::ResponseError),
Status500(models::ResponseError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_user_blocks_handler`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetUserBlocksHandlerError {
Status401(),
Status500(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_blocks_handler`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListBlocksHandlerError {
Status400(),
Status500(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`upload_block_handler`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UploadBlockHandlerError {
Status400(models::ResponseError),
Status500(models::ResponseError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`verify_blocks_handler`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum VerifyBlocksHandlerError {
Status400(models::ResponseError),
Status500(models::ResponseError),
UnknownValue(serde_json::Value),
}
pub async fn check_block_handler(configuration: &configuration::Configuration, hash: &str) -> Result<(), Error<CheckBlockHandlerError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_hash = hash;
let uri_str = format!("{}/api/v1/block/{hash}", configuration.base_path, hash=crate::apis::urlencode(p_hash));
let mut req_builder = configuration.client.request(reqwest::Method::HEAD, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<CheckBlockHandlerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_block_downloads_handler(configuration: &configuration::Configuration, hash: &str) -> Result<models::BlockDownloadsResponse, Error<GetBlockDownloadsHandlerError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_hash = hash;
let uri_str = format!("{}/api/v1/block/{hash}/downloads", configuration.base_path, hash=crate::apis::urlencode(p_hash));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BlockDownloadsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BlockDownloadsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetBlockDownloadsHandlerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_block_handler(configuration: &configuration::Configuration, hash: &str) -> Result<reqwest::Response, Error<GetBlockHandlerError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_hash = hash;
let uri_str = format!("{}/api/v1/block/{hash}", configuration.base_path, hash=crate::apis::urlencode(p_hash));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(resp)
} else {
let content = resp.text().await?;
let entity: Option<GetBlockHandlerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// If the hash is a file hash, returns all blocks with their block index related to that file. If the hash is a block hash, returns the block itself.
pub async fn get_blocks_by_hash_handler(configuration: &configuration::Configuration, hash: &str) -> Result<models::BlocksResponse, Error<GetBlocksByHashHandlerError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_hash = hash;
let uri_str = format!("{}/api/v1/blocks/{hash}", configuration.base_path, hash=crate::apis::urlencode(p_hash));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BlocksResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BlocksResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetBlocksByHashHandlerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_user_blocks_handler(configuration: &configuration::Configuration, page: Option<i32>, per_page: Option<i32>) -> Result<models::UserBlocksResponse, Error<GetUserBlocksHandlerError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_page = page;
let p_per_page = per_page;
let uri_str = format!("{}/api/v1/user/blocks", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_page {
req_builder = req_builder.query(&[("page", &param_value.to_string())]);
}
if let Some(ref param_value) = p_per_page {
req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserBlocksResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UserBlocksResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetUserBlocksHandlerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn list_blocks_handler(configuration: &configuration::Configuration, page: Option<i32>, per_page: Option<i32>) -> Result<models::ListBlocksResponse, Error<ListBlocksHandlerError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_page = page;
let p_per_page = per_page;
let uri_str = format!("{}/api/v1/blocks", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_page {
req_builder = req_builder.query(&[("page", &param_value.to_string())]);
}
if let Some(ref param_value) = p_per_page {
req_builder = req_builder.query(&[("per_page", &param_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListBlocksResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListBlocksResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListBlocksHandlerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// If the block already exists, the server will return a 200 OK response. If the block is new, the server will return a 201 Created response.
pub async fn upload_block_handler(configuration: &configuration::Configuration, file_hash: &str, idx: i64, body: std::path::PathBuf) -> Result<models::BlockUploadedResponse, Error<UploadBlockHandlerError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_file_hash = file_hash;
let p_idx = idx;
let p_body = body;
let uri_str = format!("{}/api/v1/block", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
req_builder = req_builder.query(&[("file_hash", &p_file_hash.to_string())]);
req_builder = req_builder.query(&[("idx", &p_idx.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let file_content = std::fs::read(&p_body).map_err(|e| Error::Io(e))?;
req_builder = req_builder.body(file_content);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BlockUploadedResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BlockUploadedResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UploadBlockHandlerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns a list of missing blocks.
pub async fn verify_blocks_handler(configuration: &configuration::Configuration, verify_blocks_request: models::VerifyBlocksRequest) -> Result<models::VerifyBlocksResponse, Error<VerifyBlocksHandlerError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_verify_blocks_request = verify_blocks_request;
let uri_str = format!("{}/api/v1/block/verify", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_verify_blocks_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VerifyBlocksResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VerifyBlocksResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<VerifyBlocksHandlerError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}