Skip to content

Commit 206ccb2

Browse files
authored
fix: supabase sync (#4243)
* chore: fix supabse sync * chore: bump collab * chore: fmt * chore: remove unused key
1 parent d2ccec7 commit 206ccb2

File tree

22 files changed

+132
-88
lines changed

22 files changed

+132
-88
lines changed

frontend/appflowy_tauri/src-tauri/Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/appflowy_tauri/src-tauri/Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "a45
6767
# To switch to the local path, run:
6868
# scripts/tool/update_collab_source.sh
6969
# ⚠️⚠️⚠️️
70-
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
71-
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
72-
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
73-
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
74-
collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
75-
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
76-
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
77-
collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
70+
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
71+
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
72+
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
73+
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
74+
collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
75+
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
76+
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
77+
collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
7878

7979

8080

frontend/rust-lib/Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/rust-lib/Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "a45
109109
# To switch to the local path, run:
110110
# scripts/tool/update_collab_source.sh
111111
# ⚠️⚠️⚠️️
112-
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
113-
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
114-
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
115-
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
116-
collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
117-
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
118-
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
119-
collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "bdc26b9a37399c9bc02e2309c54e31c664a9574d" }
112+
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
113+
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
114+
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
115+
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
116+
collab-plugins = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
117+
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
118+
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }
119+
collab-persistence = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "e7d77a4b233886c4e9b7e03934c03d3e4489ec86" }

