mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: skip create sync plugin when the authenticator for given user … (#4252)
* chore: skip create sync plugin when the authenticator for given user is local * chore: bump collab
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use std::fmt::Debug;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::sync::{Arc, Weak};
|
||||
|
||||
use anyhow::Error;
|
||||
@ -16,13 +16,13 @@ use tracing::trace;
|
||||
use lib_infra::future::Fut;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum CollabDataSource {
|
||||
pub enum CollabPluginProviderType {
|
||||
Local,
|
||||
AppFlowyCloud,
|
||||
Supabase,
|
||||
}
|
||||
|
||||
pub enum CollabStorageProviderContext {
|
||||
pub enum CollabPluginProviderContext {
|
||||
Local,
|
||||
AppFlowyCloud {
|
||||
uid: i64,
|
||||
@ -37,23 +37,43 @@ pub enum CollabStorageProviderContext {
|
||||
},
|
||||
}
|
||||
|
||||
pub trait CollabStorageProvider: Send + Sync + 'static {
|
||||
fn storage_source(&self) -> CollabDataSource;
|
||||
impl Display for CollabPluginProviderContext {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let str = match self {
|
||||
CollabPluginProviderContext::Local => "Local".to_string(),
|
||||
CollabPluginProviderContext::AppFlowyCloud {
|
||||
uid: _,
|
||||
collab_object,
|
||||
local_collab: _,
|
||||
} => collab_object.to_string(),
|
||||
CollabPluginProviderContext::Supabase {
|
||||
uid: _,
|
||||
collab_object,
|
||||
local_collab: _,
|
||||
local_collab_db: _,
|
||||
} => collab_object.to_string(),
|
||||
};
|
||||
write!(f, "{}", str)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_plugins(&self, context: CollabStorageProviderContext) -> Fut<Vec<Arc<dyn CollabPlugin>>>;
|
||||
pub trait CollabCloudPluginProvider: Send + Sync + 'static {
|
||||
fn provider_type(&self) -> CollabPluginProviderType;
|
||||
|
||||
fn get_plugins(&self, context: CollabPluginProviderContext) -> Fut<Vec<Arc<dyn CollabPlugin>>>;
|
||||
|
||||
fn is_sync_enabled(&self) -> bool;
|
||||
}
|
||||
|
||||
impl<T> CollabStorageProvider for Arc<T>
|
||||
impl<T> CollabCloudPluginProvider for Arc<T>
|
||||
where
|
||||
T: CollabStorageProvider,
|
||||
T: CollabCloudPluginProvider,
|
||||
{
|
||||
fn storage_source(&self) -> CollabDataSource {
|
||||
(**self).storage_source()
|
||||
fn provider_type(&self) -> CollabPluginProviderType {
|
||||
(**self).provider_type()
|
||||
}
|
||||
|
||||
fn get_plugins(&self, context: CollabStorageProviderContext) -> Fut<Vec<Arc<dyn CollabPlugin>>> {
|
||||
fn get_plugins(&self, context: CollabPluginProviderContext) -> Fut<Vec<Arc<dyn CollabPlugin>>> {
|
||||
(**self).get_plugins(context)
|
||||
}
|
||||
|
||||
@ -65,7 +85,7 @@ where
|
||||
pub struct AppFlowyCollabBuilder {
|
||||
network_reachability: CollabNetworkReachability,
|
||||
workspace_id: RwLock<Option<String>>,
|
||||
cloud_storage: tokio::sync::RwLock<Arc<dyn CollabStorageProvider>>,
|
||||
plugin_provider: tokio::sync::RwLock<Arc<dyn CollabCloudPluginProvider>>,
|
||||
snapshot_persistence: Mutex<Option<Arc<dyn SnapshotPersistence>>>,
|
||||
rocksdb_backup: Mutex<Option<Arc<dyn RocksdbBackup>>>,
|
||||
device_id: String,
|
||||
@ -89,11 +109,11 @@ impl CollabBuilderConfig {
|
||||
}
|
||||
|
||||
impl AppFlowyCollabBuilder {
|
||||
pub fn new<T: CollabStorageProvider>(storage_provider: T, device_id: String) -> Self {
|
||||
pub fn new<T: CollabCloudPluginProvider>(storage_provider: T, device_id: String) -> Self {
|
||||
Self {
|
||||
network_reachability: CollabNetworkReachability::new(),
|
||||
workspace_id: Default::default(),
|
||||
cloud_storage: tokio::sync::RwLock::new(Arc::new(storage_provider)),
|
||||
plugin_provider: tokio::sync::RwLock::new(Arc::new(storage_provider)),
|
||||
snapshot_persistence: Default::default(),
|
||||
rocksdb_backup: Default::default(),
|
||||
device_id,
|
||||
@ -219,20 +239,20 @@ impl AppFlowyCollabBuilder {
|
||||
{
|
||||
let collab_object = self.collab_object(uid, object_id, object_type)?;
|
||||
if build_config.sync_enable {
|
||||
let cloud_storage_type = self.cloud_storage.read().await.storage_source();
|
||||
let provider_type = self.plugin_provider.read().await.provider_type();
|
||||
let span = tracing::span!(tracing::Level::TRACE, "collab_builder", object_id = %object_id);
|
||||
let _enter = span.enter();
|
||||
match cloud_storage_type {
|
||||
CollabDataSource::AppFlowyCloud => {
|
||||
match provider_type {
|
||||
CollabPluginProviderType::AppFlowyCloud => {
|
||||
#[cfg(feature = "appflowy_cloud_integrate")]
|
||||
{
|
||||
trace!("init appflowy cloud collab plugins");
|
||||
let local_collab = Arc::downgrade(&collab);
|
||||
let plugins = self
|
||||
.cloud_storage
|
||||
.plugin_provider
|
||||
.read()
|
||||
.await
|
||||
.get_plugins(CollabStorageProviderContext::AppFlowyCloud {
|
||||
.get_plugins(CollabPluginProviderContext::AppFlowyCloud {
|
||||
uid,
|
||||
collab_object: collab_object.clone(),
|
||||
local_collab,
|
||||
@ -245,17 +265,17 @@ impl AppFlowyCollabBuilder {
|
||||
}
|
||||
}
|
||||
},
|
||||
CollabDataSource::Supabase => {
|
||||
CollabPluginProviderType::Supabase => {
|
||||
#[cfg(feature = "supabase_integrate")]
|
||||
{
|
||||
trace!("init supabase collab plugins");
|
||||
let local_collab = Arc::downgrade(&collab);
|
||||
let local_collab_db = collab_db.clone();
|
||||
let plugins = self
|
||||
.cloud_storage
|
||||
.plugin_provider
|
||||
.read()
|
||||
.await
|
||||
.get_plugins(CollabStorageProviderContext::Supabase {
|
||||
.get_plugins(CollabPluginProviderContext::Supabase {
|
||||
uid,
|
||||
collab_object: collab_object.clone(),
|
||||
local_collab,
|
||||
@ -267,7 +287,7 @@ impl AppFlowyCollabBuilder {
|
||||
}
|
||||
}
|
||||
},
|
||||
CollabDataSource::Local => {},
|
||||
CollabPluginProviderType::Local => {},
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user