2024-10-31 14:38:32 +08:00
|
|
|
use crate::entities::PublishPayload;
|
2023-07-29 09:46:24 +08:00
|
|
|
pub use anyhow::Error;
|
2024-10-31 14:38:32 +08:00
|
|
|
use client_api::entity::{workspace_dto::PublishInfoView, PublishInfo};
|
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};
|
2024-10-26 11:20:16 +08:00
|
|
|
use flowy_error::FlowyError;
|
2024-08-14 15:50:21 +08:00
|
|
|
use lib_infra::async_trait::async_trait;
|
|
|
|
use uuid::Uuid;
|
2023-07-29 09:46:24 +08:00
|
|
|
|
|
|
|
/// [FolderCloudService] represents the cloud service for folder.
|
2024-08-14 15:50:21 +08:00
|
|
|
#[async_trait]
|
2023-07-29 09:46:24 +08:00
|
|
|
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
|
2024-10-26 11:20:16 +08:00
|
|
|
async fn create_workspace(&self, uid: i64, name: &str) -> Result<Workspace, FlowyError>;
|
2023-07-29 09:46:24 +08:00
|
|
|
|
2024-10-26 11:20:16 +08:00
|
|
|
async fn open_workspace(&self, workspace_id: &str) -> Result<(), FlowyError>;
|
2023-11-05 14:00:24 +08:00
|
|
|
|
|
|
|
/// Returns all workspaces of the user.
|
|
|
|
/// Returns vec![] if the cloud service doesn't support multiple workspaces
|
2024-10-26 11:20:16 +08:00
|
|
|
async fn get_all_workspace(&self) -> Result<Vec<WorkspaceRecord>, FlowyError>;
|
2023-11-05 14:00:24 +08:00
|
|
|
|
2024-08-18 05:16:42 +02:00
|
|
|
async fn get_folder_data(
|
2023-11-01 11:45:35 +08:00
|
|
|
&self,
|
|
|
|
workspace_id: &str,
|
|
|
|
uid: &i64,
|
2024-10-26 11:20:16 +08:00
|
|
|
) -> Result<Option<FolderData>, FlowyError>;
|
2023-07-29 09:46:24 +08:00
|
|
|
|
2024-08-18 05:16:42 +02:00
|
|
|
async 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,
|
2024-10-26 11:20:16 +08:00
|
|
|
) -> Result<Vec<FolderSnapshot>, FlowyError>;
|
2023-07-29 09:46:24 +08:00
|
|
|
|
2024-08-18 05:16:42 +02:00
|
|
|
async 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-10-26 11:20:16 +08:00
|
|
|
) -> Result<Vec<u8>, FlowyError>;
|
2023-12-29 13:02:27 +08:00
|
|
|
|
2024-08-18 05:16:42 +02:00
|
|
|
async fn batch_create_folder_collab_objects(
|
2023-12-29 13:02:27 +08:00
|
|
|
&self,
|
|
|
|
workspace_id: &str,
|
|
|
|
objects: Vec<FolderCollabParams>,
|
2024-10-26 11:20:16 +08:00
|
|
|
) -> Result<(), FlowyError>;
|
2023-07-29 09:46:24 +08:00
|
|
|
|
|
|
|
fn service_name(&self) -> String;
|
2024-07-08 13:45:57 +08:00
|
|
|
|
2024-08-18 05:16:42 +02:00
|
|
|
async fn publish_view(
|
2024-07-08 13:45:57 +08:00
|
|
|
&self,
|
|
|
|
workspace_id: &str,
|
2024-07-22 13:35:42 +08:00
|
|
|
payload: Vec<PublishPayload>,
|
2024-10-26 11:20:16 +08:00
|
|
|
) -> Result<(), FlowyError>;
|
2024-07-08 13:45:57 +08:00
|
|
|
|
2024-10-26 11:20:16 +08:00
|
|
|
async fn unpublish_views(
|
|
|
|
&self,
|
|
|
|
workspace_id: &str,
|
|
|
|
view_ids: Vec<String>,
|
|
|
|
) -> Result<(), FlowyError>;
|
2024-07-08 13:45:57 +08:00
|
|
|
|
2024-10-31 14:38:32 +08:00
|
|
|
async fn get_publish_info(&self, view_id: &str) -> Result<PublishInfo, FlowyError>;
|
|
|
|
|
|
|
|
async fn set_publish_name(
|
|
|
|
&self,
|
|
|
|
workspace_id: &str,
|
|
|
|
view_id: String,
|
|
|
|
new_name: String,
|
|
|
|
) -> Result<(), FlowyError>;
|
2024-07-08 13:45:57 +08:00
|
|
|
|
2024-08-18 05:16:42 +02:00
|
|
|
async fn set_publish_namespace(
|
2024-07-08 13:45:57 +08:00
|
|
|
&self,
|
|
|
|
workspace_id: &str,
|
|
|
|
new_namespace: &str,
|
2024-10-26 11:20:16 +08:00
|
|
|
) -> Result<(), FlowyError>;
|
2024-07-08 13:45:57 +08:00
|
|
|
|
2024-10-31 14:38:32 +08:00
|
|
|
async fn list_published_views(
|
|
|
|
&self,
|
|
|
|
workspace_id: &str,
|
|
|
|
) -> Result<Vec<PublishInfoView>, FlowyError>;
|
|
|
|
|
|
|
|
async fn get_default_published_view_info(
|
|
|
|
&self,
|
|
|
|
workspace_id: &str,
|
|
|
|
) -> Result<PublishInfo, FlowyError>;
|
|
|
|
|
|
|
|
async fn set_default_published_view(
|
|
|
|
&self,
|
|
|
|
workspace_id: &str,
|
|
|
|
view_id: uuid::Uuid,
|
|
|
|
) -> Result<(), FlowyError>;
|
|
|
|
|
|
|
|
async fn remove_default_published_view(&self, workspace_id: &str) -> Result<(), FlowyError>;
|
|
|
|
|
2024-10-26 11:20:16 +08:00
|
|
|
async fn get_publish_namespace(&self, workspace_id: &str) -> Result<String, FlowyError>;
|
2024-10-14 20:38:04 +08:00
|
|
|
|
2024-10-26 11:20:16 +08:00
|
|
|
async fn import_zip(&self, file_path: &str) -> Result<(), FlowyError>;
|
2023-07-29 09:46:24 +08:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
}
|