mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
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:
@ -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)]
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user