server.rs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. use std::sync::Arc;
  2. use collab_plugins::cloud_storage::{CollabObject, RemoteCollabStorage};
  3. use parking_lot::RwLock;
  4. use flowy_database_deps::cloud::DatabaseCloudService;
  5. use flowy_document_deps::cloud::DocumentCloudService;
  6. use flowy_folder_deps::cloud::FolderCloudService;
  7. use flowy_storage::core::FileStorageService;
  8. use flowy_user_deps::cloud::UserCloudService;
  9. pub trait AppFlowyEncryption: Send + Sync + 'static {
  10. fn get_secret(&self) -> Option<String>;
  11. fn set_secret(&self, secret: String);
  12. }
  13. impl<T> AppFlowyEncryption for Arc<T>
  14. where
  15. T: AppFlowyEncryption,
  16. {
  17. fn get_secret(&self) -> Option<String> {
  18. (**self).get_secret()
  19. }
  20. fn set_secret(&self, secret: String) {
  21. (**self).set_secret(secret)
  22. }
  23. }
  24. /// `AppFlowyServer` trait defines a collection of services that offer cloud-based interactions
  25. /// and functionalities in AppFlowy. The methods provided ensure efficient, asynchronous operations
  26. /// for managing and accessing user data, folders, collaborative objects, and documents in a cloud environment.
  27. pub trait AppFlowyServer: Send + Sync + 'static {
  28. /// Enables or disables server sync.
  29. ///
  30. /// # Arguments
  31. ///
  32. /// * `_enable` - A boolean to toggle the server synchronization.
  33. fn set_enable_sync(&self, _enable: bool) {}
  34. /// Provides access to cloud-based user management functionalities. This includes operations
  35. /// such as user registration, authentication, profile management, and handling of user workspaces.
  36. /// The interface also offers methods for managing collaborative objects, subscribing to user updates,
  37. /// and receiving real-time events.
  38. ///
  39. /// # Returns
  40. ///
  41. /// An `Arc` wrapping the `UserCloudService` interface.
  42. fn user_service(&self) -> Arc<dyn UserCloudService>;
  43. /// Provides a service for managing workspaces and folders in a cloud environment. This includes
  44. /// functionalities to create workspaces, and fetch data, snapshots, and updates related to specific folders.
  45. ///
  46. /// # Returns
  47. ///
  48. /// An `Arc` wrapping the `FolderCloudService` interface.
  49. fn folder_service(&self) -> Arc<dyn FolderCloudService>;
  50. /// Offers a set of operations for interacting with collaborative objects within a cloud database.
  51. /// This includes functionalities such as retrieval of updates for specific objects, batch fetching,
  52. /// and obtaining snapshots.
  53. ///
  54. /// # Returns
  55. ///
  56. /// An `Arc` wrapping the `DatabaseCloudService` interface.
  57. fn database_service(&self) -> Arc<dyn DatabaseCloudService>;
  58. /// Facilitates cloud-based document management. This service offers operations for updating documents,
  59. /// fetching snapshots, and accessing primary document data in an asynchronous manner.
  60. ///
  61. /// # Returns
  62. ///
  63. /// An `Arc` wrapping the `DocumentCloudService` interface.
  64. fn document_service(&self) -> Arc<dyn DocumentCloudService>;
  65. /// Manages collaborative objects within a remote storage system. This includes operations such as
  66. /// checking storage status, retrieving updates and snapshots, and dispatching updates. The service
  67. /// also provides subscription capabilities for real-time updates.
  68. ///
  69. /// # Arguments
  70. ///
  71. /// * `collab_object` - A reference to the collaborative object.
  72. ///
  73. /// # Returns
  74. ///
  75. /// An `Option` that might contain an `Arc` wrapping the `RemoteCollabStorage` interface.
  76. fn collab_storage(&self, collab_object: &CollabObject) -> Option<Arc<dyn RemoteCollabStorage>>;
  77. fn file_storage(&self) -> Option<Arc<dyn FileStorageService>> {
  78. None
  79. }
  80. }
  81. pub struct EncryptionImpl {
  82. secret: RwLock<Option<String>>,
  83. }
  84. impl EncryptionImpl {
  85. pub fn new(secret: Option<String>) -> Self {
  86. Self {
  87. secret: RwLock::new(secret),
  88. }
  89. }
  90. }
  91. impl AppFlowyEncryption for EncryptionImpl {
  92. fn get_secret(&self) -> Option<String> {
  93. self.secret.read().clone()
  94. }
  95. fn set_secret(&self, secret: String) {
  96. *self.secret.write() = Some(secret);
  97. }
  98. }