frontend/rust-lib/dart-ffi/src/env_serde.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ impl AppFlowyDartConfiguration {
2828

2929
pub fn write_env(&self) {
3030
self.authenticator_type.write_env();
31-
self.appflowy_cloud_config.write_env();
32-
self.supabase_config.write_env();
31+
match self.authenticator_type {
32+
AuthenticatorType::AppFlowyCloud => {
33+
self.appflowy_cloud_config.write_env();
34+
},
35+
AuthenticatorType::Supabase => {
36+
self.supabase_config.write_env();
37+
},
38+
_ => {},
39+
}
3340

3441
for (k, v) in self.envs.iter() {
3542
std::env::set_var(k, v);

frontend/rust-lib/event-integration/src/user_event.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,21 @@ impl EventIntegrationTest {
190190
Ok(user_profile)
191191
}
192192

193-
pub async fn import_appflowy_data(&self, path: String, name: &str) {
193+
pub async fn import_appflowy_data(&self, path: String, name: &str) -> Result<(), FlowyError> {
194194
let payload = ImportAppFlowyDataPB {
195195
path,
196196
import_container_name: name.to_string(),
197197
};
198-
EventBuilder::new(self.clone())
198+
match EventBuilder::new(self.clone())
199199
.event(FolderEvent::ImportAppFlowyDataFolder)
200200
.payload(payload)
201201
.async_send()
202-
.await;
202+
.await
203+
.error()
204+
{
205+
Some(err) => Err(err),
206+
None => Ok(()),
207+
}
203208
}
204209
}
205210

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use collab_entity::CollabType;
44
use event_integration::user_event::user_localhost_af_cloud;
55
use event_integration::{document_data_from_document_doc_state, EventIntegrationTest};
66
use flowy_core::DEFAULT_NAME;
7+
use flowy_user::errors::ErrorCode;
78
use serde_json::{json, Value};
9+
use std::env::temp_dir;
810

911
#[tokio::test]
1012
async fn import_appflowy_data_folder_test() {
@@ -29,7 +31,8 @@ async fn import_appflowy_data_folder_test() {
2931
user_db_path.to_str().unwrap().to_string(),
3032
&import_container_name,
3133
)
32-
.await;
34+
.await
35+
.unwrap();
3336
// after import, the structure is:
3437
// workspace:
3538
// view: Getting Started
@@ -74,7 +77,8 @@ async fn import_appflowy_data_folder_test2() {
7477
user_db_path.to_str().unwrap().to_string(),
7578
&import_container_name,
7679
)
77-
.await;
80+
.await
81+
.unwrap();
7882

7983
let views = test.get_all_workspace_views().await;
8084
assert_eq!(views.len(), 2);
@@ -84,6 +88,19 @@ async fn import_appflowy_data_folder_test2() {
8488
drop(cleaner);
8589
}
8690

91+
#[tokio::test]
92+
async fn import_empty_appflowy_data_folder_test() {
93+
let path = temp_dir();
94+
user_localhost_af_cloud().await;
95+
let test = EventIntegrationTest::new_with_name(DEFAULT_NAME).await;
96+
let _ = test.af_cloud_sign_up().await;
97+
let error = test
98+
.import_appflowy_data(path.to_str().unwrap().to_string(), "empty_folder")
99+
.await
100+
.unwrap_err();
101+
assert_eq!(error.code, ErrorCode::AppFlowyDataFolderImportError);
102+
}
103+
87104
#[tokio::test]
88105
async fn import_appflowy_data_folder_multiple_times_test() {
89106
let import_container_name = "040_local_2".to_string();
@@ -106,7 +123,8 @@ async fn import_appflowy_data_folder_multiple_times_test() {
106123
user_db_path.to_str().unwrap().to_string(),
107124
&import_container_name,
108125
)
109-
.await;
126+
.await
127+
.unwrap();
110128
// after import, the structure is:
111129
// Getting Started
112130
// 040_local_2
@@ -121,7 +139,8 @@ async fn import_appflowy_data_folder_multiple_times_test() {
121139
user_db_path.to_str().unwrap().to_string(),
122140
&import_container_name,
123141
)
124-
.await;
142+
.await
143+
.unwrap();
125144
// after import, the structure is:
126145
// Getting Started
127146
// 040_local_2
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
mod anon_user_test;
22
mod auth_test;
3+
mod import_af_data_folder_test;
34
mod member_test;
4-
mod sync_third_party_data_test;

frontend/rust-lib/flowy-core/src/integrate/server.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ use flowy_server::supabase::SupabaseServer;
1212
use flowy_server::{AppFlowyEncryption, AppFlowyServer, EncryptionImpl};
1313
use flowy_server_config::af_cloud_config::AFCloudConfiguration;
1414
use flowy_server_config::supabase_config::SupabaseConfiguration;
15+
use flowy_server_config::AuthenticatorType;
1516
use flowy_sqlite::kv::StorePreferences;
1617
use flowy_user_deps::entities::*;
1718

1819
use crate::AppFlowyCoreConfig;
1920

20-
pub(crate) const SERVER_PROVIDER_TYPE_KEY: &str = "server_provider_type";
21-
2221
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize_repr, Deserialize_repr)]
2322
#[repr(u8)]
2423
pub enum Server {
@@ -53,6 +52,7 @@ pub struct ServerProvider {
5352
server: RwLock<Server>,
5453
providers: RwLock<HashMap<Server, Arc<dyn AppFlowyServer>>>,
5554
pub(crate) encryption: RwLock<Arc<dyn AppFlowyEncryption>>,
55+
#[allow(dead_code)]
5656
pub(crate) store_preferences: Weak<StorePreferences>,
5757
pub(crate) enable_sync: RwLock<bool>,
5858
pub(crate) uid: Arc<RwLock<Option<i64>>>,
@@ -166,10 +166,12 @@ impl From<&Authenticator> for Server {
166166
}
167167
}
168168

169-
pub fn current_server_type(store_preferences: &Arc<StorePreferences>) -> Server {
170-
store_preferences
171-
.get_object::<Server>(SERVER_PROVIDER_TYPE_KEY)
172-
.unwrap_or(Server::Local)
169+
pub fn current_server_type() -> Server {
170+
match AuthenticatorType::from_env() {
171+
AuthenticatorType::Local => Server::Local,
172+
AuthenticatorType::Supabase => Server::Supabase,
173+
AuthenticatorType::AppFlowyCloud => Server::AppFlowyCloud,
174+
}
173175
}
174176

175177
struct LocalServerDBImpl {

frontend/rust-lib/flowy-core/src/integrate/trait_impls.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use flowy_user_deps::cloud::{UserCloudService, UserCloudServiceProvider};
2828
use flowy_user_deps::entities::{Authenticator, UserTokenState};
2929
use lib_infra::future::{to_fut, Fut, FutureResult};
3030

31-
use crate::integrate::server::{Server, ServerProvider, SERVER_PROVIDER_TYPE_KEY};
31+
use crate::integrate::server::{Server, ServerProvider};
3232

3333
impl FileStorageService for ServerProvider {
3434
fn create_object(&self, object: StorageObject) -> FutureResult<String, FlowyError> {
@@ -96,18 +96,6 @@ impl UserCloudServiceProvider for ServerProvider {
9696
fn set_authenticator(&self, authenticator: Authenticator) {
9797
let server_type: Server = authenticator.into();
9898
self.set_server_type(server_type.clone());
99-
100-
match self.store_preferences.upgrade() {
101-
None => tracing::error!("🔴Failed to update server provider type: store preferences is drop"),
102-
Some(store_preferences) => {
103-
match store_preferences.set_object(SERVER_PROVIDER_TYPE_KEY, server_type.clone()) {
104-
Ok(_) => tracing::trace!("Set server provider: {:?}", server_type),
105-
Err(e) => {
106-
tracing::error!("🔴Failed to update server provider type: {:?}", e);
107-
},
108-
}
109-
},
110-
}
11199
}
112100

113101
fn get_authenticator(&self) -> Authenticator {

0 commit comments

Comments
 (0)