Remove custom multipart response definition

This commit is contained in:
asonix 2023-12-05 13:22:04 -06:00
parent ea1cd5b0f2
commit 388cb4019f
1 changed files with 8 additions and 16 deletions

View File

@ -16,7 +16,10 @@ use base64::{prelude::BASE64_STANDARD, Engine};
use futures_util::{Stream, StreamExt, TryStreamExt};
use reqwest::{header::RANGE, Body, Response};
use reqwest_middleware::{ClientWithMiddleware, RequestBuilder};
use rusty_s3::{actions::S3Action, Bucket, BucketError, Credentials, UrlStyle};
use rusty_s3::{
actions::{CreateMultipartUpload, S3Action},
Bucket, BucketError, Credentials, UrlStyle,
};
use std::{pin::Pin, string::FromUtf8Error, time::Duration};
use storage_path_generator::{Generator, Path};
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
@ -105,16 +108,6 @@ pub(crate) struct ObjectStoreConfig {
client_timeout: u64,
}
#[derive(serde::Deserialize, Debug)]
struct InitiateMultipartUploadResponse {
#[serde(rename = "Bucket")]
_bucket: String,
#[serde(rename = "Key")]
_key: String,
#[serde(rename = "UploadId")]
upload_id: String,
}
impl ObjectStoreConfig {
pub(crate) fn build(self, client: ClientWithMiddleware) -> ObjectStore {
ObjectStore {
@ -232,10 +225,9 @@ impl Store for ObjectStore {
return Err(status_error(response).await);
}
let body = response.bytes().await.map_err(ObjectError::Request)?;
let body: InitiateMultipartUploadResponse =
quick_xml::de::from_reader(&*body).map_err(ObjectError::from)?;
let upload_id = &body.upload_id;
let body = response.text().await.map_err(ObjectError::Request)?;
let body = CreateMultipartUpload::parse_response(&body).map_err(ObjectError::from)?;
let upload_id = body.upload_id();
// hack-ish: use async block as Result boundary
let res = async {
@ -257,7 +249,7 @@ impl Store for ObjectStore {
let this = self.clone();
let object_id2 = object_id.clone();
let upload_id2 = upload_id.clone();
let upload_id2 = upload_id.to_string();
let handle = actix_rt::spawn(
async move {
let response = this