chore: update client api commit id (#3745)

* chore: update client api commit id

* chore: fix test

* chore: remove check_visual_studio_installation task

* chore: update client api
This commit is contained in:
Nathan.fooo 2023-10-23 11:43:31 +08:00 committed by GitHub
parent 8e5b6b6e27
commit 1e9137fcfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 320 additions and 80 deletions

View File

@ -762,7 +762,7 @@ dependencies = [
[[package]]
name = "client-api"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"anyhow",
"bytes",
@ -775,6 +775,7 @@ dependencies = [
"gotrue-entity",
"lib0",
"mime",
"mime_guess",
"parking_lot",
"realtime-entity",
"reqwest",
@ -1437,15 +1438,17 @@ checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308"
[[package]]
name = "database-entity"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"anyhow",
"chrono",
"collab-entity",
"serde",
"serde_json",
"serde_repr",
"sqlx",
"thiserror",
"tracing",
"uuid",
"validator",
]
@ -2778,7 +2781,7 @@ dependencies = [
[[package]]
name = "gotrue"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"anyhow",
"futures-util",
@ -2794,9 +2797,11 @@ dependencies = [
[[package]]
name = "gotrue-entity"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"anyhow",
"jsonwebtoken",
"lazy_static",
"reqwest",
"serde",
"serde_json",
@ -3227,7 +3232,7 @@ dependencies = [
[[package]]
name = "infra"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"anyhow",
"reqwest",
@ -3373,6 +3378,20 @@ dependencies = [
"treediff",
]
[[package]]
name = "jsonwebtoken"
version = "8.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378"
dependencies = [
"base64 0.21.2",
"pem",
"ring",
"serde",
"serde_json",
"simple_asn1",
]
[[package]]
name = "kuchiki"
version = "0.8.1"
@ -3894,6 +3913,17 @@ dependencies = [
"winapi",
]
[[package]]
name = "num-bigint"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.45"
@ -4190,6 +4220,15 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "pem"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8"
dependencies = [
"base64 0.13.1",
]
[[package]]
name = "percent-encoding"
version = "2.3.0"
@ -4876,7 +4915,7 @@ dependencies = [
[[package]]
name = "realtime-entity"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"bytes",
"collab",
@ -5598,7 +5637,7 @@ dependencies = [
[[package]]
name = "shared_entity"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"anyhow",
"database-entity",
@ -5653,6 +5692,18 @@ version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf"
[[package]]
name = "simple_asn1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adc4e5204eb1910f40f9cfa375f6f05b68c3abac4b6fd879c8ff5e7ae8a0a085"
dependencies = [
"num-bigint",
"num-traits",
"thiserror",
"time",
]
[[package]]
name = "siphasher"
version = "0.3.10"

View File

@ -38,7 +38,7 @@ custom-protocol = ["tauri/custom-protocol"]
# Run the script:
# scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "52b82e68" }
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "7a309c6f69d8b34709292052e9ef0561e16c82a1" }
# Please use the following script to update collab.
# Working directory: frontend
#

View File

@ -660,7 +660,7 @@ dependencies = [
[[package]]
name = "client-api"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"anyhow",
"bytes",
@ -673,6 +673,7 @@ dependencies = [
"gotrue-entity",
"lib0",
"mime",
"mime_guess",
"parking_lot",
"realtime-entity",
"reqwest",
@ -1264,15 +1265,17 @@ checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308"
[[package]]
name = "database-entity"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"anyhow",
"chrono",
"collab-entity",
"serde",
"serde_json",
"serde_repr",
"sqlx",
"thiserror",
"tracing",
"uuid",
"validator",
]
@ -2437,7 +2440,7 @@ dependencies = [
[[package]]
name = "gotrue"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"anyhow",
"futures-util",
@ -2453,9 +2456,11 @@ dependencies = [
[[package]]
name = "gotrue-entity"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"anyhow",
"jsonwebtoken",
"lazy_static",
"reqwest",
"serde",
"serde_json",
@ -2811,7 +2816,7 @@ dependencies = [
[[package]]
name = "infra"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"anyhow",
"reqwest",
@ -2885,6 +2890,20 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "jsonwebtoken"
version = "8.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378"
dependencies = [
"base64 0.21.3",
"pem",
"ring",
"serde",
"serde_json",
"simple_asn1",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -3309,6 +3328,27 @@ dependencies = [
"winapi",
]
[[package]]
name = "num-bigint"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.16"
@ -3517,6 +3557,15 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "pem"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8"
dependencies = [
"base64 0.13.1",
]
[[package]]
name = "percent-encoding"
version = "2.3.0"
@ -4202,7 +4251,7 @@ dependencies = [
[[package]]
name = "realtime-entity"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"bytes",
"collab",
@ -4823,7 +4872,7 @@ dependencies = [
[[package]]
name = "shared_entity"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=52b82e68#52b82e68f6e61e9e38606b9110d782870ee911e4"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=7a309c6f69d8b34709292052e9ef0561e16c82a1#7a309c6f69d8b34709292052e9ef0561e16c82a1"
dependencies = [
"anyhow",
"database-entity",
@ -4872,6 +4921,18 @@ version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf"
[[package]]
name = "simple_asn1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adc4e5204eb1910f40f9cfa375f6f05b68c3abac4b6fd879c8ff5e7ae8a0a085"
dependencies = [
"num-bigint",
"num-traits",
"thiserror",
"time",
]
[[package]]
name = "siphasher"
version = "0.3.11"

View File

@ -82,7 +82,7 @@ incremental = false
# Run the script:
# scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "52b82e68" }
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "7a309c6f69d8b34709292052e9ef0561e16c82a1" }
# Please use the following script to update collab.
# Working directory: frontend
#

View File

@ -87,9 +87,10 @@ impl FlowyCoreTest {
}
pub async fn get_document_update(&self, document_id: &str) -> Vec<u8> {
let workspace_id = self.user_manager.workspace_id().unwrap();
let cloud_service = self.document_manager.get_cloud_service().clone();
let remote_updates = cloud_service
.get_document_updates(document_id)
.get_document_updates(document_id, &workspace_id)
.await
.unwrap();
@ -212,7 +213,7 @@ impl FlowyCoreTest {
let mut map = HashMap::new();
map.insert(USER_SIGN_IN_URL.to_string(), sign_in_url);
map.insert(USER_DEVICE_ID.to_string(), uuid::Uuid::new_v4().to_string());
map.insert(USER_DEVICE_ID.to_string(), Uuid::new_v4().to_string());
let payload = OauthSignInPB {
map,
auth_type: AuthTypePB::AFCloud,
@ -261,7 +262,7 @@ impl FlowyCoreTest {
.event(FolderEvent::GetCurrentWorkspace)
.async_send()
.await
.parse::<flowy_folder2::entities::WorkspaceSettingPB>()
.parse::<WorkspaceSettingPB>()
}
pub async fn get_all_workspace_views(&self) -> Vec<ViewPB> {
@ -269,7 +270,7 @@ impl FlowyCoreTest {
.event(FolderEvent::ReadWorkspaceViews)
.async_send()
.await
.parse::<flowy_folder2::entities::RepeatedViewPB>()
.parse::<RepeatedViewPB>()
.items
}
@ -281,7 +282,7 @@ impl FlowyCoreTest {
})
.async_send()
.await
.parse::<flowy_folder2::entities::ViewPB>()
.parse::<ViewPB>()
}
pub async fn delete_view(&self, view_id: &str) {
@ -333,7 +334,7 @@ impl FlowyCoreTest {
.payload(payload)
.async_send()
.await
.parse::<flowy_folder2::entities::ViewPB>()
.parse::<ViewPB>()
}
pub async fn create_document(
@ -391,7 +392,7 @@ impl FlowyCoreTest {
.payload(payload)
.async_send()
.await
.parse::<flowy_folder2::entities::ViewPB>()
.parse::<ViewPB>()
}
pub async fn open_database(&self, view_id: &str) {
@ -434,7 +435,7 @@ impl FlowyCoreTest {
.payload(payload)
.async_send()
.await
.parse::<flowy_folder2::entities::ViewPB>()
.parse::<ViewPB>()
}
pub async fn create_calendar(
@ -459,7 +460,7 @@ impl FlowyCoreTest {
.payload(payload)
.async_send()
.await
.parse::<flowy_folder2::entities::ViewPB>()
.parse::<ViewPB>()
}
pub async fn get_database(&self, view_id: &str) -> DatabasePB {
@ -470,7 +471,7 @@ impl FlowyCoreTest {
})
.async_send()
.await
.parse::<flowy_database2::entities::DatabasePB>()
.parse::<DatabasePB>()
}
pub async fn get_all_database_fields(&self, view_id: &str) -> RepeatedFieldPB {
@ -836,7 +837,7 @@ impl FlowyCoreTest {
})
.async_send()
.await
.parse::<flowy_folder2::entities::ViewPB>()
.parse::<ViewPB>()
}
}

View File

@ -71,9 +71,10 @@ impl FlowySupabaseDatabaseTest {
}
pub async fn get_database_collab_update(&self, database_id: &str) -> Vec<u8> {
let workspace_id = self.user_manager.workspace_id().unwrap();
let cloud_service = self.database_manager.get_cloud_service().clone();
let remote_updates = cloud_service
.get_collab_update(database_id, CollabType::Database)
.get_collab_update(database_id, CollabType::Database, &workspace_id)
.await
.unwrap();

View File

@ -273,12 +273,13 @@ async fn migrate_anon_document_on_cloud_signup() {
let _ = test.supabase_party_sign_up().await;
let workspace_id = test.user_manager.workspace_id().unwrap();
// After sign up, the documents should be migrated to the cloud
// So, we can get the document data from the cloud
let data: DocumentData = test
.document_manager
.get_cloud_service()
.get_document_data(&view.id)
.get_document_data(&view.id, &workspace_id)
.await
.unwrap()
.unwrap();
@ -372,6 +373,7 @@ async fn migrate_anon_data_on_cloud_signup() {
let rows = editor.get_rows(&database_view.id).await.unwrap();
assert_eq!(rows.len(), 3);
let workspace_id = test.user_manager.workspace_id().unwrap();
if i == 0 {
let first_row = rows.first().unwrap().as_ref();
let icon_url = first_row.meta.icon_url.clone().unwrap();
@ -381,7 +383,7 @@ async fn migrate_anon_data_on_cloud_signup() {
let document_data: DocumentData = test
.document_manager
.get_cloud_service()
.get_document_data(&document_id)
.get_document_data(&document_id, &workspace_id)
.await
.unwrap()
.unwrap();
@ -407,7 +409,7 @@ async fn migrate_anon_data_on_cloud_signup() {
}
assert!(cloud_service
.get_collab_update(&database_id, CollabType::Database)
.get_collab_update(&database_id, CollabType::Database, &workspace_id)
.await
.is_ok());
}

View File

@ -38,6 +38,14 @@ impl DocumentUser for DocumentUserImpl {
.user_id()
}
fn workspace_id(&self) -> Result<String, FlowyError> {
self
.0
.upgrade()
.ok_or(FlowyError::internal().with_context("Unexpected error: UserSession is None"))?
.workspace_id()
}
fn token(&self) -> Result<Option<String>, FlowyError> {
self
.0

View File

@ -190,13 +190,15 @@ impl DatabaseCloudService for ServerProvider {
&self,
object_id: &str,
collab_type: CollabType,
workspace_id: &str,
) -> FutureResult<CollabObjectUpdate, Error> {
let workspace_id = workspace_id.to_string();
let server = self.get_server(&self.get_server_type());
let database_id = object_id.to_string();
FutureResult::new(async move {
server?
.database_service()
.get_collab_update(&database_id, collab_type)
.get_collab_update(&database_id, collab_type, &workspace_id)
.await
})
}
@ -205,12 +207,14 @@ impl DatabaseCloudService for ServerProvider {
&self,
object_ids: Vec<String>,
object_ty: CollabType,
workspace_id: &str,
) -> FutureResult<CollabObjectUpdateByOid, Error> {
let workspace_id = workspace_id.to_string();
let server = self.get_server(&self.get_server_type());
FutureResult::new(async move {
server?
.database_service()
.batch_get_collab_updates(object_ids, object_ty)
.batch_get_collab_updates(object_ids, object_ty, &workspace_id)
.await
})
}
@ -232,13 +236,18 @@ impl DatabaseCloudService for ServerProvider {
}
impl DocumentCloudService for ServerProvider {
fn get_document_updates(&self, document_id: &str) -> FutureResult<Vec<Vec<u8>>, Error> {
let server = self.get_server(&self.get_server_type());
fn get_document_updates(
&self,
document_id: &str,
workspace_id: &str,
) -> FutureResult<Vec<Vec<u8>>, Error> {
let workspace_id = workspace_id.to_string();
let document_id = document_id.to_string();
let server = self.get_server(&self.get_server_type());
FutureResult::new(async move {
server?
.document_service()
.get_document_updates(&document_id)
.get_document_updates(&document_id, &workspace_id)
.await
})
}
@ -247,24 +256,31 @@ impl DocumentCloudService for ServerProvider {
&self,
document_id: &str,
limit: usize,
workspace_id: &str,
) -> FutureResult<Vec<DocumentSnapshot>, Error> {
let workspace_id = workspace_id.to_string();
let server = self.get_server(&self.get_server_type());
let document_id = document_id.to_string();
FutureResult::new(async move {
server?
.document_service()
.get_document_snapshots(&document_id, limit)
.get_document_snapshots(&document_id, limit, &workspace_id)
.await
})
}
fn get_document_data(&self, document_id: &str) -> FutureResult<Option<DocumentData>, Error> {
fn get_document_data(
&self,
document_id: &str,
workspace_id: &str,
) -> FutureResult<Option<DocumentData>, Error> {
let workspace_id = workspace_id.to_string();
let server = self.get_server(&self.get_server_type());
let document_id = document_id.to_string();
FutureResult::new(async move {
server?
.document_service()
.get_document_data(&document_id)
.get_document_data(&document_id, &workspace_id)
.await
})
}

View File

@ -125,6 +125,7 @@ impl AppFlowyCore {
server_provider.clone(),
Arc::downgrade(&collab_builder),
);
collab_builder
.set_snapshot_persistence(Arc::new(SnapshotDBImpl(Arc::downgrade(&user_manager))));
@ -179,8 +180,8 @@ impl AppFlowyCore {
let cloned_user_session = Arc::downgrade(&user_manager);
runtime.block_on(async move {
if let Some(user_session) = cloned_user_session.upgrade() {
if let Err(err) = user_session
if let Some(user_manager) = cloned_user_session.upgrade() {
if let Err(err) = user_manager
.init(user_status_callback, collab_interact_impl)
.await
{

View File

@ -16,12 +16,14 @@ pub trait DatabaseCloudService: Send + Sync {
&self,
object_id: &str,
collab_type: CollabType,
workspace_id: &str,
) -> FutureResult<CollabObjectUpdate, Error>;
fn batch_get_collab_updates(
&self,
object_ids: Vec<String>,
object_ty: CollabType,
workspace_id: &str,
) -> FutureResult<CollabObjectUpdateByOid, Error>;
fn get_collab_snapshots(

View File

@ -76,11 +76,12 @@ impl DatabaseManager {
pub async fn initialize(
&self,
uid: i64,
_workspace_id: String,
workspace_id: String,
database_views_aggregate_id: String,
) -> FlowyResult<()> {
let collab_db = self.user.collab_db(uid)?;
let collab_builder = UserDatabaseCollabServiceImpl {
workspace_id: workspace_id.clone(),
collab_builder: self.collab_builder.clone(),
cloud_service: self.cloud_service.clone(),
};
@ -92,7 +93,11 @@ impl DatabaseManager {
trace!("workspace database not exist, try to fetch from remote");
match self
.cloud_service
.get_collab_update(&database_views_aggregate_id, CollabType::WorkspaceDatabase)
.get_collab_update(
&database_views_aggregate_id,
CollabType::WorkspaceDatabase,
&workspace_id,
)
.await
{
Ok(updates) => {
@ -370,6 +375,7 @@ fn subscribe_block_event(workspace_database: &WorkspaceDatabase) {
}
struct UserDatabaseCollabServiceImpl {
workspace_id: String,
collab_builder: Arc<AppFlowyCollabBuilder>,
cloud_service: Arc<dyn DatabaseCloudService>,
}
@ -380,6 +386,7 @@ impl DatabaseCollabService for UserDatabaseCollabServiceImpl {
object_id: &str,
object_ty: CollabType,
) -> CollabFuture<Result<CollabObjectUpdate, DatabaseError>> {
let workspace_id = self.workspace_id.clone();
let object_id = object_id.to_string();
let weak_cloud_service = Arc::downgrade(&self.cloud_service);
Box::pin(async move {
@ -390,7 +397,7 @@ impl DatabaseCollabService for UserDatabaseCollabServiceImpl {
},
Some(cloud_service) => {
let updates = cloud_service
.get_collab_update(&object_id, object_ty)
.get_collab_update(&object_id, object_ty, &workspace_id)
.await?;
Ok(updates)
},
@ -403,6 +410,7 @@ impl DatabaseCollabService for UserDatabaseCollabServiceImpl {
object_ids: Vec<String>,
object_ty: CollabType,
) -> CollabFuture<Result<CollabObjectUpdateByOid, DatabaseError>> {
let workspace_id = self.workspace_id.clone();
let weak_cloud_service = Arc::downgrade(&self.cloud_service);
Box::pin(async move {
match weak_cloud_service.upgrade() {
@ -412,7 +420,7 @@ impl DatabaseCollabService for UserDatabaseCollabServiceImpl {
},
Some(cloud_service) => {
let updates = cloud_service
.batch_get_collab_updates(object_ids, object_ty)
.batch_get_collab_updates(object_ids, object_ty, &workspace_id)
.await?;
Ok(updates)
},

View File

@ -7,15 +7,24 @@ use lib_infra::future::FutureResult;
/// Each kind of server should implement this trait. Check out the [AppFlowyServerProvider] of
/// [flowy-server] crate for more information.
pub trait DocumentCloudService: Send + Sync + 'static {
fn get_document_updates(&self, document_id: &str) -> FutureResult<Vec<Vec<u8>>, Error>;
fn get_document_updates(
&self,
document_id: &str,
workspace_id: &str,
) -> FutureResult<Vec<Vec<u8>>, Error>;
fn get_document_snapshots(
&self,
document_id: &str,
limit: usize,
workspace_id: &str,
) -> FutureResult<Vec<DocumentSnapshot>, Error>;
fn get_document_data(&self, document_id: &str) -> FutureResult<Option<DocumentData>, Error>;
fn get_document_data(
&self,
document_id: &str,
workspace_id: &str,
) -> FutureResult<Option<DocumentData>, Error>;
}
pub struct DocumentSnapshot {

View File

@ -22,6 +22,9 @@ use crate::reminder::DocumentReminderAction;
pub trait DocumentUser: Send + Sync {
fn user_id(&self) -> Result<i64, FlowyError>;
fn workspace_id(&self) -> Result<String, FlowyError>;
fn token(&self) -> Result<Option<String>, FlowyError>; // unused now.
fn collab_db(&self, uid: i64) -> Result<Weak<RocksCollabDB>, FlowyError>;
}
@ -101,7 +104,10 @@ impl DocumentManager {
let mut updates = vec![];
if !self.is_doc_exist(doc_id)? {
// Try to get the document from the cloud service
updates = self.cloud_service.get_document_updates(doc_id).await?;
updates = self
.cloud_service
.get_document_updates(&self.user.workspace_id()?, doc_id)
.await?;
}
let uid = self.user.user_id()?;
@ -120,7 +126,10 @@ impl DocumentManager {
pub async fn get_document_data(&self, doc_id: &str) -> FlowyResult<DocumentData> {
let mut updates = vec![];
if !self.is_doc_exist(doc_id)? {
updates = self.cloud_service.get_document_updates(doc_id).await?;
updates = self
.cloud_service
.get_document_updates(doc_id, &self.user.workspace_id()?)
.await?;
}
let uid = self.user.user_id()?;
let collab = self.collab_for_document(uid, doc_id, updates).await?;
@ -152,9 +161,10 @@ impl DocumentManager {
document_id: &str,
limit: usize,
) -> FlowyResult<Vec<DocumentSnapshotPB>> {
let workspace_id = self.user.workspace_id()?;
let snapshots = self
.cloud_service
.get_document_snapshots(document_id, limit)
.get_document_snapshots(document_id, limit, &workspace_id)
.await?
.into_iter()
.map(|snapshot| DocumentSnapshotPB {

View File

@ -9,6 +9,7 @@ use nanoid::nanoid;
use parking_lot::Once;
use tempfile::TempDir;
use tracing_subscriber::{fmt::Subscriber, util::SubscriberInitExt, EnvFilter};
use uuid::Uuid;
use collab_integrate::collab_builder::{AppFlowyCollabBuilder, DefaultCollabStorageProvider};
use collab_integrate::RocksCollabDB;
@ -61,6 +62,10 @@ impl DocumentUser for FakeUser {
Ok(1)
}
fn workspace_id(&self) -> Result<String, FlowyError> {
Ok(Uuid::new_v4().to_string())
}
fn token(&self) -> Result<Option<String>, FlowyError> {
Ok(None)
}
@ -120,7 +125,11 @@ pub fn gen_id() -> String {
pub struct LocalTestDocumentCloudServiceImpl();
impl DocumentCloudService for LocalTestDocumentCloudServiceImpl {
fn get_document_updates(&self, _document_id: &str) -> FutureResult<Vec<Vec<u8>>, Error> {
fn get_document_updates(
&self,
_document_id: &str,
_workspace_id: &str,
) -> FutureResult<Vec<Vec<u8>>, Error> {
FutureResult::new(async move { Ok(vec![]) })
}
@ -128,11 +137,16 @@ impl DocumentCloudService for LocalTestDocumentCloudServiceImpl {
&self,
_document_id: &str,
_limit: usize,
_workspace_id: &str,
) -> FutureResult<Vec<DocumentSnapshot>, Error> {
FutureResult::new(async move { Ok(vec![]) })
}
fn get_document_data(&self, _document_id: &str) -> FutureResult<Option<DocumentData>, Error> {
fn get_document_data(
&self,
_document_id: &str,
_workspace_id: &str,
) -> FutureResult<Option<DocumentData>, Error> {
FutureResult::new(async move { Ok(None) })
}
}

View File

@ -1,6 +1,6 @@
use anyhow::Error;
use client_api::entity::QueryCollabResult::{Failed, Success};
use client_api::entity::{BatchQueryCollabParams, QueryCollabParams};
use client_api::entity::{BatchQueryCollab, BatchQueryCollabParams, QueryCollabParams};
use client_api::error::ErrorCode::RecordNotFound;
use collab_entity::CollabType;
use tracing::error;
@ -22,11 +22,14 @@ where
&self,
object_id: &str,
collab_type: CollabType,
workspace_id: &str,
) -> FutureResult<CollabObjectUpdate, Error> {
let workspace_id = workspace_id.to_string();
let object_id = object_id.to_string();
let try_get_client = self.0.try_get_client();
FutureResult::new(async move {
let params = QueryCollabParams {
workspace_id,
object_id,
collab_type,
};
@ -47,20 +50,22 @@ where
&self,
object_ids: Vec<String>,
object_ty: CollabType,
workspace_id: &str,
) -> FutureResult<CollabObjectUpdateByOid, Error> {
let workspace_id = workspace_id.to_string();
let try_get_client = self.0.try_get_client();
FutureResult::new(async move {
let client = try_get_client?;
let params = BatchQueryCollabParams(
object_ids
.into_iter()
.map(|object_id| QueryCollabParams {
.map(|object_id| BatchQueryCollab {
object_id,
collab_type: object_ty.clone(),
})
.collect(),
);
let results = client.batch_get_collab(params).await?;
let results = client.batch_get_collab(&workspace_id, params).await?;
Ok(
results
.0

View File

@ -16,11 +16,17 @@ impl<T> DocumentCloudService for AFCloudDocumentCloudServiceImpl<T>
where
T: AFServer,
{
fn get_document_updates(&self, document_id: &str) -> FutureResult<Vec<Vec<u8>>, Error> {
fn get_document_updates(
&self,
document_id: &str,
workspace_id: &str,
) -> FutureResult<Vec<Vec<u8>>, Error> {
let workspace_id = workspace_id.to_string();
let try_get_client = self.0.try_get_client();
let document_id = document_id.to_string();
FutureResult::new(async move {
let params = QueryCollabParams {
workspace_id,
object_id: document_id.to_string(),
collab_type: CollabType::Document,
};
@ -36,15 +42,22 @@ where
&self,
_document_id: &str,
_limit: usize,
_workspace_id: &str,
) -> FutureResult<Vec<DocumentSnapshot>, Error> {
FutureResult::new(async move { Ok(vec![]) })
}
fn get_document_data(&self, document_id: &str) -> FutureResult<Option<DocumentData>, Error> {
fn get_document_data(
&self,
document_id: &str,
workspace_id: &str,
) -> FutureResult<Option<DocumentData>, Error> {
let try_get_client = self.0.try_get_client();
let document_id = document_id.to_string();
let workspace_id = workspace_id.to_string();
FutureResult::new(async move {
let params = QueryCollabParams {
workspace_id,
object_id: document_id.clone(),
collab_type: CollabType::Document,
};

View File

@ -33,10 +33,10 @@ where
.to_string();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).await?;
Ok(client.put_file(&object.workspace_id, buffer, mime).await?)
Ok(client.put_blob(&object.workspace_id, buffer, mime).await?)
},
ObjectValue::Bytes { bytes, mime } => {
Ok(client.put_file(&object.workspace_id, bytes, mime).await?)
Ok(client.put_blob(&object.workspace_id, bytes, mime).await?)
},
}
})
@ -46,7 +46,7 @@ where
let try_get_client = self.0.try_get_client();
FutureResult::new(async move {
let client = try_get_client?;
client.delete_file(&object_url).await?;
client.delete_blob(&object_url).await?;
Ok(())
})
}
@ -55,7 +55,7 @@ where
let try_get_client = self.0.try_get_client();
FutureResult::new(async move {
let client = try_get_client?;
let bytes = client.get_file(&object_url).await?;
let bytes = client.get_blob(&object_url).await?;
Ok(bytes)
})
}

View File

@ -25,6 +25,7 @@ where
FutureResult::new(async move {
let params = QueryCollabParams {
object_id: workspace_id.clone(),
workspace_id: workspace_id.clone(),
collab_type: CollabType::Folder,
};
let updates = vec![try_get_client?
@ -50,7 +51,8 @@ where
let try_get_client = self.0.try_get_client();
FutureResult::new(async move {
let params = QueryCollabParams {
object_id: workspace_id,
object_id: workspace_id.clone(),
workspace_id,
collab_type: CollabType::Folder,
};
let update = try_get_client?

View File

@ -2,9 +2,10 @@ use std::collections::HashMap;
use std::sync::Arc;
use anyhow::{anyhow, Error};
use client_api::entity::dto::UserUpdateParams;
use client_api::entity::dto::auth_dto::UpdateUsernameParams;
use client_api::entity::dto::workspace_dto::CreateWorkspaceMember;
use client_api::entity::{
AFUserProfileView, AFWorkspace, AFWorkspaces, InsertCollabParams, OAuthProvider,
AFRole, AFUserProfileView, AFWorkspace, AFWorkspaces, InsertCollabParams, OAuthProvider,
};
use collab_entity::CollabObject;
@ -91,10 +92,11 @@ where
FutureResult::new(async move {
let client = try_get_client?;
client
.update(UserUpdateParams {
.update_user(UpdateUsernameParams {
name: params.name,
email: params.email,
password: params.password,
metadata: None,
})
.await?;
Ok(())
@ -108,7 +110,7 @@ where
let try_get_client = self.server.try_get_client();
FutureResult::new(async move {
let client = try_get_client?;
let profile = client.profile().await?;
let profile = client.get_profile().await?;
let encryption_type = encryption_type_from_profile(&profile);
Ok(Some(UserProfile {
email: profile.email.unwrap_or("".to_string()),
@ -131,7 +133,7 @@ where
fn get_user_workspaces(&self, _uid: i64) -> FutureResult<Vec<UserWorkspace>, Error> {
let try_get_client = self.server.try_get_client();
FutureResult::new(async move {
let workspaces = try_get_client?.workspaces().await?;
let workspaces = try_get_client?.get_workspaces().await?;
Ok(to_user_workspaces(workspaces)?)
})
}
@ -145,7 +147,7 @@ where
// from cloud
let client = try_get_client?;
let profile = client.profile().await?;
let profile = client.get_profile().await?;
let client_token = client.access_token()?;
// compare and check
@ -167,7 +169,13 @@ where
let try_get_client = self.server.try_get_client();
FutureResult::new(async move {
try_get_client?
.add_workspace_members(workspace_id.parse()?, vec![user_email])
.add_workspace_members(
workspace_id,
vec![CreateWorkspaceMember {
email: user_email,
role: AFRole::Member,
}],
)
.await?;
Ok(())
})
@ -181,7 +189,7 @@ where
let try_get_client = self.server.try_get_client();
FutureResult::new(async move {
try_get_client?
.remove_workspace_members(workspace_id.parse()?, vec![user_email])
.remove_workspace_members(workspace_id, vec![user_email])
.await?;
Ok(())
})
@ -230,7 +238,7 @@ pub async fn user_sign_in_with_url(
params: AFCloudOAuthParams,
) -> Result<AuthResponse, FlowyError> {
let is_new_user = client.sign_in_with_url(&params.sign_in_url).await?;
let (profile, af_workspaces) = tokio::try_join!(client.profile(), client.workspaces())?;
let (profile, af_workspaces) = tokio::try_join!(client.get_profile(), client.get_workspaces())?;
let latest_workspace = to_user_workspace(
af_workspaces

View File

@ -13,6 +13,7 @@ impl DatabaseCloudService for LocalServerDatabaseCloudServiceImpl {
&self,
_object_id: &str,
_collab_type: CollabType,
_workspace_id: &str,
) -> FutureResult<CollabObjectUpdate, Error> {
FutureResult::new(async move { Ok(vec![]) })
}
@ -21,6 +22,7 @@ impl DatabaseCloudService for LocalServerDatabaseCloudServiceImpl {
&self,
_object_ids: Vec<String>,
_object_ty: CollabType,
_workspace_id: &str,
) -> FutureResult<CollabObjectUpdateByOid, Error> {
FutureResult::new(async move { Ok(CollabObjectUpdateByOid::default()) })
}

View File

@ -6,7 +6,11 @@ use lib_infra::future::FutureResult;
pub(crate) struct LocalServerDocumentCloudServiceImpl();
impl DocumentCloudService for LocalServerDocumentCloudServiceImpl {
fn get_document_updates(&self, _document_id: &str) -> FutureResult<Vec<Vec<u8>>, Error> {
fn get_document_updates(
&self,
_document_id: &str,
_workspace_id: &str,
) -> FutureResult<Vec<Vec<u8>>, Error> {
FutureResult::new(async move { Ok(vec![]) })
}
@ -14,11 +18,16 @@ impl DocumentCloudService for LocalServerDocumentCloudServiceImpl {
&self,
_document_id: &str,
_limit: usize,
_workspace_id: &str,
) -> FutureResult<Vec<DocumentSnapshot>, Error> {
FutureResult::new(async move { Ok(vec![]) })
}
fn get_document_data(&self, _document_id: &str) -> FutureResult<Option<DocumentData>, Error> {
fn get_document_data(
&self,
_document_id: &str,
_workspace_id: &str,
) -> FutureResult<Option<DocumentData>, Error> {
FutureResult::new(async move { Ok(None) })
}
}

View File

@ -30,6 +30,7 @@ where
&self,
object_id: &str,
collab_type: CollabType,
_workspace_id: &str,
) -> FutureResult<CollabObjectUpdate, Error> {
let try_get_postgrest = self.server.try_get_weak_postgrest();
let object_id = object_id.to_string();
@ -53,6 +54,7 @@ where
&self,
object_ids: Vec<String>,
object_ty: CollabType,
_workspace_id: &str,
) -> FutureResult<CollabObjectUpdateByOid, Error> {
let try_get_postgrest = self.server.try_get_weak_postgrest();
let (tx, rx) = channel();

View File

@ -27,7 +27,11 @@ where
T: SupabaseServerService,
{
#[tracing::instrument(level = "debug", skip(self))]
fn get_document_updates(&self, document_id: &str) -> FutureResult<Vec<Vec<u8>>, Error> {
fn get_document_updates(
&self,
document_id: &str,
workspace_id: &str,
) -> FutureResult<Vec<Vec<u8>>, Error> {
let try_get_postgrest = self.server.try_get_weak_postgrest();
let document_id = document_id.to_string();
let (tx, rx) = channel();
@ -52,6 +56,7 @@ where
&self,
document_id: &str,
limit: usize,
_workspace_id: &str,
) -> FutureResult<Vec<DocumentSnapshot>, Error> {
let try_get_postgrest = self.server.try_get_postgrest();
let document_id = document_id.to_string();
@ -72,7 +77,11 @@ where
}
#[tracing::instrument(level = "debug", skip(self))]
fn get_document_data(&self, document_id: &str) -> FutureResult<Option<DocumentData>, Error> {
fn get_document_data(
&self,
document_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();
let (tx, rx) = channel();

View File

@ -45,7 +45,7 @@ async fn supabase_create_database_test() {
}
let updates_by_oid = database_service
.batch_get_collab_updates(row_ids, CollabType::DatabaseRow)
.batch_get_collab_updates(row_ids, CollabType::DatabaseRow, "fake_workspace_id")
.await
.unwrap();

View File

@ -5,7 +5,7 @@ use collab_user::core::MutexUserAwareness;
use serde_json::Value;
use tokio::sync::{Mutex, RwLock};
use tokio_stream::StreamExt;
use tracing::{debug, error, info, instrument};
use tracing::{debug, error, event, info, instrument};
use collab_integrate::collab_builder::AppFlowyCollabBuilder;
use collab_integrate::RocksCollabDB;
@ -347,16 +347,18 @@ impl UserManager {
UserAwarenessDataSource::Remote
};
debug!("Sign up response: {:?}", response);
event!(tracing::Level::DEBUG, "Sign up response: {:?}", response);
if response.is_new_user {
if let Some(old_user) = migration_user {
let new_user = MigrationUser {
user_profile: user_profile.clone(),
session: new_session.clone(),
};
info!(
event!(
tracing::Level::INFO,
"Migrate old user data from {:?} to {:?}",
old_user.user_profile.uid, new_user.user_profile.uid
old_user.user_profile.uid,
new_user.user_profile.uid
);
self
.migrate_local_user_to_cloud(&old_user, &new_user)
@ -488,6 +490,10 @@ impl UserManager {
Ok(self.get_session()?.user_id)
}
pub fn workspace_id(&self) -> Result<String, FlowyError> {
Ok(self.get_session()?.user_workspace.id)
}
pub fn token(&self) -> Result<Option<String>, FlowyError> {
Ok(None)
}