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
fix: supabase sync (#4243)
Nathan.fooo206ccb2c4339
diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.lock b/frontend/appflowy_tauri/src-tauri/Cargo.lockindex 8d1f34442b..7a0bcf437c 100644--- a/frontend/appflowy_tauri/src-tauri/Cargo.lock+++ b/frontend/appflowy_tauri/src-tauri/Cargo.lock@@ -883,7 +883,7 @@ dependencies = [[[package]]name = "collab"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","async-trait",@@ -902,7 +902,7 @@ dependencies = [[[package]]name = "collab-database"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","async-trait",@@ -932,7 +932,7 @@ dependencies = [[[package]]name = "collab-derive"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["proc-macro2","quote",@@ -944,7 +944,7 @@ dependencies = [[[package]]name = "collab-document"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","collab",@@ -963,7 +963,7 @@ dependencies = [[[package]]name = "collab-entity"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","bytes",@@ -977,7 +977,7 @@ dependencies = [[[package]]name = "collab-folder"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","chrono",@@ -1019,7 +1019,7 @@ dependencies = [[[package]]name = "collab-persistence"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","async-trait",@@ -1040,7 +1040,7 @@ dependencies = [[[package]]name = "collab-plugins"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","async-trait",@@ -1066,7 +1066,7 @@ dependencies = [[[package]]name = "collab-user"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","collab",diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.toml b/frontend/appflowy_tauri/src-tauri/Cargo.tomlindex b48542feef..4b9ff16dfe 100644--- a/frontend/appflowy_tauri/src-tauri/Cargo.toml+++ b/frontend/appflowy_tauri/src-tauri/Cargo.toml@@ -67,14 +67,14 @@ client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "a45# To switch to the local path, run:# scripts/tool/update_collab_source.sh# ⚠️⚠️⚠️️-collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }+collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lockindex 3fc928e588..4e0fa41c54 100644--- a/frontend/rust-lib/Cargo.lock+++ b/frontend/rust-lib/Cargo.lock@@ -733,7 +733,7 @@ dependencies = [[[package]]name = "collab"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","async-trait",@@ -752,7 +752,7 @@ dependencies = [[[package]]name = "collab-database"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","async-trait",@@ -782,7 +782,7 @@ dependencies = [[[package]]name = "collab-derive"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["proc-macro2","quote",@@ -794,7 +794,7 @@ dependencies = [[[package]]name = "collab-document"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","collab",@@ -813,7 +813,7 @@ dependencies = [[[package]]name = "collab-entity"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","bytes",@@ -827,7 +827,7 @@ dependencies = [[[package]]name = "collab-folder"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","chrono",@@ -869,7 +869,7 @@ dependencies = [[[package]]name = "collab-persistence"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","async-trait",@@ -890,7 +890,7 @@ dependencies = [[[package]]name = "collab-plugins"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","async-trait",@@ -916,7 +916,7 @@ dependencies = [[[package]]name = "collab-user"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=bdc26b9a37399c9bc02e2309c54e31c664a9574d#bdc26b9a37399c9bc02e2309c54e31c664a9574d"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=e7d77a4b233886c4e9b7e03934c03d3e4489ec86#e7d77a4b233886c4e9b7e03934c03d3e4489ec86"dependencies = ["anyhow","collab",diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.tomlindex f038067321..0d78534349 100644--- a/frontend/rust-lib/Cargo.toml+++ b/frontend/rust-lib/Cargo.toml@@ -109,11 +109,11 @@ client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "a45# To switch to the local path, run:# scripts/tool/update_collab_source.sh# ⚠️⚠️⚠️️-collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }-collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }+collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }+collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }diff --git a/frontend/rust-lib/dart-ffi/src/env_serde.rs b/frontend/rust-lib/dart-ffi/src/env_serde.rsindex 596b9cbe98..e24aa3db0d 100644--- a/frontend/rust-lib/dart-ffi/src/env_serde.rs+++ b/frontend/rust-lib/dart-ffi/src/env_serde.rs@@ -28,8 +28,15 @@ impl AppFlowyDartConfiguration {pub fn write_env(&self) {self.authenticator_type.write_env();- self.appflowy_cloud_config.write_env();- self.supabase_config.write_env();+ match self.authenticator_type {+ AuthenticatorType::AppFlowyCloud => {+ self.appflowy_cloud_config.write_env();+ },+ AuthenticatorType::Supabase => {+ self.supabase_config.write_env();+ },+ _ => {},+ }for (k, v) in self.envs.iter() {std::env::set_var(k, v);diff --git a/frontend/rust-lib/event-integration/src/user_event.rs b/frontend/rust-lib/event-integration/src/user_event.rsindex a257e0b193..6f1eea5737 100644--- a/frontend/rust-lib/event-integration/src/user_event.rs+++ b/frontend/rust-lib/event-integration/src/user_event.rs@@ -190,16 +190,21 @@ impl EventIntegrationTest {Ok(user_profile)}- pub async fn import_appflowy_data(&self, path: String, name: &str) {+ pub async fn import_appflowy_data(&self, path: String, name: &str) -> Result<(), FlowyError> {let payload = ImportAppFlowyDataPB {path,import_container_name: name.to_string(),};- EventBuilder::new(self.clone())+ match EventBuilder::new(self.clone()).event(FolderEvent::ImportAppFlowyDataFolder).payload(payload).async_send()- .await;+ .await+ .error()+ {+ Some(err) => Err(err),+ None => Ok(()),+ }}}diff --git a/frontend/rust-lib/event-integration/tests/user/af_cloud_test/sync_third_party_data_test.rs b/frontend/rust-lib/event-integration/tests/user/af_cloud_test/import_af_data_folder_test.rssimilarity index 93%rename from frontend/rust-lib/event-integration/tests/user/af_cloud_test/sync_third_party_data_test.rsrename to frontend/rust-lib/event-integration/tests/user/af_cloud_test/import_af_data_folder_test.rsindex 68db4e73fb..bd59e48578 100644--- a/frontend/rust-lib/event-integration/tests/user/af_cloud_test/sync_third_party_data_test.rs+++ b/frontend/rust-lib/event-integration/tests/user/af_cloud_test/import_af_data_folder_test.rs@@ -4,7 +4,9 @@ use collab_entity::CollabType;use event_integration::user_event::user_localhost_af_cloud;use event_integration::{document_data_from_document_doc_state, EventIntegrationTest};use flowy_core::DEFAULT_NAME;+use flowy_user::errors::ErrorCode;use serde_json::{json, Value};+use std::env::temp_dir;#[tokio::test]async fn import_appflowy_data_folder_test() {@@ -29,7 +31,8 @@ async fn import_appflowy_data_folder_test() {user_db_path.to_str().unwrap().to_string(),&import_container_name,)- .await;+ .await+ .unwrap();// after import, the structure is:// workspace:// view: Getting Started@@ -74,7 +77,8 @@ async fn import_appflowy_data_folder_test2() {user_db_path.to_str().unwrap().to_string(),&import_container_name,)- .await;+ .await+ .unwrap();let views = test.get_all_workspace_views().await;assert_eq!(views.len(), 2);@@ -84,6 +88,19 @@ async fn import_appflowy_data_folder_test2() {drop(cleaner);}+#[tokio::test]+async fn import_empty_appflowy_data_folder_test() {+ let path = temp_dir();+ user_localhost_af_cloud().await;+ let test = EventIntegrationTest::new_with_name(DEFAULT_NAME).await;+ let _ = test.af_cloud_sign_up().await;+ let error = test+ .import_appflowy_data(path.to_str().unwrap().to_string(), "empty_folder")+ .await+ .unwrap_err();+ assert_eq!(error.code, ErrorCode::AppFlowyDataFolderImportError);+}+#[tokio::test]async fn import_appflowy_data_folder_multiple_times_test() {let import_container_name = "040_local_2".to_string();@@ -106,7 +123,8 @@ async fn import_appflowy_data_folder_multiple_times_test() {user_db_path.to_str().unwrap().to_string(),&import_container_name,)- .await;+ .await+ .unwrap();// after import, the structure is:// Getting Started// 040_local_2@@ -121,7 +139,8 @@ async fn import_appflowy_data_folder_multiple_times_test() {user_db_path.to_str().unwrap().to_string(),&import_container_name,)- .await;+ .await+ .unwrap();// after import, the structure is:// Getting Started// 040_local_2diff --git a/frontend/rust-lib/event-integration/tests/user/af_cloud_test/mod.rs b/frontend/rust-lib/event-integration/tests/user/af_cloud_test/mod.rsindex e939cca9f9..645fd4399a 100644--- a/frontend/rust-lib/event-integration/tests/user/af_cloud_test/mod.rs+++ b/frontend/rust-lib/event-integration/tests/user/af_cloud_test/mod.rs@@ -1,4 +1,4 @@mod anon_user_test;mod auth_test;+mod import_af_data_folder_test;mod member_test;-mod sync_third_party_data_test;diff --git a/frontend/rust-lib/flowy-core/src/integrate/server.rs b/frontend/rust-lib/flowy-core/src/integrate/server.rsindex 003fef856f..72da086d9e 100644--- a/frontend/rust-lib/flowy-core/src/integrate/server.rs+++ b/frontend/rust-lib/flowy-core/src/integrate/server.rs@@ -12,13 +12,12 @@ use flowy_server::supabase::SupabaseServer;use flowy_server::{AppFlowyEncryption, AppFlowyServer, EncryptionImpl};use flowy_server_config::af_cloud_config::AFCloudConfiguration;use flowy_server_config::supabase_config::SupabaseConfiguration;+use flowy_server_config::AuthenticatorType;use flowy_sqlite::kv::StorePreferences;use flowy_user_deps::entities::*;use crate::AppFlowyCoreConfig;-pub(crate) const SERVER_PROVIDER_TYPE_KEY: &str = "server_provider_type";-#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize_repr, Deserialize_repr)]#[repr(u8)]pub enum Server {@@ -53,6 +52,7 @@ pub struct ServerProvider {server: RwLock<Server>,providers: RwLock<HashMap<Server, Arc<dyn AppFlowyServer>>>,pub(crate) encryption: RwLock<Arc<dyn AppFlowyEncryption>>,+ #[allow(dead_code)]pub(crate) store_preferences: Weak<StorePreferences>,pub(crate) enable_sync: RwLock<bool>,pub(crate) uid: Arc<RwLock<Option<i64>>>,@@ -166,10 +166,12 @@ impl From<&Authenticator> for Server {}}-pub fn current_server_type(store_preferences: &Arc<StorePreferences>) -> Server {- store_preferences- .get_object::<Server>(SERVER_PROVIDER_TYPE_KEY)- .unwrap_or(Server::Local)+pub fn current_server_type() -> Server {+ match AuthenticatorType::from_env() {+ AuthenticatorType::Local => Server::Local,+ AuthenticatorType::Supabase => Server::Supabase,+ AuthenticatorType::AppFlowyCloud => Server::AppFlowyCloud,+ }}struct LocalServerDBImpl {diff --git a/frontend/rust-lib/flowy-core/src/integrate/trait_impls.rs b/frontend/rust-lib/flowy-core/src/integrate/trait_impls.rsindex 0221e2d7a8..f1fc46758c 100644--- a/frontend/rust-lib/flowy-core/src/integrate/trait_impls.rs+++ b/frontend/rust-lib/flowy-core/src/integrate/trait_impls.rs@@ -28,7 +28,7 @@ use flowy_user_deps::cloud::{UserCloudService, UserCloudServiceProvider};use flowy_user_deps::entities::{Authenticator, UserTokenState};use lib_infra::future::{to_fut, Fut, FutureResult};-use crate::integrate::server::{Server, ServerProvider, SERVER_PROVIDER_TYPE_KEY};+use crate::integrate::server::{Server, ServerProvider};impl FileStorageService for ServerProvider {fn create_object(&self, object: StorageObject) -> FutureResult<String, FlowyError> {@@ -96,18 +96,6 @@ impl UserCloudServiceProvider for ServerProvider {fn set_authenticator(&self, authenticator: Authenticator) {let server_type: Server = authenticator.into();self.set_server_type(server_type.clone());-- match self.store_preferences.upgrade() {- None => tracing::error!("🔴Failed to update server provider type: store preferences is drop"),- Some(store_preferences) => {- match store_preferences.set_object(SERVER_PROVIDER_TYPE_KEY, server_type.clone()) {- Ok(_) => tracing::trace!("Set server provider: {:?}", server_type),- Err(e) => {- tracing::error!("🔴Failed to update server provider type: {:?}", e);- },- }- },- }}fn get_authenticator(&self) -> Authenticator {diff --git a/frontend/rust-lib/flowy-core/src/integrate/user.rs b/frontend/rust-lib/flowy-core/src/integrate/user.rsindex cf2a765368..54e958ae3e 100644--- a/frontend/rust-lib/flowy-core/src/integrate/user.rs+++ b/frontend/rust-lib/flowy-core/src/integrate/user.rs@@ -14,7 +14,7 @@ use flowy_user_deps::cloud::{UserCloudConfig, UserCloudServiceProvider};use flowy_user_deps::entities::{Authenticator, UserProfile, UserWorkspace};use lib_infra::future::{to_fut, Fut};-use crate::integrate::server::ServerProvider;+use crate::integrate::server::{Server, ServerProvider};use crate::AppFlowyCoreConfig;pub(crate) struct UserStatusCallbackImpl {@@ -131,6 +131,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {let database_manager = self.database_manager.clone();let user_workspace = user_workspace.clone();let document_manager = self.document_manager.clone();+ let server_type = self.server_provider.get_server_type();to_fut(async move {event!(@@ -155,7 +156,21 @@ impl UserStatusCallback for UserStatusCallbackImpl {).await{- Ok(doc_state) => FolderInitDataSource::Cloud(doc_state),+ Ok(doc_state) => match server_type {+ Server::Local => FolderInitDataSource::LocalDisk {+ create_if_not_exist: true,+ },+ Server::AppFlowyCloud => FolderInitDataSource::Cloud(doc_state),+ Server::Supabase => {+ if is_new_user {+ FolderInitDataSource::LocalDisk {+ create_if_not_exist: true,+ }+ } else {+ FolderInitDataSource::Cloud(doc_state)+ }+ },+ },Err(_) => FolderInitDataSource::LocalDisk {create_if_not_exist: true,},diff --git a/frontend/rust-lib/flowy-core/src/lib.rs b/frontend/rust-lib/flowy-core/src/lib.rsindex d1462e4cac..889be21db1 100644--- a/frontend/rust-lib/flowy-core/src/lib.rs+++ b/frontend/rust-lib/flowy-core/src/lib.rs@@ -96,7 +96,7 @@ impl AppFlowyCore {let task_dispatcher = Arc::new(RwLock::new(task_scheduler));runtime.spawn(TaskRunner::run(task_dispatcher.clone()));- let server_type = current_server_type(&store_preference);+ let server_type = current_server_type();debug!("🔥runtime:{}, server:{}", runtime, server_type);let server_provider = Arc::new(ServerProvider::new(config.clone(),diff --git a/frontend/rust-lib/flowy-error/src/code.rs b/frontend/rust-lib/flowy-error/src/code.rsindex 88cea70b07..f3e0632d6b 100644--- a/frontend/rust-lib/flowy-error/src/code.rs+++ b/frontend/rust-lib/flowy-error/src/code.rs@@ -265,6 +265,9 @@ pub enum ErrorCode {#[error("Local version not support")]LocalVersionNotSupport = 88,++ #[error("AppFlowy data folder import error")]+ AppFlowyDataFolderImportError = 89,}impl ErrorCode {diff --git a/frontend/rust-lib/flowy-server/src/af_cloud/impls/folder.rs b/frontend/rust-lib/flowy-server/src/af_cloud/impls/folder.rsindex 88d7850733..709459e491 100644--- a/frontend/rust-lib/flowy-server/src/af_cloud/impls/folder.rs+++ b/frontend/rust-lib/flowy-server/src/af_cloud/impls/folder.rs@@ -75,7 +75,7 @@ where.doc_state.to_vec();let folder =- Folder::from_collab_raw_data(uid, CollabOrigin::Empty, doc_state, &workspace_id, vec![])?;+ Folder::from_collab_doc_state(uid, CollabOrigin::Empty, doc_state, &workspace_id, vec![])?;Ok(folder.get_folder_data())})}diff --git a/frontend/rust-lib/flowy-server/src/supabase/api/collab_storage.rs b/frontend/rust-lib/flowy-server/src/supabase/api/collab_storage.rsindex f1e2b11e0e..3138e72f86 100644--- a/frontend/rust-lib/flowy-server/src/supabase/api/collab_storage.rs+++ b/frontend/rust-lib/flowy-server/src/supabase/api/collab_storage.rs@@ -75,9 +75,9 @@ whereasync fn get_snapshots(&self, object_id: &str, limit: usize) -> Vec<RemoteCollabSnapshot> {match self.server.try_get_postgrest() {- Ok(postgrest) => match get_snapshots_from_server(object_id, postgrest, limit).await {- Ok(snapshots) => snapshots,- Err(err) => {+ Ok(postgrest) => get_snapshots_from_server(object_id, postgrest, limit)+ .await+ .unwrap_or_else(|err| {tracing::error!("🔴fetch snapshots by oid:{} with limit: {} failed: {:?}",object_id,@@ -85,8 +85,7 @@ whereerr);vec![]- },- },+ }),Err(err) => {tracing::error!("🔴get postgrest failed: {:?}", err);vec![]diff --git a/frontend/rust-lib/flowy-server/src/supabase/api/document.rs b/frontend/rust-lib/flowy-server/src/supabase/api/document.rsindex c9c36e25eb..47cfe11312 100644--- a/frontend/rust-lib/flowy-server/src/supabase/api/document.rs+++ b/frontend/rust-lib/flowy-server/src/supabase/api/document.rs@@ -82,7 +82,7 @@ wherefn get_document_data(&self,document_id: &str,- workspace_id: &str,+ _workspace_id: &str,) -> FutureResult<Option<DocumentData>, Error> {let try_get_postgrest = self.server.try_get_weak_postgrest();let document_id = document_id.to_string();diff --git a/frontend/rust-lib/flowy-server/src/supabase/api/folder.rs b/frontend/rust-lib/flowy-server/src/supabase/api/folder.rsindex 4ad6cf7305..de92fcea95 100644--- a/frontend/rust-lib/flowy-server/src/supabase/api/folder.rs+++ b/frontend/rust-lib/flowy-server/src/supabase/api/folder.rs@@ -99,12 +99,11 @@ where.iter().map(|update| update.value.as_ref()).collect::<Vec<&[u8]>>();-let doc_state = merge_updates_v1(&updates).map_err(|err| anyhow::anyhow!("merge updates failed: {:?}", err))?;let folder =- Folder::from_collab_raw_data(uid, CollabOrigin::Empty, doc_state, &workspace_id, vec![])?;+ Folder::from_collab_doc_state(uid, CollabOrigin::Empty, doc_state, &workspace_id, vec![])?;Ok(folder.get_folder_data())})}diff --git a/frontend/rust-lib/flowy-server/src/supabase/api/request.rs b/frontend/rust-lib/flowy-server/src/supabase/api/request.rsindex ae74d24d62..2162aeacbb 100644--- a/frontend/rust-lib/flowy-server/src/supabase/api/request.rs+++ b/frontend/rust-lib/flowy-server/src/supabase/api/request.rs@@ -73,11 +73,14 @@ impl Action for FetchObjectUpdateAction {Some(postgrest) => {match get_updates_from_server(&object_id, &object_ty, &postgrest).await {Ok(items) => {+ if items.is_empty() {+ return Ok(vec![]);+ }+let updates = items.iter().map(|update| update.value.as_ref()).collect::<Vec<&[u8]>>();-let doc_state = merge_updates_v1(&updates).map_err(|err| anyhow::anyhow!("merge updates failed: {:?}", err))?;Ok(doc_state)@@ -280,15 +283,18 @@ pub async fn batch_get_updates_from_server(if let Some(oid) = record.get("oid").and_then(|value| value.as_str()) {match parser_updates_form_json(record.clone(), &postgrest.secret()) {Ok(items) => {- let updates = items- .iter()- .map(|update| update.value.as_ref())- .collect::<Vec<&[u8]>>();-- let doc_state = merge_updates_v1(&updates)- .map_err(|err| anyhow::anyhow!("merge updates failed: {:?}", err))?;+ if items.is_empty() {+ updates_by_oid.insert(oid.to_string(), vec![]);+ } else {+ let updates = items+ .iter()+ .map(|update| update.value.as_ref())+ .collect::<Vec<&[u8]>>();- updates_by_oid.insert(oid.to_string(), doc_state);+ let doc_state = merge_updates_v1(&updates)+ .map_err(|err| anyhow::anyhow!("merge updates failed: {:?}", err))?;+ updates_by_oid.insert(oid.to_string(), doc_state);+ }},Err(e) => {tracing::error!("parser_updates_form_json error: {:?}", e);diff --git a/frontend/rust-lib/flowy-server/tests/supabase_test/util.rs b/frontend/rust-lib/flowy-server/tests/supabase_test/util.rsindex 984041677d..b0ab3028b1 100644--- a/frontend/rust-lib/flowy-server/tests/supabase_test/util.rs+++ b/frontend/rust-lib/flowy-server/tests/supabase_test/util.rs@@ -120,7 +120,7 @@ pub async fn print_encryption_folder_snapshot(.pop().unwrap();let collab = Arc::new(- MutexCollab::new_with_raw_data(CollabOrigin::Empty, folder_id, snapshot.blob, vec![]).unwrap(),+ MutexCollab::new_with_doc_state(CollabOrigin::Empty, folder_id, snapshot.blob, vec![]).unwrap(),);let folder_data = Folder::open(uid, collab, None).unwrap()diff --git a/frontend/rust-lib/flowy-user/src/anon_user/migrate_anon_user_collab.rs b/frontend/rust-lib/flowy-user/src/anon_user/migrate_anon_user_collab.rsindex 34a319f0a9..3c615dca22 100644--- a/frontend/rust-lib/flowy-user/src/anon_user/migrate_anon_user_collab.rs+++ b/frontend/rust-lib/flowy-user/src/anon_user/migrate_anon_user_collab.rs@@ -297,7 +297,7 @@ where}let origin = CollabOrigin::Client(CollabClient::new(new_uid, "phantom"));- let new_folder_collab = Collab::new_with_raw_data(origin, new_workspace_id, vec![], vec![])+ let new_folder_collab = Collab::new_with_doc_state(origin, new_workspace_id, vec![], vec![]).map_err(|err| PersistenceError::Internal(err.into()))?;let mutex_collab = Arc::new(MutexCollab::from_collab(new_folder_collab));let new_user_id = UserId::from(new_uid);diff --git a/frontend/rust-lib/flowy-user/src/manager.rs b/frontend/rust-lib/flowy-user/src/manager.rsindex d433196a10..22a5cd1aa2 100644--- a/frontend/rust-lib/flowy-user/src/manager.rs+++ b/frontend/rust-lib/flowy-user/src/manager.rs@@ -670,7 +670,8 @@ impl UserManager {pub fn import_data(&self, source: ImportDataSource) -> Result<ImportData, FlowyError> {let session = self.get_session()?;let collab_db = self.database.get_collab_db(session.user_id)?;- let import_result = import_data(&session, source, collab_db)?;+ let import_result = import_data(&session, source, collab_db)+ .map_err(|err| FlowyError::new(ErrorCode::AppFlowyDataFolderImportError, err.to_string()))?;Ok(import_result)}diff --git a/frontend/rust-lib/flowy-user/src/services/data_import/appflowy_data_import.rs b/frontend/rust-lib/flowy-user/src/services/data_import/appflowy_data_import.rsindex 6afc3324d1..6d59155d2e 100644--- a/frontend/rust-lib/flowy-user/src/services/data_import/appflowy_data_import.rs+++ b/frontend/rust-lib/flowy-user/src/services/data_import/appflowy_data_import.rs@@ -332,7 +332,7 @@ whereW: YrsDocAction<'a>,PersistenceError: From<W::Error>,{- let collab = Collab::new_with_raw_data(CollabOrigin::Empty, new_object_id, doc_state, vec![])?;+ let collab = Collab::new_with_doc_state(CollabOrigin::Empty, new_object_id, doc_state, vec![])?;import_collab_object(&collab, new_uid, new_object_id, w_txn);Ok(())}