2023-07-14 13:37:13 +08:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2023-08-17 23:46:39 +08:00
|
|
|
use anyhow::Error;
|
|
|
|
|
2023-07-29 09:46:24 +08:00
|
|
|
use flowy_folder_deps::cloud::{
|
|
|
|
gen_workspace_id, FolderCloudService, FolderData, FolderSnapshot, Workspace,
|
|
|
|
};
|
2023-05-23 23:55:21 +08:00
|
|
|
use lib_infra::future::FutureResult;
|
|
|
|
use lib_infra::util::timestamp;
|
|
|
|
|
2023-07-14 13:37:13 +08:00
|
|
|
use crate::local_server::LocalServerDB;
|
|
|
|
|
|
|
|
pub(crate) struct LocalServerFolderCloudServiceImpl {
|
|
|
|
pub db: Arc<dyn LocalServerDB>,
|
|
|
|
}
|
2023-05-23 23:55:21 +08:00
|
|
|
|
|
|
|
impl FolderCloudService for LocalServerFolderCloudServiceImpl {
|
2023-07-29 09:46:24 +08:00
|
|
|
fn create_workspace(&self, _uid: i64, name: &str) -> FutureResult<Workspace, Error> {
|
2023-05-23 23:55:21 +08:00
|
|
|
let name = name.to_string();
|
|
|
|
FutureResult::new(async move {
|
|
|
|
Ok(Workspace {
|
2023-07-29 09:46:24 +08:00
|
|
|
id: gen_workspace_id().to_string(),
|
2023-05-23 23:55:21 +08:00
|
|
|
name: name.to_string(),
|
2023-05-31 17:42:14 +08:00
|
|
|
child_views: Default::default(),
|
2023-05-23 23:55:21 +08:00
|
|
|
created_at: timestamp(),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2023-07-05 20:57:09 +08:00
|
|
|
|
2023-07-29 09:46:24 +08:00
|
|
|
fn get_folder_data(&self, _workspace_id: &str) -> FutureResult<Option<FolderData>, Error> {
|
2023-07-14 13:37:13 +08:00
|
|
|
FutureResult::new(async move { Ok(None) })
|
|
|
|
}
|
|
|
|
|
2023-08-17 23:46:39 +08:00
|
|
|
fn get_folder_snapshots(
|
2023-07-05 20:57:09 +08:00
|
|
|
&self,
|
|
|
|
_workspace_id: &str,
|
2023-08-17 23:46:39 +08:00
|
|
|
_limit: usize,
|
|
|
|
) -> FutureResult<Vec<FolderSnapshot>, Error> {
|
|
|
|
FutureResult::new(async move { Ok(vec![]) })
|
2023-07-05 20:57:09 +08:00
|
|
|
}
|
|
|
|
|
2023-07-29 09:46:24 +08:00
|
|
|
fn get_folder_updates(&self, workspace_id: &str, uid: i64) -> FutureResult<Vec<Vec<u8>>, Error> {
|
2023-07-14 13:37:13 +08:00
|
|
|
let weak_db = Arc::downgrade(&self.db);
|
|
|
|
let workspace_id = workspace_id.to_string();
|
|
|
|
FutureResult::new(async move {
|
|
|
|
match weak_db.upgrade() {
|
|
|
|
None => Ok(vec![]),
|
|
|
|
Some(db) => {
|
|
|
|
let updates = db.get_collab_updates(uid, &workspace_id)?;
|
|
|
|
Ok(updates)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn service_name(&self) -> String {
|
|
|
|
"Local".to_string()
|
2023-07-05 20:57:09 +08:00
|
|
|
}
|
2023-05-23 23:55:21 +08:00
|
|
|
}
|