/*
* SpatioAPI
*
* The REST API that owns every resource in your Spatio workspace: notes, sheets, slides, tasks, calendar events, mail, chat, files, and contacts. SpatioMCP wraps this API; Spatio Desktop reads from it. You can call it directly from your own code. All requests must be authenticated with a Personal Access Token (`Authorization: Bearer pat_...`) or an OAuth 2.1 access token, and use HTTPS. Official SDKs (MIT, generated from this spec on every release): - TypeScript: https://github.com/spatio-labs/spatio-ts (`npm install @spatio-labs/spatio-ts`) - Python: https://github.com/spatio-labs/spatio-py (`pip install spatio-sdk`) - Go: https://github.com/spatio-labs/spatio-go (`go get github.com/spatio-labs/spatio-go`) This specification is generated from the platform-service Go source on every push to `main`. The spec, not hand-written documentation, is the source of truth: server stubs and SDKs are generated from it, and any drift between the spec and the running service fails CI.
*
* The version of the OpenAPI document: v1
* Contact: hello@spatio.app
* 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};
use tokio::fs::File as TokioFile;
use tokio_util::codec::{BytesCodec, FramedRead};
/// struct for typed errors of method [`bulk_delete_files`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum BulkDeleteFilesError {
Status400(models::ApiError),
Status401(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`bulk_move_files`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum BulkMoveFilesError {
Status400(models::ApiError),
Status401(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`commit_chunked_upload`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CommitChunkedUploadError {
Status400(models::ApiError),
Status401(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_file_folder`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateFileFolderError {
Status400(models::CreateNote400Response),
Status401(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_file`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteFileError {
Status401(models::ApiError),
Status404(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`extract_file_text`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ExtractFileTextError {
Status401(models::ApiError),
Status404(models::ApiError),
Status422(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_chunked_file_manifest`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetChunkedFileManifestError {
Status401(models::ApiError),
Status404(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_file`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFileError {
Status401(models::ApiError),
Status404(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_file_download_url`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFileDownloadUrlError {
Status401(models::ApiError),
Status404(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`init_chunked_upload`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum InitChunkedUploadError {
Status400(models::ApiError),
Status401(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_file_folders`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListFileFoldersError {
Status401(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_files`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListFilesError {
Status401(models::ApiError),
Status500(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_files_and_folders`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListFilesAndFoldersError {
Status401(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`move_file`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum MoveFileError {
Status400(models::ApiError),
Status401(models::ApiError),
Status404(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`search_files`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchFilesError {
Status401(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_file`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateFileError {
Status400(models::ApiError),
Status401(models::ApiError),
Status404(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`upload_chunked_block`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UploadChunkedBlockError {
Status400(models::ApiError),
Status401(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`upload_file`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UploadFileError {
Status400(models::CreateNote400Response),
Status401(models::ApiError),
Status402(models::QuotaExceededError),
Status500(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`upload_file_base64`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UploadFileBase64Error {
Status400(models::CreateNote400Response),
Status401(models::ApiError),
Status402(models::QuotaExceededError),
Status500(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_commit_chunked_upload`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceCommitChunkedUploadError {
Status401(models::ApiError),
Status403(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_create_file_folder`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceCreateFileFolderError {
Status401(models::ApiError),
Status403(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_delete_file`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceDeleteFileError {
Status401(models::ApiError),
Status403(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_get_file`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceGetFileError {
Status401(models::ApiError),
Status403(models::ApiError),
Status404(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_get_file_download`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceGetFileDownloadError {
Status401(models::ApiError),
Status403(models::ApiError),
Status404(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_get_file_manifest`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceGetFileManifestError {
Status401(models::ApiError),
Status403(models::ApiError),
Status404(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_init_chunked_upload`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceInitChunkedUploadError {
Status401(models::ApiError),
Status403(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_list_file_folders`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceListFileFoldersError {
Status401(models::ApiError),
Status403(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_list_files`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceListFilesError {
Status401(models::ApiError),
Status403(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_move_file`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceMoveFileError {
Status401(models::ApiError),
Status403(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_update_file`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceUpdateFileError {
Status401(models::ApiError),
Status403(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_upload_chunked_block`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceUploadChunkedBlockError {
Status401(models::ApiError),
Status403(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_upload_file`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceUploadFileError {
Status401(models::ApiError),
Status403(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`workspace_upload_file_base64`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkspaceUploadFileBase64Error {
Status401(models::ApiError),
Status403(models::ApiError),
UnknownValue(serde_json::Value),
}
pub async fn bulk_delete_files(configuration: &configuration::Configuration, bulk_delete_files_request: models::BulkDeleteFilesRequest) -> Result<models::BulkFilesResponse, Error<BulkDeleteFilesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_bulk_delete_files_request = bulk_delete_files_request;
let uri_str = format!("{}/v1/files/delete", 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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_bulk_delete_files_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::BulkFilesResponse`"))),
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::BulkFilesResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<BulkDeleteFilesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn bulk_move_files(configuration: &configuration::Configuration, bulk_move_files_request: models::BulkMoveFilesRequest) -> Result<models::BulkFilesResponse, Error<BulkMoveFilesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_bulk_move_files_request = bulk_move_files_request;
let uri_str = format!("{}/v1/files/move", 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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_bulk_move_files_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::BulkFilesResponse`"))),
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::BulkFilesResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<BulkMoveFilesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn commit_chunked_upload(configuration: &configuration::Configuration, commit_chunked_upload_request: models::CommitChunkedUploadRequest) -> Result<models::CommitChunkedUploadResponse, Error<CommitChunkedUploadError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_commit_chunked_upload_request = commit_chunked_upload_request;
let uri_str = format!("{}/v1/files/upload/chunked/commit", 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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_commit_chunked_upload_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::CommitChunkedUploadResponse`"))),
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::CommitChunkedUploadResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CommitChunkedUploadError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn create_file_folder(configuration: &configuration::Configuration, create_folder_request: models::CreateFolderRequest, account_id: Option<&str>, provider: Option<&str>, x_workspace_id: Option<&str>) -> Result<models::Folder, Error<CreateFileFolderError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_create_folder_request = create_folder_request;
let p_query_account_id = account_id;
let p_query_provider = provider;
let p_header_x_workspace_id = x_workspace_id;
let uri_str = format!("{}/v1/files/folders", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_provider {
req_builder = req_builder.query(&[("provider", ¶m_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(param_value) = p_header_x_workspace_id {
req_builder = req_builder.header("X-Workspace-ID", param_value.to_string());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_create_folder_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::Folder`"))),
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::Folder`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateFileFolderError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn delete_file(configuration: &configuration::Configuration, id: &str, account_id: Option<&str>, x_workspace_id: Option<&str>) -> Result<(), Error<DeleteFileError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let p_query_account_id = account_id;
let p_header_x_workspace_id = x_workspace_id;
let uri_str = format!("{}/v1/files/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_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(param_value) = p_header_x_workspace_id {
req_builder = req_builder.header("X-Workspace-ID", param_value.to_string());
}
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();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<DeleteFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn extract_file_text(configuration: &configuration::Configuration, id: &str, account_id: Option<&str>, x_workspace_id: Option<&str>, page_start: Option<i32>, page_end: Option<i32>, max_chars: Option<i32>) -> Result<models::ExtractTextResult, Error<ExtractFileTextError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let p_query_account_id = account_id;
let p_header_x_workspace_id = x_workspace_id;
let p_query_page_start = page_start;
let p_query_page_end = page_end;
let p_query_max_chars = max_chars;
let uri_str = format!("{}/v1/files/{id}/extract-text", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_page_start {
req_builder = req_builder.query(&[("pageStart", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_page_end {
req_builder = req_builder.query(&[("pageEnd", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_max_chars {
req_builder = req_builder.query(&[("maxChars", ¶m_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(param_value) = p_header_x_workspace_id {
req_builder = req_builder.header("X-Workspace-ID", param_value.to_string());
}
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::ExtractTextResult`"))),
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::ExtractTextResult`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ExtractFileTextError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Only meaningful for files uploaded via `upload/chunked/_*`. Files uploaded via `upload` or `upload/base64` return `404`.
pub async fn get_chunked_file_manifest(configuration: &configuration::Configuration, id: &str, account_id: Option<&str>, x_workspace_id: Option<&str>) -> Result<models::ChunkedFileManifest, Error<GetChunkedFileManifestError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let p_query_account_id = account_id;
let p_header_x_workspace_id = x_workspace_id;
let uri_str = format!("{}/v1/files/{id}/manifest", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_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(param_value) = p_header_x_workspace_id {
req_builder = req_builder.header("X-Workspace-ID", param_value.to_string());
}
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::ChunkedFileManifest`"))),
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::ChunkedFileManifest`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetChunkedFileManifestError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_file(configuration: &configuration::Configuration, id: &str, account_id: Option<&str>, x_workspace_id: Option<&str>) -> Result<models::SpatioFile, Error<GetFileError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let p_query_account_id = account_id;
let p_header_x_workspace_id = x_workspace_id;
let uri_str = format!("{}/v1/files/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_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(param_value) = p_header_x_workspace_id {
req_builder = req_builder.header("X-Workspace-ID", param_value.to_string());
}
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::SpatioFile`"))),
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::SpatioFile`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns a JSON envelope with a pre-signed URL pointing at the backing storage. Clients follow the URL — the platform does not stream bytes through itself.
pub async fn get_file_download_url(configuration: &configuration::Configuration, id: &str, account_id: Option<&str>, x_workspace_id: Option<&str>) -> Result<models::DownloadFileResponse, Error<GetFileDownloadUrlError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let p_query_account_id = account_id;
let p_header_x_workspace_id = x_workspace_id;
let uri_str = format!("{}/v1/files/{id}/download", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_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(param_value) = p_header_x_workspace_id {
req_builder = req_builder.header("X-Workspace-ID", param_value.to_string());
}
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::DownloadFileResponse`"))),
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::DownloadFileResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetFileDownloadUrlError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Client computes per-block hashes ahead of time and submits the list. The server replies with which blocks need uploading vs. already-on-server (deduplicated). Subsequent calls upload the missing blocks via `uploadChunkedBlock`, then `commit`.
pub async fn init_chunked_upload(configuration: &configuration::Configuration, init_chunked_upload_request: models::InitChunkedUploadRequest) -> Result<models::InitChunkedUploadResponse, Error<InitChunkedUploadError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_init_chunked_upload_request = init_chunked_upload_request;
let uri_str = format!("{}/v1/files/upload/chunked/init", 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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_init_chunked_upload_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::InitChunkedUploadResponse`"))),
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::InitChunkedUploadResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<InitChunkedUploadError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn list_file_folders(configuration: &configuration::Configuration, account_id: Option<&str>, provider: Option<&str>, x_workspace_id: Option<&str>, parent_id: Option<&str>, workspace_id: Option<&str>, organization_id: Option<&str>, limit: Option<i32>, offset: Option<i32>) -> Result<models::FolderListEnvelope, Error<ListFileFoldersError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_provider = provider;
let p_header_x_workspace_id = x_workspace_id;
let p_query_parent_id = parent_id;
let p_query_workspace_id = workspace_id;
let p_query_organization_id = organization_id;
let p_query_limit = limit;
let p_query_offset = offset;
let uri_str = format!("{}/v1/files/folders", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_provider {
req_builder = req_builder.query(&[("provider", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_parent_id {
req_builder = req_builder.query(&[("parentId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_workspace_id {
req_builder = req_builder.query(&[("workspaceId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_organization_id {
req_builder = req_builder.query(&[("organizationId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_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(param_value) = p_header_x_workspace_id {
req_builder = req_builder.header("X-Workspace-ID", param_value.to_string());
}
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::FolderListEnvelope`"))),
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::FolderListEnvelope`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListFileFoldersError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Fan-out list. Returns files from every connected file provider unless filtered by `?accountId=` or `?provider=`. Folder contents are scoped via `?folderId=`; omit for account root.
pub async fn list_files(configuration: &configuration::Configuration, account_id: Option<&str>, provider: Option<&str>, x_workspace_id: Option<&str>, folder_id: Option<&str>, workspace_id: Option<&str>, organization_id: Option<&str>, limit: Option<i32>, offset: Option<i32>, sort_by: Option<&str>, sort_order: Option<&str>) -> Result<models::FileListEnvelope, Error<ListFilesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_provider = provider;
let p_header_x_workspace_id = x_workspace_id;
let p_query_folder_id = folder_id;
let p_query_workspace_id = workspace_id;
let p_query_organization_id = organization_id;
let p_query_limit = limit;
let p_query_offset = offset;
let p_query_sort_by = sort_by;
let p_query_sort_order = sort_order;
let uri_str = format!("{}/v1/files", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_provider {
req_builder = req_builder.query(&[("provider", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_folder_id {
req_builder = req_builder.query(&[("folderId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_workspace_id {
req_builder = req_builder.query(&[("workspaceId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_organization_id {
req_builder = req_builder.query(&[("organizationId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_sort_by {
req_builder = req_builder.query(&[("sortBy", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_sort_order {
req_builder = req_builder.query(&[("sortOrder", ¶m_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(param_value) = p_header_x_workspace_id {
req_builder = req_builder.header("X-Workspace-ID", param_value.to_string());
}
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::FileListEnvelope`"))),
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::FileListEnvelope`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListFilesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Calls `listFiles` and `listFileFolders` in parallel and merges the results. Saves a round-trip when the UI shows both side-by-side.
pub async fn list_files_and_folders(configuration: &configuration::Configuration, account_id: Option<&str>, provider: Option<&str>, folder_id: Option<&str>, workspace_id: Option<&str>, organization_id: Option<&str>, limit: Option<i32>, offset: Option<i32>, sort_by: Option<&str>, sort_order: Option<&str>) -> Result<models::FilesAndFoldersResponse, Error<ListFilesAndFoldersError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_provider = provider;
let p_query_folder_id = folder_id;
let p_query_workspace_id = workspace_id;
let p_query_organization_id = organization_id;
let p_query_limit = limit;
let p_query_offset = offset;
let p_query_sort_by = sort_by;
let p_query_sort_order = sort_order;
let uri_str = format!("{}/v1/files/list", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_provider {
req_builder = req_builder.query(&[("provider", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_folder_id {
req_builder = req_builder.query(&[("folderId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_workspace_id {
req_builder = req_builder.query(&[("workspaceId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_organization_id {
req_builder = req_builder.query(&[("organizationId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_sort_by {
req_builder = req_builder.query(&[("sortBy", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_sort_order {
req_builder = req_builder.query(&[("sortOrder", ¶m_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::FilesAndFoldersResponse`"))),
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::FilesAndFoldersResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListFilesAndFoldersError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn move_file(configuration: &configuration::Configuration, id: &str, move_file_request: models::MoveFileRequest, account_id: Option<&str>, x_workspace_id: Option<&str>) -> Result<models::MoveFileResponse, Error<MoveFileError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let p_body_move_file_request = move_file_request;
let p_query_account_id = account_id;
let p_header_x_workspace_id = x_workspace_id;
let uri_str = format!("{}/v1/files/{id}/move", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_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(param_value) = p_header_x_workspace_id {
req_builder = req_builder.header("X-Workspace-ID", param_value.to_string());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_move_file_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::MoveFileResponse`"))),
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::MoveFileResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<MoveFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// In-memory search — the platform lists up to ~500 files and filters locally on `name` (case-insensitive substring). Not suitable for global search across very large file libraries.
pub async fn search_files(configuration: &configuration::Configuration, query: &str, account_id: Option<&str>, provider: Option<&str>, folder_id: Option<&str>, workspace_id: Option<&str>, organization_id: Option<&str>, limit: Option<i32>, offset: Option<i32>) -> Result<models::SearchFilesResponse, Error<SearchFilesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_query = query;
let p_query_account_id = account_id;
let p_query_provider = provider;
let p_query_folder_id = folder_id;
let p_query_workspace_id = workspace_id;
let p_query_organization_id = organization_id;
let p_query_limit = limit;
let p_query_offset = offset;
let uri_str = format!("{}/v1/files/search", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_provider {
req_builder = req_builder.query(&[("provider", ¶m_value.to_string())]);
}
req_builder = req_builder.query(&[("query", &p_query_query.to_string())]);
if let Some(ref param_value) = p_query_folder_id {
req_builder = req_builder.query(&[("folderId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_workspace_id {
req_builder = req_builder.query(&[("workspaceId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_organization_id {
req_builder = req_builder.query(&[("organizationId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_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::SearchFilesResponse`"))),
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::SearchFilesResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SearchFilesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn update_file(configuration: &configuration::Configuration, id: &str, update_file_request: models::UpdateFileRequest, account_id: Option<&str>, x_workspace_id: Option<&str>) -> Result<models::SpatioFile, Error<UpdateFileError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let p_body_update_file_request = update_file_request;
let p_query_account_id = account_id;
let p_header_x_workspace_id = x_workspace_id;
let uri_str = format!("{}/v1/files/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_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(param_value) = p_header_x_workspace_id {
req_builder = req_builder.header("X-Workspace-ID", param_value.to_string());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_update_file_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::SpatioFile`"))),
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::SpatioFile`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn upload_chunked_block(configuration: &configuration::Configuration, session_id: &str, block_hash: &str, block: std::path::PathBuf, block_index: Option<i32>) -> Result<models::UploadChunkedBlockResponse, Error<UploadChunkedBlockError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_form_session_id = session_id;
let p_form_block_hash = block_hash;
let p_form_block = block;
let p_form_block_index = block_index;
let uri_str = format!("{}/v1/files/upload/chunked/blocks", 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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let mut multipart_form = reqwest::multipart::Form::new();
multipart_form = multipart_form.text("sessionId", p_form_session_id.to_string());
multipart_form = multipart_form.text("blockHash", p_form_block_hash.to_string());
if let Some(param_value) = p_form_block_index {
multipart_form = multipart_form.text("blockIndex", param_value.to_string());
}
let file = TokioFile::open(&p_form_block).await?;
let stream = FramedRead::new(file, BytesCodec::new());
let file_name = p_form_block.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
let file_part = reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(stream)).file_name(file_name);
multipart_form = multipart_form.part("block", file_part);
req_builder = req_builder.multipart(multipart_form);
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::UploadChunkedBlockResponse`"))),
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::UploadChunkedBlockResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UploadChunkedBlockError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Multipart upload. Form field `file` carries the binary; auxiliary form fields scope the upload (`folderId`, `workspaceId`, `organizationId`, `accountId`). Max body size is currently 100 MB.
pub async fn upload_file(configuration: &configuration::Configuration, file: std::path::PathBuf, folder_id: Option<&str>, workspace_id: Option<&str>, organization_id: Option<&str>, account_id: Option<&str>) -> Result<models::SpatioFile, Error<UploadFileError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_form_file = file;
let p_form_folder_id = folder_id;
let p_form_workspace_id = workspace_id;
let p_form_organization_id = organization_id;
let p_form_account_id = account_id;
let uri_str = format!("{}/v1/files/upload", 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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let mut multipart_form = reqwest::multipart::Form::new();
let file = TokioFile::open(&p_form_file).await?;
let stream = FramedRead::new(file, BytesCodec::new());
let file_name = p_form_file.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
let file_part = reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(stream)).file_name(file_name);
multipart_form = multipart_form.part("file", file_part);
if let Some(param_value) = p_form_folder_id {
multipart_form = multipart_form.text("folderId", param_value.to_string());
}
if let Some(param_value) = p_form_workspace_id {
multipart_form = multipart_form.text("workspaceId", param_value.to_string());
}
if let Some(param_value) = p_form_organization_id {
multipart_form = multipart_form.text("organizationId", param_value.to_string());
}
if let Some(param_value) = p_form_account_id {
multipart_form = multipart_form.text("accountId", param_value.to_string());
}
req_builder = req_builder.multipart(multipart_form);
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::SpatioFile`"))),
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::SpatioFile`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UploadFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Equivalent to `uploadFile` for clients that can't post multipart bodies (e.g. browser fetch with strict CSP).
pub async fn upload_file_base64(configuration: &configuration::Configuration, upload_file_base64_request: models::UploadFileBase64Request) -> Result<models::SpatioFile, Error<UploadFileBase64Error>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_upload_file_base64_request = upload_file_base64_request;
let uri_str = format!("{}/v1/files/upload/base64", 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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_upload_file_base64_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::SpatioFile`"))),
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::SpatioFile`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UploadFileBase64Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_commit_chunked_upload(configuration: &configuration::Configuration, org: &str, workspace: &str, request_body: std::collections::HashMap<String, serde_json::Value>) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceCommitChunkedUploadError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let p_body_request_body = request_body;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files/upload/chunked/commit", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace));
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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_request_body);
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 `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceCommitChunkedUploadError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_create_file_folder(configuration: &configuration::Configuration, org: &str, workspace: &str, request_body: std::collections::HashMap<String, serde_json::Value>) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceCreateFileFolderError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let p_body_request_body = request_body;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files/folders", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace));
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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_request_body);
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 `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceCreateFileFolderError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_delete_file(configuration: &configuration::Configuration, org: &str, workspace: &str, id: &str) -> Result<(), Error<WorkspaceDeleteFileError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let p_path_id = id;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files/{id}", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace), id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
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();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceDeleteFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_get_file(configuration: &configuration::Configuration, org: &str, workspace: &str, id: &str) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceGetFileError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let p_path_id = id;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files/{id}", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace), id=crate::apis::urlencode(p_path_id));
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());
}
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 `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceGetFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_get_file_download(configuration: &configuration::Configuration, org: &str, workspace: &str, id: &str) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceGetFileDownloadError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let p_path_id = id;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files/{id}/download", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace), id=crate::apis::urlencode(p_path_id));
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());
}
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 `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceGetFileDownloadError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_get_file_manifest(configuration: &configuration::Configuration, org: &str, workspace: &str, id: &str) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceGetFileManifestError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let p_path_id = id;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files/{id}/manifest", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace), id=crate::apis::urlencode(p_path_id));
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());
}
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 `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceGetFileManifestError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_init_chunked_upload(configuration: &configuration::Configuration, org: &str, workspace: &str, request_body: std::collections::HashMap<String, serde_json::Value>) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceInitChunkedUploadError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let p_body_request_body = request_body;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files/upload/chunked/init", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace));
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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_request_body);
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 `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceInitChunkedUploadError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_list_file_folders(configuration: &configuration::Configuration, org: &str, workspace: &str) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceListFileFoldersError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files/folders", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace));
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());
}
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 `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceListFileFoldersError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_list_files(configuration: &configuration::Configuration, org: &str, workspace: &str) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceListFilesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace));
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());
}
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 `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceListFilesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_move_file(configuration: &configuration::Configuration, org: &str, workspace: &str, id: &str, request_body: std::collections::HashMap<String, serde_json::Value>) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceMoveFileError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let p_path_id = id;
let p_body_request_body = request_body;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files/{id}/move", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace), id=crate::apis::urlencode(p_path_id));
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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_request_body);
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 `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceMoveFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_update_file(configuration: &configuration::Configuration, org: &str, workspace: &str, id: &str, request_body: std::collections::HashMap<String, serde_json::Value>) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceUpdateFileError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let p_path_id = id;
let p_body_request_body = request_body;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files/{id}", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace), id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
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());
};
req_builder = req_builder.json(&p_body_request_body);
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 `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceUpdateFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_upload_chunked_block(configuration: &configuration::Configuration, org: &str, workspace: &str, body: std::path::PathBuf) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceUploadChunkedBlockError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let p_body_body = body;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files/upload/chunked/blocks", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace));
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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let file = TokioFile::open(p_body_body).await?;
let stream = FramedRead::new(file, BytesCodec::new());
req_builder = req_builder.body(reqwest::Body::wrap_stream(stream));
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 `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceUploadChunkedBlockError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_upload_file(configuration: &configuration::Configuration, org: &str, workspace: &str, file: Option<std::path::PathBuf>) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceUploadFileError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let p_form_file = file;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files/upload", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace));
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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let mut multipart_form = reqwest::multipart::Form::new();
if let Some(ref param_value) = p_form_file {
let file = TokioFile::open(param_value).await?;
let stream = FramedRead::new(file, BytesCodec::new());
let file_name = param_value.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
let file_part = reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(stream)).file_name(file_name);
multipart_form = multipart_form.part("file", file_part);
}
req_builder = req_builder.multipart(multipart_form);
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 `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceUploadFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn workspace_upload_file_base64(configuration: &configuration::Configuration, org: &str, workspace: &str, request_body: std::collections::HashMap<String, serde_json::Value>) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkspaceUploadFileBase64Error>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_org = org;
let p_path_workspace = workspace;
let p_body_request_body = request_body;
let uri_str = format!("{}/v1/organizations/{org}/workspaces/{workspace}/files/upload/base64", configuration.base_path, org=crate::apis::urlencode(p_path_org), workspace=crate::apis::urlencode(p_path_workspace));
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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_request_body);
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 `std::collections::HashMap<String, serde_json::Value>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WorkspaceUploadFileBase64Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}