feat: cloud workspace api (#4469)

* feat: workspace api

* feat: added cloud apis for add and delete workspace

* feat: add and delete workspace event handlers

* chore: rust fmt

* chore: save user workspace

* test: add test

* test: add test

* chore: add to gitignore

* feat: update api add name to workspace

* chore: cargo clippy and rename to create

* chore: add envrc and direnv to gitignore

* chore: change name to create workspace instead of add workspace

* chore: update client api rev

* feat: add create workspace impl

* chore: restore gitignore to original

* test: fix create workspace event test

* fix: change delete workspace input

* fix: compile

* fix: create workspace test

* feat: add error code for request payload too large

* chore: remove cargo backup files

* feat: add is async option for upload file handler

* chore: update client api version

---------

Co-authored-by: nathan <nathan@appflowy.io>
This commit is contained in:
Zack
2024-02-04 05:49:45 +08:00
committed by GitHub
parent 250f29f325
commit 08938b8c70
46 changed files with 457 additions and 128 deletions

View File

@ -73,6 +73,9 @@ pub struct UploadFileParamsPB {
#[pb(index = 2)]
#[validate(custom = "required_valid_path")]
pub local_file_path: String,
#[pb(index = 3)]
pub is_async: bool,
}
#[derive(Default, ProtoBuf, Validate)]

View File

@ -411,10 +411,13 @@ pub(crate) async fn upload_file_handler(
let AFPluginData(UploadFileParamsPB {
workspace_id,
local_file_path,
is_async,
}) = params;
let manager = upgrade_document(manager)?;
let url = manager.upload_file(workspace_id, &local_file_path).await?;
let url = manager
.upload_file(workspace_id, &local_file_path, is_async)
.await?;
Ok(AFPluginData(UploadedFilePB {
url,

View File

@ -254,18 +254,25 @@ impl DocumentManager {
&self,
workspace_id: String,
local_file_path: &str,
is_async: bool,
) -> FlowyResult<String> {
let (object_identity, object_value) = object_from_disk(&workspace_id, local_file_path).await?;
let storage_service = self.storage_service_upgrade()?;
let url = storage_service.get_object_url(object_identity).await?;
// let the upload happen in the background
let clone_url = url.clone();
af_spawn(async move {
if let Err(e) = storage_service.put_object(clone_url, object_value).await {
error!("upload file failed: {}", e);
}
});
match is_async {
false => storage_service.put_object(clone_url, object_value).await?,
true => {
// let the upload happen in the background
af_spawn(async move {
if let Err(e) = storage_service.put_object(clone_url, object_value).await {
error!("upload file failed: {}", e);
}
});
},
}
Ok(url)
}