2023-07-29 09:46:24 +08:00
|
|
|
pub use anyhow::Error;
|
2023-12-29 13:02:27 +08:00
|
|
|
use collab_entity::CollabType;
|
2023-11-01 11:45:35 +08:00
|
|
|
pub use collab_folder::{Folder, FolderData, Workspace};
|
2023-08-17 23:46:39 +08:00
|
|
|
use uuid::Uuid;
|
2023-07-29 09:46:24 +08:00
|
|
|
|
|
|
|
use lib_infra::future::FutureResult;
|
|
|
|
|
|
|
|
/// [FolderCloudService] represents the cloud service for folder.
|
|
|
|
pub trait FolderCloudService: Send + Sync + 'static {
|
2023-11-05 14:00:24 +08:00
|
|
|
/// Creates a new workspace for the user.
|
|
|
|
/// Returns error if the cloud service doesn't support multiple workspaces
|
2023-07-29 09:46:24 +08:00
|
|
|
fn create_workspace(&self, uid: i64, name: &str) -> FutureResult<Workspace, Error>;
|
|
|
|
|
2023-11-05 14:00:24 +08:00
|
|
|
fn open_workspace(&self, workspace_id: &str) -> FutureResult<(), Error>;
|
|
|
|
|
|
|
|
/// Returns all workspaces of the user.
|
|
|
|
/// Returns vec![] if the cloud service doesn't support multiple workspaces
|
|
|
|
fn get_all_workspace(&self) -> FutureResult<Vec<WorkspaceRecord>, Error>;
|
|
|
|
|
2023-11-01 11:45:35 +08:00
|
|
|
fn get_folder_data(
|
|
|
|
&self,
|
|
|
|
workspace_id: &str,
|
|
|
|
uid: &i64,
|
|
|
|
) -> FutureResult<Option<FolderData>, Error>;
|
2023-07-29 09:46:24 +08:00
|
|
|
|
2023-08-17 23:46:39 +08:00
|
|
|
fn get_folder_snapshots(
|
2023-07-29 09:46:24 +08:00
|
|
|
&self,
|
|
|
|
workspace_id: &str,
|
2023-08-17 23:46:39 +08:00
|
|
|
limit: usize,
|
|
|
|
) -> FutureResult<Vec<FolderSnapshot>, Error>;
|
2023-07-29 09:46:24 +08:00
|
|
|
|
2024-02-04 05:49:45 +08:00
|
|
|
fn get_folder_doc_state(
|
2023-12-29 13:02:27 +08:00
|
|
|
&self,
|
|
|
|
workspace_id: &str,
|
|
|
|
uid: i64,
|
|
|
|
collab_type: CollabType,
|
|
|
|
object_id: &str,
|
2024-03-23 09:18:47 +08:00
|
|
|
) -> FutureResult<Vec<u8>, Error>;
|
2023-12-29 13:02:27 +08:00
|
|
|
|
2024-02-04 05:49:45 +08:00
|
|
|
fn batch_create_folder_collab_objects(
|
2023-12-29 13:02:27 +08:00
|
|
|
&self,
|
|
|
|
workspace_id: &str,
|
|
|
|
objects: Vec<FolderCollabParams>,
|
|
|
|
) -> FutureResult<(), Error>;
|
2023-07-29 09:46:24 +08:00
|
|
|
|
|
|
|
fn service_name(&self) -> String;
|
|
|
|
}
|
|
|
|
|
2023-12-29 13:02:27 +08:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct FolderCollabParams {
|
|
|
|
pub object_id: String,
|
|
|
|
pub encoded_collab_v1: Vec<u8>,
|
|
|
|
pub collab_type: CollabType,
|
|
|
|
}
|
|
|
|
|
2023-07-29 09:46:24 +08:00
|
|
|
pub struct FolderSnapshot {
|
|
|
|
pub snapshot_id: i64,
|
|
|
|
pub database_id: String,
|
|
|
|
pub data: Vec<u8>,
|
|
|
|
pub created_at: i64,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn gen_workspace_id() -> Uuid {
|
|
|
|
uuid::Uuid::new_v4()
|
|
|
|
}
|
2023-08-28 13:28:24 +08:00
|
|
|
|
|
|
|
pub fn gen_view_id() -> Uuid {
|
|
|
|
uuid::Uuid::new_v4()
|
|
|
|
}
|
2023-11-05 14:00:24 +08:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct WorkspaceRecord {
|
|
|
|
pub id: String,
|
|
|
|
pub name: String,
|
|
|
|
pub created_at: i64,
|
|
|
|
}
|