Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
appflowy committed Jun 19, 2024
1 parent 1e5fa14 commit 4d49961
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 99 deletions.
69 changes: 26 additions & 43 deletions frontend/rust-lib/flowy-core/src/integrate/trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use lib_infra::future::FutureResult;

use crate::integrate::server::{Server, ServerProvider};

#[async_trait]
impl StorageCloudService for ServerProvider {
fn get_object_url(&self, object_id: ObjectIdentity) -> FutureResult<String, FlowyError> {
let server = self.get_server();
Expand Down Expand Up @@ -87,74 +88,56 @@ impl StorageCloudService for ServerProvider {
storage.get_object_url_v1(workspace_id, parent_dir, file_id)
}

fn create_upload(
async fn create_upload(
&self,
workspace_id: &str,
parent_dir: &str,
file_id: &str,
content_type: &str,
) -> FutureResult<CreateUploadResponse, FlowyError> {
let workspace_id = workspace_id.to_string();
let parent_dir = parent_dir.to_string();
let content_type = content_type.to_string();
let file_id = file_id.to_string();
) -> Result<CreateUploadResponse, FlowyError> {
let server = self.get_server();
FutureResult::new(async move {
let storage = server?.file_storage().ok_or(FlowyError::internal())?;
storage
.create_upload(&workspace_id, &parent_dir, &file_id, &content_type)
.await
})
let storage = server?.file_storage().ok_or(FlowyError::internal())?;
storage
.create_upload(workspace_id, parent_dir, file_id, content_type)
.await
}

fn upload_part(
async fn upload_part(
&self,
workspace_id: &str,
parent_dir: &str,
upload_id: &str,
file_id: &str,
part_number: i32,
body: Vec<u8>,
) -> FutureResult<UploadPartResponse, FlowyError> {
let workspace_id = workspace_id.to_string();
let parent_dir = parent_dir.to_string();
let upload_id = upload_id.to_string();
let file_id = file_id.to_string();
) -> Result<UploadPartResponse, FlowyError> {
let server = self.get_server();
FutureResult::new(async move {
let storage = server?.file_storage().ok_or(FlowyError::internal())?;
storage
.upload_part(
&workspace_id,
&parent_dir,
&upload_id,
&file_id,
part_number,
body,
)
.await
})
let storage = server?.file_storage().ok_or(FlowyError::internal())?;
storage
.upload_part(
workspace_id,
parent_dir,
upload_id,
file_id,
part_number,
body,
)
.await
}

fn complete_upload(
async fn complete_upload(
&self,
workspace_id: &str,
parent_dir: &str,
upload_id: &str,
file_id: &str,
parts: Vec<CompletedPartRequest>,
) -> FutureResult<(), FlowyError> {
let workspace_id = workspace_id.to_string();
let parent_dir = parent_dir.to_string();
let upload_id = upload_id.to_string();
let file_id = file_id.to_string();
) -> Result<(), FlowyError> {
let server = self.get_server();
FutureResult::new(async move {
let storage = server?.file_storage().ok_or(FlowyError::internal())?;
storage
.complete_upload(&workspace_id, &parent_dir, &upload_id, &file_id, parts)
.await
})
let storage = server?.file_storage().ok_or(FlowyError::internal())?;
storage
.complete_upload(workspace_id, parent_dir, upload_id, file_id, parts)
.await
}
}

Expand Down
6 changes: 3 additions & 3 deletions frontend/rust-lib/flowy-document/tests/document/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ impl StorageService for DocumentTestFileStorageService {

async fn resume_upload(
&self,
workspace_id: &str,
parent_dir: &str,
file_id: &str,
_workspace_id: &str,
_parent_dir: &str,
_file_id: &str,
) -> Result<(), FlowyError> {
todo!()
}
Expand Down
84 changes: 37 additions & 47 deletions frontend/rust-lib/flowy-server/src/af_cloud/impls/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use client_api::entity::{CompleteUploadRequest, CreateUploadRequest};
use flowy_error::{FlowyError, FlowyResult};
use flowy_storage_pub::cloud::{ObjectIdentity, ObjectValue, StorageCloudService};
use flowy_storage_pub::storage::{CompletedPartRequest, CreateUploadResponse, UploadPartResponse};
use lib_infra::async_trait::async_trait;
use lib_infra::future::FutureResult;

use crate::af_cloud::AFServer;
Expand All @@ -14,6 +15,7 @@ impl<T> AFCloudFileStorageServiceImpl<T> {
}
}

#[async_trait]
impl<T> StorageCloudService for AFCloudFileStorageServiceImpl<T>
where
T: AFServer,
Expand Down Expand Up @@ -71,84 +73,72 @@ where
Ok(url)
}

fn create_upload(
async fn create_upload(
&self,
workspace_id: &str,
parent_dir: &str,
file_id: &str,
content_type: &str,
) -> FutureResult<CreateUploadResponse, FlowyError> {
let workspace_id = workspace_id.to_string();
) -> Result<CreateUploadResponse, FlowyError> {
let parent_dir = parent_dir.to_string();
let content_type = content_type.to_string();
let file_id = file_id.to_string();
let try_get_client = self.0.try_get_client();
FutureResult::new(async move {
let client = try_get_client?;
let req = CreateUploadRequest {
file_id,
parent_dir,
content_type,
};
let resp = client.create_upload(&workspace_id, req).await?;
Ok(resp)
})
let client = try_get_client?;
let req = CreateUploadRequest {
file_id,
parent_dir,
content_type,
};
let resp = client.create_upload(workspace_id, req).await?;
Ok(resp)
}

fn upload_part(
async fn upload_part(
&self,
workspace_id: &str,
parent_dir: &str,
upload_id: &str,
file_id: &str,
part_number: i32,
body: Vec<u8>,
) -> FutureResult<UploadPartResponse, FlowyError> {
let workspace_id = workspace_id.to_string();
let parent_dir = parent_dir.to_string();
let upload_id = upload_id.to_string();
let file_id = file_id.to_string();
) -> Result<UploadPartResponse, FlowyError> {
let try_get_client = self.0.try_get_client();
FutureResult::new(async move {
let client = try_get_client?;
let resp = client
.upload_part(
&workspace_id,
&parent_dir,
&file_id,
&upload_id,
part_number,
body,
)
.await?;
let client = try_get_client?;
let resp = client
.upload_part(
workspace_id,
parent_dir,
file_id,
upload_id,
part_number,
body,
)
.await?;

Ok(resp)
})
Ok(resp)
}

fn complete_upload(
async fn complete_upload(
&self,
workspace_id: &str,
parent_dir: &str,
upload_id: &str,
file_id: &str,
parts: Vec<CompletedPartRequest>,
) -> FutureResult<(), FlowyError> {
let workspace_id = workspace_id.to_string();
) -> Result<(), FlowyError> {
let parent_dir = parent_dir.to_string();
let upload_id = upload_id.to_string();
let file_id = file_id.to_string();
let try_get_client = self.0.try_get_client();
FutureResult::new(async move {
let client = try_get_client?;
let request = CompleteUploadRequest {
file_id,
parent_dir,
upload_id,
parts,
};
client.complete_upload(&workspace_id, request).await?;
Ok(())
})
let client = try_get_client?;
let request = CompleteUploadRequest {
file_id,
parent_dir,
upload_id,
parts,
};
client.complete_upload(workspace_id, request).await?;
Ok(())
}
}
14 changes: 8 additions & 6 deletions frontend/rust-lib/flowy-storage-pub/src/cloud.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::storage::{CompletedPartRequest, CreateUploadResponse, UploadPartResponse};
use async_trait::async_trait;
use bytes::Bytes;
use flowy_error::{FlowyError, FlowyResult};
use lib_infra::future::FutureResult;
use mime::Mime;

#[async_trait]
pub trait StorageCloudService: Send + Sync {
/// Creates a new storage object.
///
Expand Down Expand Up @@ -51,32 +53,32 @@ pub trait StorageCloudService: Send + Sync {
file_id: &str,
) -> FlowyResult<String>;

fn create_upload(
async fn create_upload(
&self,
workspace_id: &str,
parent_dir: &str,
file_id: &str,
content_type: &str,
) -> FutureResult<CreateUploadResponse, FlowyError>;
) -> Result<CreateUploadResponse, FlowyError>;

fn upload_part(
async fn upload_part(
&self,
workspace_id: &str,
parent_dir: &str,
upload_id: &str,
file_id: &str,
part_number: i32,
body: Vec<u8>,
) -> FutureResult<UploadPartResponse, FlowyError>;
) -> Result<UploadPartResponse, FlowyError>;

fn complete_upload(
async fn complete_upload(
&self,
workspace_id: &str,
parent_dir: &str,
upload_id: &str,
file_id: &str,
parts: Vec<CompletedPartRequest>,
) -> FutureResult<(), FlowyError>;
) -> Result<(), FlowyError>;
}

pub trait FileStoragePlan: Send + Sync + 'static {
Expand Down

0 comments on commit 4d49961

Please sign in to comment.