AppFlowy/frontend/rust-lib/flowy-server/src/server.rs

136 lines
4.4 KiB
Rust
Raw Normal View History

2023-08-31 08:40:40 +00:00
use std::sync::Arc;
use anyhow::Error;
feat: integrate client-api (#3430) * chore: update client-api rev * chore: update collab rev id * feat: add sign_in_request and import shared entity * feat: added to userworkspace from af_workspace * chore: add script to update the client-api rev id * chore: update client-api rev * feat: add workspaces api * feat: added check user * chore: config * chore: update client_api version * chore: ws connect * chore: ws connect * chore: update crate versions * chore: rename event * chore: update client-appi * chore: set appflowy cloud env * chore: add env template * chore: update env name * docs: update docs * fix: check_user * feat: impl sign_in_with_url * feat: add file storage placeholders * chore: update client-api * chore: disable test * feat: impl workspace add and remove * chore: sign up test * feat: select cover image on upload (#3488) * fix: close popover after item selection in settings view (#3362) * fix: close popover after item selection in settings view * fix: add missing await before closing popover * fix: find popover container by context instead of passing controllers around * fix: add requested changes * feat: close text direction settings popups after selection * fix: clean up * fix: restore theme value dropdown as StatefulWidget * feat: openai and stabilityai integration (#3439) * chore: create trait * test: add tests * chore: remove log * chore: disable log * chore: checklist ux flow redesign (#3418) * chore: ux flow redesign * chore: remove unused imports * fix: allow creation of tasks of the same name * chore: apply code suggestions from Mathias * fix: add padding below field title text field (#3440) * Fixed Issue no #3426 * Reversed the pubspec.lock mistaken update * FIXED PADDING * Fixed Padding issue on calender field edit popup * chore: rename package name (#3501) * fix: right icon size sam as left one (#3494) * feat: enable removing user icon (#3487) * feat: enable removing user icon * fix: generate to true * fix: review comments * fix: more review comments * fix: integration test and final changes * fix: made cursor grab and background color when hovering on Appearance Options Buttons (#3498) * chore: calendar UI polish (#3484) * chore: update calendar theming * feat: add event popup editor * chore: new event button redesign and add card shadows * chore: unscheduled events button * chore: event title text field * fix: focus node double dispose * chore: show popover when create new event * test: integrate some tests for integration testing purposes * fix: some fixes and more integration tests * chore: add more space between font item and font menu * feat: add reset font button in toolbar * feat: only show text direction toolbar item when RTL is enabled * fix: unable to change RTL of heading block * test: add integration test for ltr/rtl mode * chore: update inlang project settings (#3441) * feat: using script to update the collab source. (#3508) * chore: add script * chore: update script * chore: update bytes version * chore: submit lock file * chore: update test * chore: update test * chore: bump version * chore: update * ci: fix * ci: fix * chore: update commit id * chore: update commit id * chore: update commit id * fix: is cloud enable --------- Co-authored-by: Fu Zi Xiang <speed2exe@live.com.sg> Co-authored-by: Mathias Mogensen <42929161+Xazin@users.noreply.github.com> Co-authored-by: Vincenzo De Petris <37916223+vincendep@users.noreply.github.com> Co-authored-by: Richard Shiue <71320345+richardshiue@users.noreply.github.com> Co-authored-by: Aryan More <61151896+aryan-more@users.noreply.github.com> Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io> Co-authored-by: Lakhan Baheti <94619783+1akhanBaheti@users.noreply.github.com> Co-authored-by: Nitin-Poojary <70025277+Nitin-Poojary@users.noreply.github.com> Co-authored-by: Jannes Blobel <72493222+jannesblobel@users.noreply.github.com>
2023-10-02 09:22:22 +00:00
use client_api::ws::{WSConnectStateReceiver, WebSocketChannel};
use collab_entity::CollabObject;
use collab_plugins::cloud_storage::RemoteCollabStorage;
2023-08-31 08:40:40 +00:00
use parking_lot::RwLock;
use tokio_stream::wrappers::WatchStream;
2023-08-31 08:40:40 +00:00
use flowy_database_deps::cloud::DatabaseCloudService;
use flowy_document_deps::cloud::DocumentCloudService;
use flowy_folder_deps::cloud::FolderCloudService;
use flowy_storage::FileStorageService;
2023-08-31 08:40:40 +00:00
use flowy_user_deps::cloud::UserCloudService;
use flowy_user_deps::entities::UserTokenState;
use lib_infra::future::FutureResult;
2023-08-31 08:40:40 +00:00
pub trait AppFlowyEncryption: Send + Sync + 'static {
fn get_secret(&self) -> Option<String>;
fn set_secret(&self, secret: String);
}
impl<T> AppFlowyEncryption for Arc<T>
where
T: AppFlowyEncryption,
{
fn get_secret(&self) -> Option<String> {
(**self).get_secret()
}
fn set_secret(&self, secret: String) {
(**self).set_secret(secret)
}
}
/// `AppFlowyServer` trait defines a collection of services that offer cloud-based interactions
/// and functionalities in AppFlowy. The methods provided ensure efficient, asynchronous operations
/// for managing and accessing user data, folders, collaborative objects, and documents in a cloud environment.
pub trait AppFlowyServer: Send + Sync + 'static {
fn set_token(&self, _token: &str) -> Result<(), Error> {
Ok(())
}
fn subscribe_token_state(&self) -> Option<WatchStream<UserTokenState>> {
None
}
2023-08-31 08:40:40 +00:00
/// Enables or disables server sync.
///
/// # Arguments
///
/// * `_enable` - A boolean to toggle the server synchronization.
fn set_enable_sync(&self, _uid: i64, _enable: bool) {}
2023-08-31 08:40:40 +00:00
/// Provides access to cloud-based user management functionalities. This includes operations
/// such as user registration, authentication, profile management, and handling of user workspaces.
/// The interface also offers methods for managing collaborative objects, subscribing to user updates,
/// and receiving real-time events.
///
/// # Returns
///
/// An `Arc` wrapping the `UserCloudService` interface.
fn user_service(&self) -> Arc<dyn UserCloudService>;
/// Provides a service for managing workspaces and folders in a cloud environment. This includes
/// functionalities to create workspaces, and fetch data, snapshots, and updates related to specific folders.
///
/// # Returns
///
/// An `Arc` wrapping the `FolderCloudService` interface.
fn folder_service(&self) -> Arc<dyn FolderCloudService>;
/// Offers a set of operations for interacting with collaborative objects within a cloud database.
/// This includes functionalities such as retrieval of updates for specific objects, batch fetching,
/// and obtaining snapshots.
///
/// # Returns
///
/// An `Arc` wrapping the `DatabaseCloudService` interface.
fn database_service(&self) -> Arc<dyn DatabaseCloudService>;
/// Facilitates cloud-based document management. This service offers operations for updating documents,
/// fetching snapshots, and accessing primary document data in an asynchronous manner.
///
/// # Returns
///
/// An `Arc` wrapping the `DocumentCloudService` interface.
fn document_service(&self) -> Arc<dyn DocumentCloudService>;
/// Manages collaborative objects within a remote storage system. This includes operations such as
/// checking storage status, retrieving updates and snapshots, and dispatching updates. The service
/// also provides subscription capabilities for real-time updates.
///
/// # Arguments
///
/// * `collab_object` - A reference to the collaborative object.
///
/// # Returns
///
/// An `Option` that might contain an `Arc` wrapping the `RemoteCollabStorage` interface.
fn collab_storage(&self, _collab_object: &CollabObject) -> Option<Arc<dyn RemoteCollabStorage>> {
None
}
fn collab_ws_channel(
&self,
_object_id: &str,
) -> FutureResult<Option<(Arc<WebSocketChannel>, WSConnectStateReceiver, bool)>, anyhow::Error>
{
FutureResult::new(async { Ok(None) })
}
2023-08-31 08:40:40 +00:00
fn file_storage(&self) -> Option<Arc<dyn FileStorageService>>;
2023-08-31 08:40:40 +00:00
}
pub struct EncryptionImpl {
secret: RwLock<Option<String>>,
}
impl EncryptionImpl {
pub fn new(secret: Option<String>) -> Self {
Self {
secret: RwLock::new(secret),
}
}
}
impl AppFlowyEncryption for EncryptionImpl {
fn get_secret(&self) -> Option<String> {
self.secret.read().clone()
}
fn set_secret(&self, secret: String) {
*self.secret.write() = Some(secret);
}
}