Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
chore: impl local unspport
Nathan791a79a2341b
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dartindex 04eb701a66..4ff5ccbf67 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart@@ -389,7 +389,7 @@ class _CreateWorkspaceButton extends StatelessWidget {workspaceBloc.add(UserWorkspaceEvent.createWorkspace(name,- AuthTypePB.Local,+ AuthTypePB.Server,),);},diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lockindex dcac892c6a..4a3fae985a 100644--- a/frontend/rust-lib/Cargo.lock+++ b/frontend/rust-lib/Cargo.lock@@ -1270,7 +1270,7 @@ dependencies = [[[package]]name = "collab"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=1920e21f47e88a238e11356be0b3ef2f3acdc23e#1920e21f47e88a238e11356be0b3ef2f3acdc23e"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3#f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3"dependencies = ["anyhow","arc-swap",@@ -1295,7 +1295,7 @@ dependencies = [[[package]]name = "collab-database"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=1920e21f47e88a238e11356be0b3ef2f3acdc23e#1920e21f47e88a238e11356be0b3ef2f3acdc23e"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3#f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3"dependencies = ["anyhow","async-trait",@@ -1335,7 +1335,7 @@ dependencies = [[[package]]name = "collab-document"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=1920e21f47e88a238e11356be0b3ef2f3acdc23e#1920e21f47e88a238e11356be0b3ef2f3acdc23e"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3#f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3"dependencies = ["anyhow","arc-swap",@@ -1356,7 +1356,7 @@ dependencies = [[[package]]name = "collab-entity"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=1920e21f47e88a238e11356be0b3ef2f3acdc23e#1920e21f47e88a238e11356be0b3ef2f3acdc23e"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3#f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3"dependencies = ["anyhow","bytes",@@ -1376,7 +1376,7 @@ dependencies = [[[package]]name = "collab-folder"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=1920e21f47e88a238e11356be0b3ef2f3acdc23e#1920e21f47e88a238e11356be0b3ef2f3acdc23e"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3#f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3"dependencies = ["anyhow","arc-swap",@@ -1398,7 +1398,7 @@ dependencies = [[[package]]name = "collab-importer"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=1920e21f47e88a238e11356be0b3ef2f3acdc23e#1920e21f47e88a238e11356be0b3ef2f3acdc23e"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3#f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3"dependencies = ["anyhow","async-recursion",@@ -1461,7 +1461,7 @@ dependencies = [[[package]]name = "collab-plugins"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=1920e21f47e88a238e11356be0b3ef2f3acdc23e#1920e21f47e88a238e11356be0b3ef2f3acdc23e"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3#f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3"dependencies = ["anyhow","async-stream",@@ -1539,7 +1539,7 @@ dependencies = [[[package]]name = "collab-user"version = "0.2.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=1920e21f47e88a238e11356be0b3ef2f3acdc23e#1920e21f47e88a238e11356be0b3ef2f3acdc23e"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3#f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3"dependencies = ["anyhow","collab",diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.tomlindex 61259d1e7b..1561c7ea7d 100644--- a/frontend/rust-lib/Cargo.toml+++ b/frontend/rust-lib/Cargo.toml@@ -144,14 +144,14 @@ rocksdb = { git = "https://github.com/rust-rocksdb/rust-rocksdb", rev = "1710120# To switch to the local path, run:# scripts/tool/update_collab_source.sh# ⚠️⚠️⚠️️-collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "1920e21f47e88a238e11356be0b3ef2f3acdc23e" }-collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "1920e21f47e88a238e11356be0b3ef2f3acdc23e" }-collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "1920e21f47e88a238e11356be0b3ef2f3acdc23e" }-collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "1920e21f47e88a238e11356be0b3ef2f3acdc23e" }-collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "1920e21f47e88a238e11356be0b3ef2f3acdc23e" }-collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "1920e21f47e88a238e11356be0b3ef2f3acdc23e" }-collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "1920e21f47e88a238e11356be0b3ef2f3acdc23e" }-collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "1920e21f47e88a238e11356be0b3ef2f3acdc23e" }+collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3" }+collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3" }+collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3" }+collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3" }+collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3" }+collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3" }+collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3" }+collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f029a79e6112c296286cd7bb4c6dcaa4cf0d33f3" }# Working directory: frontend# To update the commit ID, run:diff --git a/frontend/rust-lib/flowy-server/src/local_server/impls/database.rs b/frontend/rust-lib/flowy-server/src/local_server/impls/database.rsindex 46b0cdd649..ad1184a09a 100644--- a/frontend/rust-lib/flowy-server/src/local_server/impls/database.rs+++ b/frontend/rust-lib/flowy-server/src/local_server/impls/database.rs@@ -1,16 +1,18 @@#![allow(unused_variables)]++use crate::af_cloud::define::LoggedUser;+use crate::local_server::util::default_encode_collab_for_collab_type;use collab::entity::EncodedCollab;-use collab_database::database::default_database_data;-use collab_database::workspace_database::default_workspace_database_data;-use collab_document::document_data::default_document_collab_data;use collab_entity::CollabType;-use collab_user::core::default_user_awareness_data;use flowy_database_pub::cloud::{DatabaseCloudService, DatabaseSnapshot, EncodeCollabByOid};-use flowy_error::FlowyError;+use flowy_error::{ErrorCode, FlowyError};use lib_infra::async_trait::async_trait;+use std::sync::Arc;use uuid::Uuid;-pub(crate) struct LocalServerDatabaseCloudServiceImpl();+pub(crate) struct LocalServerDatabaseCloudServiceImpl {+ pub logged_user: Arc<dyn LoggedUser>,+}#[async_trait]impl DatabaseCloudService for LocalServerDatabaseCloudServiceImpl {@@ -18,24 +20,20 @@ impl DatabaseCloudService for LocalServerDatabaseCloudServiceImpl {&self,object_id: &Uuid,collab_type: CollabType,- workspace_id: &Uuid,+ _workspace_id: &Uuid, // underscore to silence “unused” warning) -> Result<Option<EncodedCollab>, FlowyError> {+ let uid = self.logged_user.user_id()?;let object_id = object_id.to_string();- match collab_type {- CollabType::Document => {- let encode_collab = default_document_collab_data(&object_id)?;- Ok(Some(encode_collab))- },- CollabType::Database => default_database_data(&object_id)- .await- .map(Some)- .map_err(Into::into),- CollabType::WorkspaceDatabase => Ok(Some(default_workspace_database_data(&object_id))),- CollabType::Folder => Ok(None),- CollabType::DatabaseRow => Ok(None),- CollabType::UserAwareness => Ok(Some(default_user_awareness_data(&object_id))),- CollabType::Unknown => Ok(None),- }+ default_encode_collab_for_collab_type(uid, &object_id, collab_type)+ .await+ .map(Some)+ .or_else(|err| {+ if matches!(err.code, ErrorCode::NotSupportYet) {+ Ok(None)+ } else {+ Err(err)+ }+ })}async fn create_database_encode_collab(diff --git a/frontend/rust-lib/flowy-server/src/local_server/impls/folder.rs b/frontend/rust-lib/flowy-server/src/local_server/impls/folder.rsindex 1acb0846c9..7f4720de99 100644--- a/frontend/rust-lib/flowy-server/src/local_server/impls/folder.rs+++ b/frontend/rust-lib/flowy-server/src/local_server/impls/folder.rs@@ -1,9 +1,14 @@#![allow(unused_variables)]use crate::af_cloud::define::LoggedUser;+use crate::local_server::util::default_encode_collab_for_collab_type;use client_api::entity::workspace_dto::PublishInfoView;use client_api::entity::PublishInfo;+use collab::core::origin::CollabOrigin;+use collab::preclude::Collab;use collab_entity::CollabType;+use collab_plugins::local_storage::kv::doc::CollabKVAction;+use collab_plugins::local_storage::kv::KVTransactionDB;use flowy_error::FlowyError;use flowy_folder_pub::cloud::{gen_workspace_id, FolderCloudService, FolderCollabParams, FolderData, FolderSnapshot,@@ -61,7 +66,29 @@ impl FolderCloudService for LocalServerFolderCloudServiceImpl {collab_type: CollabType,object_id: &Uuid,) -> Result<Vec<u8>, FlowyError> {- Err(FlowyError::local_version_not_support())+ let object_id = object_id.to_string();+ let workspace_id = workspace_id.to_string();+ let collab_db = self.logged_user.get_collab_db(uid)?.upgrade().unwrap();+ let read_txn = collab_db.read_txn();+ let is_exist = read_txn.is_exist(uid, &workspace_id.to_string(), &object_id.to_string());+ if is_exist {+ // load doc+ let collab = Collab::new_with_origin(CollabOrigin::Empty, &object_id, vec![], false);+ read_txn.load_doc(uid, &workspace_id, &object_id, collab.doc())?;+ let data = collab.encode_collab_v1(|c| {+ collab_type+ .validate_require_data(c)+ .map_err(|err| FlowyError::invalid_data().with_context(err))?;+ Ok::<_, FlowyError>(())+ })?;+ Ok(data.doc_state.to_vec())+ } else {+ let data = default_encode_collab_for_collab_type(uid, &object_id, collab_type).await?;+ drop(read_txn);++ // create default folder doc+ Err(FlowyError::local_version_not_support())+ }}async fn batch_create_folder_collab_objects(diff --git a/frontend/rust-lib/flowy-server/src/local_server/mod.rs b/frontend/rust-lib/flowy-server/src/local_server/mod.rsindex 6e67356fd9..2b9fe07250 100644--- a/frontend/rust-lib/flowy-server/src/local_server/mod.rs+++ b/frontend/rust-lib/flowy-server/src/local_server/mod.rs@@ -3,3 +3,4 @@ pub use server::*;pub mod impls;mod server;pub(crate) mod uid;+mod util;diff --git a/frontend/rust-lib/flowy-server/src/local_server/server.rs b/frontend/rust-lib/flowy-server/src/local_server/server.rsindex 8ddcb2d76c..9ce19f5df6 100644--- a/frontend/rust-lib/flowy-server/src/local_server/server.rs+++ b/frontend/rust-lib/flowy-server/src/local_server/server.rs@@ -53,7 +53,9 @@ impl AppFlowyServer for LocalServer {}fn database_service(&self) -> Arc<dyn DatabaseCloudService> {- Arc::new(LocalServerDatabaseCloudServiceImpl())+ Arc::new(LocalServerDatabaseCloudServiceImpl {+ logged_user: self.logged_user.clone(),+ })}fn database_ai_service(&self) -> Option<Arc<dyn DatabaseAIService>> {diff --git a/frontend/rust-lib/flowy-server/src/local_server/util.rs b/frontend/rust-lib/flowy-server/src/local_server/util.rsnew file mode 100644index 0000000000..bd00212afb--- /dev/null+++ b/frontend/rust-lib/flowy-server/src/local_server/util.rs@@ -0,0 +1,45 @@+use collab::core::origin::CollabOrigin;+use collab::entity::EncodedCollab;+use collab::preclude::Collab;+use collab_database::database::default_database_data;+use collab_database::workspace_database::default_workspace_database_data;+use collab_document::document_data::default_document_collab_data;+use collab_entity::CollabType;+use collab_user::core::default_user_awareness_data;+use flowy_error::{FlowyError, FlowyResult};++pub async fn default_encode_collab_for_collab_type(+ _uid: i64,+ object_id: &str,+ collab_type: CollabType,+) -> FlowyResult<EncodedCollab> {+ match collab_type {+ CollabType::Document => {+ let encode_collab = default_document_collab_data(object_id)?;+ Ok(encode_collab)+ },+ CollabType::Database => default_database_data(object_id).await.map_err(Into::into),+ CollabType::WorkspaceDatabase => Ok(default_workspace_database_data(object_id)),+ CollabType::Folder => {+ // let collab = Collab::new_with_origin(CollabOrigin::Empty, object_id, vec![], false);+ // let workspace = Workspace::new(object_id.to_string(), "".to_string(), uid);+ // let folder_data = FolderData::new(workspace);+ // let folder = Folder::create(uid, collab, None, folder_data);+ // let data = folder.encode_collab_v1(|c| {+ // collab_type+ // .validate_require_data(c)+ // .map_err(|err| FlowyError::invalid_data().with_context(err))?;+ // Ok::<_, FlowyError>(())+ // })?;+ // Ok(data)+ Err(FlowyError::not_support())+ },+ CollabType::DatabaseRow => Err(FlowyError::not_support()),+ CollabType::UserAwareness => Ok(default_user_awareness_data(object_id)),+ CollabType::Unknown => {+ let collab = Collab::new_with_origin(CollabOrigin::Empty, object_id, vec![], false);+ let data = collab.encode_collab_v1(|_| Ok::<_, FlowyError>(()))?;+ Ok(data)+ },+ }+}