Skip to main content

mesa_dev_oapi/apis/
lfs_api.rs

1/*
2 * Depot API
3 *
4 * Depot HTTP API v1
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`post_by_org_by_repo_lfs_objects`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum PostByOrgByRepoLfsObjectsError {
22    Status400(models::PostByOrgApiKeys400Response),
23    Status401(models::PostByOrgApiKeys400Response),
24    Status403(models::PostByOrgApiKeys400Response),
25    Status404(models::PostByOrgApiKeys400Response),
26    Status406(models::PostByOrgApiKeys400Response),
27    Status409(models::PostByOrgApiKeys400Response),
28    Status500(models::PostByOrgApiKeys400Response),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`post_by_org_by_repo_lfs_objects_download`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum PostByOrgByRepoLfsObjectsDownloadError {
36    Status400(models::PostByOrgApiKeys400Response),
37    Status401(models::PostByOrgApiKeys400Response),
38    Status403(models::PostByOrgApiKeys400Response),
39    Status404(models::PostByOrgApiKeys400Response),
40    Status406(models::PostByOrgApiKeys400Response),
41    Status409(models::PostByOrgApiKeys400Response),
42    Status500(models::PostByOrgApiKeys400Response),
43    UnknownValue(serde_json::Value),
44}
45
46
47/// Request pre-signed URLs to upload large files to LFS storage. After uploading, use the commit endpoint with LFS file references to create commits.
48pub async fn post_by_org_by_repo_lfs_objects(configuration: &configuration::Configuration, org: &str, repo: &str, post_by_org_by_repo_lfs_objects_request: Option<models::PostByOrgByRepoLfsObjectsRequest>) -> Result<models::PostByOrgByRepoLfsObjects200Response, Error<PostByOrgByRepoLfsObjectsError>> {
49    // add a prefix to parameters to efficiently prevent name collisions
50    let p_path_org = org;
51    let p_path_repo = repo;
52    let p_body_post_by_org_by_repo_lfs_objects_request = post_by_org_by_repo_lfs_objects_request;
53
54    let uri_str = format!("{}/{org}/{repo}/lfs/objects", configuration.base_path, org=crate::apis::urlencode(p_path_org), repo=crate::apis::urlencode(p_path_repo));
55    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
56
57    if let Some(ref user_agent) = configuration.user_agent {
58        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
59    }
60    if let Some(ref token) = configuration.bearer_access_token {
61        req_builder = req_builder.bearer_auth(token.to_owned());
62    };
63    req_builder = req_builder.json(&p_body_post_by_org_by_repo_lfs_objects_request);
64
65    let req = req_builder.build()?;
66    let resp = configuration.client.execute(req).await?;
67
68    let status = resp.status();
69    let content_type = resp
70        .headers()
71        .get("content-type")
72        .and_then(|v| v.to_str().ok())
73        .unwrap_or("application/octet-stream");
74    let content_type = super::ContentType::from(content_type);
75
76    if !status.is_client_error() && !status.is_server_error() {
77        let content = resp.text().await?;
78        match content_type {
79            ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from),
80            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PostByOrgByRepoLfsObjects200Response`"))),
81            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::PostByOrgByRepoLfsObjects200Response`")))),
82        }
83    } else {
84        let content = resp.text().await?;
85        let entity: Option<PostByOrgByRepoLfsObjectsError> = serde_json::from_str(&content).ok();
86        Err(Error::ResponseError(ResponseContent { status, content, entity }))
87    }
88}
89
90/// Request pre-signed URLs to download large files from LFS storage.
91pub async fn post_by_org_by_repo_lfs_objects_download(configuration: &configuration::Configuration, org: &str, repo: &str, post_by_org_by_repo_lfs_objects_download_request: Option<models::PostByOrgByRepoLfsObjectsDownloadRequest>) -> Result<models::PostByOrgByRepoLfsObjects200Response, Error<PostByOrgByRepoLfsObjectsDownloadError>> {
92    // add a prefix to parameters to efficiently prevent name collisions
93    let p_path_org = org;
94    let p_path_repo = repo;
95    let p_body_post_by_org_by_repo_lfs_objects_download_request = post_by_org_by_repo_lfs_objects_download_request;
96
97    let uri_str = format!("{}/{org}/{repo}/lfs/objects/download", configuration.base_path, org=crate::apis::urlencode(p_path_org), repo=crate::apis::urlencode(p_path_repo));
98    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
99
100    if let Some(ref user_agent) = configuration.user_agent {
101        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
102    }
103    if let Some(ref token) = configuration.bearer_access_token {
104        req_builder = req_builder.bearer_auth(token.to_owned());
105    };
106    req_builder = req_builder.json(&p_body_post_by_org_by_repo_lfs_objects_download_request);
107
108    let req = req_builder.build()?;
109    let resp = configuration.client.execute(req).await?;
110
111    let status = resp.status();
112    let content_type = resp
113        .headers()
114        .get("content-type")
115        .and_then(|v| v.to_str().ok())
116        .unwrap_or("application/octet-stream");
117    let content_type = super::ContentType::from(content_type);
118
119    if !status.is_client_error() && !status.is_server_error() {
120        let content = resp.text().await?;
121        match content_type {
122            ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from),
123            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PostByOrgByRepoLfsObjects200Response`"))),
124            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::PostByOrgByRepoLfsObjects200Response`")))),
125        }
126    } else {
127        let content = resp.text().await?;
128        let entity: Option<PostByOrgByRepoLfsObjectsDownloadError> = serde_json::from_str(&content).ok();
129        Err(Error::ResponseError(ResponseContent { status, content, entity }))
130    }
131}
132