Refactor/rename crate (#1275)

This commit is contained in:
Nathan.fooo
2022-10-13 23:29:37 +08:00
committed by GitHub
parent 48bb80b1d0
commit cf4a2920f8
68 changed files with 857 additions and 723 deletions

View File

@ -13,7 +13,7 @@ flowy-sync = { path = "../../../shared-lib/flowy-sync"}
flowy-folder-data-model = { path = "../../../shared-lib/flowy-folder-data-model"}
flowy-folder = { path = "../flowy-folder" }
flowy-user = { path = "../flowy-user" }
flowy-text-block = { path = "../flowy-text-block" }
flowy-document = { path = "../flowy-document" }
lazy_static = "1.4.0"
lib-infra = { path = "../../../shared-lib/lib-infra" }
protobuf = {version = "2.18.0"}

View File

@ -2,45 +2,45 @@ use crate::{
configuration::*,
request::{HttpRequestBuilder, ResponseMiddleware},
};
use flowy_document::DocumentCloudService;
use flowy_error::FlowyError;
use flowy_sync::entities::text_block::{CreateTextBlockParams, DocumentPB, ResetTextBlockParams, TextBlockIdPB};
use flowy_text_block::TextEditorCloudService;
use flowy_sync::entities::document::{CreateDocumentParams, DocumentIdPB, DocumentPayloadPB, ResetDocumentParams};
use http_flowy::response::FlowyResponse;
use lazy_static::lazy_static;
use lib_infra::future::FutureResult;
use std::sync::Arc;
pub struct BlockHttpCloudService {
pub struct DocumentCloudServiceImpl {
config: ClientServerConfiguration,
}
impl BlockHttpCloudService {
impl DocumentCloudServiceImpl {
pub fn new(config: ClientServerConfiguration) -> Self {
Self { config }
}
}
impl TextEditorCloudService for BlockHttpCloudService {
fn create_text_block(&self, token: &str, params: CreateTextBlockParams) -> FutureResult<(), FlowyError> {
impl DocumentCloudService for DocumentCloudServiceImpl {
fn create_document(&self, token: &str, params: CreateDocumentParams) -> FutureResult<(), FlowyError> {
let token = token.to_owned();
let url = self.config.doc_url();
FutureResult::new(async move { create_document_request(&token, params, &url).await })
}
fn read_text_block(&self, token: &str, params: TextBlockIdPB) -> FutureResult<Option<DocumentPB>, FlowyError> {
fn fetch_document(&self, token: &str, params: DocumentIdPB) -> FutureResult<Option<DocumentPayloadPB>, FlowyError> {
let token = token.to_owned();
let url = self.config.doc_url();
FutureResult::new(async move { read_document_request(&token, params, &url).await })
}
fn update_text_block(&self, token: &str, params: ResetTextBlockParams) -> FutureResult<(), FlowyError> {
fn update_document_content(&self, token: &str, params: ResetDocumentParams) -> FutureResult<(), FlowyError> {
let token = token.to_owned();
let url = self.config.doc_url();
FutureResult::new(async move { reset_doc_request(&token, params, &url).await })
}
}
pub async fn create_document_request(token: &str, params: CreateTextBlockParams, url: &str) -> Result<(), FlowyError> {
pub async fn create_document_request(token: &str, params: CreateDocumentParams, url: &str) -> Result<(), FlowyError> {
let _ = request_builder()
.post(url)
.header(HEADER_TOKEN, token)
@ -52,9 +52,9 @@ pub async fn create_document_request(token: &str, params: CreateTextBlockParams,
pub async fn read_document_request(
token: &str,
params: TextBlockIdPB,
params: DocumentIdPB,
url: &str,
) -> Result<Option<DocumentPB>, FlowyError> {
) -> Result<Option<DocumentPayloadPB>, FlowyError> {
let doc = request_builder()
.get(url)
.header(HEADER_TOKEN, token)
@ -65,7 +65,7 @@ pub async fn read_document_request(
Ok(doc)
}
pub async fn reset_doc_request(token: &str, params: ResetTextBlockParams, url: &str) -> Result<(), FlowyError> {
pub async fn reset_doc_request(token: &str, params: ResetDocumentParams, url: &str) -> Result<(), FlowyError> {
let _ = request_builder()
.patch(url)
.header(HEADER_TOKEN, token)

View File

@ -1,6 +1,6 @@
use flowy_sync::entities::revision::{RepeatedRevision, Revision};
use flowy_sync::{
entities::{folder::FolderInfo, text_block::DocumentPB},
entities::{document::DocumentPayloadPB, folder::FolderInfo},
errors::CollaborateError,
server_document::*,
server_folder::FolderCloudPersistence,
@ -29,25 +29,25 @@ pub trait RevisionCloudStorage: Send + Sync {
) -> BoxResultFuture<(), CollaborateError>;
}
pub(crate) struct LocalTextBlockCloudPersistence {
pub(crate) struct LocalDocumentCloudPersistence {
storage: Arc<dyn RevisionCloudStorage>,
}
impl Debug for LocalTextBlockCloudPersistence {
impl Debug for LocalDocumentCloudPersistence {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str("LocalRevisionCloudPersistence")
}
}
impl std::default::Default for LocalTextBlockCloudPersistence {
impl std::default::Default for LocalDocumentCloudPersistence {
fn default() -> Self {
LocalTextBlockCloudPersistence {
LocalDocumentCloudPersistence {
storage: Arc::new(MemoryDocumentCloudStorage::default()),
}
}
}
impl FolderCloudPersistence for LocalTextBlockCloudPersistence {
impl FolderCloudPersistence for LocalDocumentCloudPersistence {
fn read_folder(&self, _user_id: &str, folder_id: &str) -> BoxResultFuture<FolderInfo, CollaborateError> {
let storage = self.storage.clone();
let folder_id = folder_id.to_owned();
@ -109,8 +109,8 @@ impl FolderCloudPersistence for LocalTextBlockCloudPersistence {
}
}
impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence {
fn read_text_block(&self, doc_id: &str) -> BoxResultFuture<DocumentPB, CollaborateError> {
impl DocumentCloudPersistence for LocalDocumentCloudPersistence {
fn read_document(&self, doc_id: &str) -> BoxResultFuture<DocumentPayloadPB, CollaborateError> {
let storage = self.storage.clone();
let doc_id = doc_id.to_owned();
Box::pin(async move {
@ -122,11 +122,11 @@ impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence {
})
}
fn create_text_block(
fn create_document(
&self,
doc_id: &str,
repeated_revision: RepeatedRevision,
) -> BoxResultFuture<Option<DocumentPB>, CollaborateError> {
) -> BoxResultFuture<Option<DocumentPayloadPB>, CollaborateError> {
let doc_id = doc_id.to_owned();
let storage = self.storage.clone();
Box::pin(async move {
@ -135,7 +135,7 @@ impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence {
})
}
fn read_text_block_revisions(
fn read_document_revisions(
&self,
doc_id: &str,
rev_ids: Option<Vec<i64>>,
@ -148,7 +148,7 @@ impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence {
})
}
fn save_text_block_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> {
fn save_document_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> {
let storage = self.storage.clone();
Box::pin(async move {
let _ = storage.set_revisions(repeated_revision).await?;
@ -156,7 +156,7 @@ impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence {
})
}
fn reset_text_block(&self, doc_id: &str, revisions: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> {
fn reset_document(&self, doc_id: &str, revisions: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> {
let storage = self.storage.clone();
let doc_id = doc_id.to_owned();
Box::pin(async move {

View File

@ -1,4 +1,4 @@
use crate::local_server::persistence::LocalTextBlockCloudPersistence;
use crate::local_server::persistence::LocalDocumentCloudPersistence;
use async_stream::stream;
use bytes::Bytes;
use flowy_error::{internal_error, FlowyError};
@ -6,7 +6,7 @@ use flowy_folder::event_map::FolderCouldServiceV1;
use flowy_sync::{
client_document::default::initial_document_str,
entities::{
text_block::{CreateTextBlockParams, DocumentPB, ResetTextBlockParams, TextBlockIdPB},
document::{CreateDocumentParams, DocumentIdPB, DocumentPayloadPB, ResetDocumentParams},
ws_data::{ClientRevisionWSData, ClientRevisionWSDataType},
},
errors::CollaborateError,
@ -39,7 +39,7 @@ impl LocalServer {
client_ws_sender: mpsc::UnboundedSender<WebSocketRawMessage>,
client_ws_receiver: broadcast::Sender<WebSocketRawMessage>,
) -> Self {
let persistence = Arc::new(LocalTextBlockCloudPersistence::default());
let persistence = Arc::new(LocalDocumentCloudPersistence::default());
let doc_manager = Arc::new(ServerDocumentManager::new(persistence.clone()));
let folder_manager = Arc::new(ServerFolderManager::new(persistence));
let stop_tx = RwLock::new(None);
@ -252,6 +252,7 @@ impl RevisionUser for LocalRevisionUser {
}
}
use flowy_document::DocumentCloudService;
use flowy_folder::entities::{
app::{AppIdPB, CreateAppParams, UpdateAppParams},
trash::RepeatedTrashIdPB,
@ -261,7 +262,6 @@ use flowy_folder::entities::{
use flowy_folder_data_model::revision::{
gen_app_id, gen_workspace_id, AppRevision, TrashRevision, ViewRevision, WorkspaceRevision,
};
use flowy_text_block::TextEditorCloudService;
use flowy_user::entities::{
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB,
};
@ -414,22 +414,26 @@ impl UserCloudService for LocalServer {
}
}
impl TextEditorCloudService for LocalServer {
fn create_text_block(&self, _token: &str, _params: CreateTextBlockParams) -> FutureResult<(), FlowyError> {
impl DocumentCloudService for LocalServer {
fn create_document(&self, _token: &str, _params: CreateDocumentParams) -> FutureResult<(), FlowyError> {
FutureResult::new(async { Ok(()) })
}
fn read_text_block(&self, _token: &str, params: TextBlockIdPB) -> FutureResult<Option<DocumentPB>, FlowyError> {
let doc = DocumentPB {
block_id: params.value,
text: initial_document_str(),
fn fetch_document(
&self,
_token: &str,
params: DocumentIdPB,
) -> FutureResult<Option<DocumentPayloadPB>, FlowyError> {
let doc = DocumentPayloadPB {
doc_id: params.value,
content: initial_document_str(),
rev_id: 0,
base_rev_id: 0,
};
FutureResult::new(async { Ok(Some(doc)) })
}
fn update_text_block(&self, _token: &str, _params: ResetTextBlockParams) -> FutureResult<(), FlowyError> {
fn update_document_content(&self, _token: &str, _params: ResetDocumentParams) -> FutureResult<(), FlowyError> {
FutureResult::new(async { Ok(()) })
}
}