From 680d1309865faec3477ddabe2c37b15390d9b3b3 Mon Sep 17 00:00:00 2001 From: appflowy Date: Mon, 7 Feb 2022 10:37:01 +0800 Subject: [PATCH] refactor: remove unuse crate references --- frontend/Makefile.toml | 6 ------ frontend/rust-lib/dart-ffi/Cargo.toml | 3 --- frontend/rust-lib/dart-ffi/src/lib.rs | 5 ++--- frontend/rust-lib/flowy-net/src/http_server/core.rs | 8 ++++---- frontend/rust-lib/flowy-net/src/lib.rs | 2 ++ frontend/rust-lib/flowy-sdk/Cargo.toml | 1 - .../flowy-sdk/src/deps_resolve/document_deps.rs | 2 +- .../flowy-sdk/src/deps_resolve/folder_deps.rs | 6 +++--- .../rust-lib/flowy-sdk/src/deps_resolve/user_deps.rs | 2 +- frontend/rust-lib/flowy-sdk/src/lib.rs | 7 ++++--- frontend/rust-lib/flowy-test/Cargo.toml | 1 - frontend/rust-lib/flowy-test/src/lib.rs | 2 +- shared-lib/Cargo.lock | 1 - shared-lib/lib-ws/Cargo.toml | 1 - shared-lib/lib-ws/src/errors.rs | 7 +++++++ shared-lib/lib-ws/src/protobuf/model/document | 8 -------- shared-lib/lib-ws/src/ws.rs | 11 +++++------ 17 files changed, 30 insertions(+), 43 deletions(-) delete mode 100644 shared-lib/lib-ws/src/protobuf/model/document diff --git a/frontend/Makefile.toml b/frontend/Makefile.toml index 550575819f..48433548c2 100644 --- a/frontend/Makefile.toml +++ b/frontend/Makefile.toml @@ -115,12 +115,6 @@ script = [ echo PRODUCT_EXT: ${PRODUCT_EXT} echo APP_ENVIRONMENT: ${APP_ENVIRONMENT} echo ${platforms} - - echo "-------- Flutter --------" - flutter doctor - - echo "-------- Rust --------" - rustup show ''' ] script_runner = "@shell" diff --git a/frontend/rust-lib/dart-ffi/Cargo.toml b/frontend/rust-lib/dart-ffi/Cargo.toml index 1db8a03325..6787a98d26 100644 --- a/frontend/rust-lib/dart-ffi/Cargo.toml +++ b/frontend/rust-lib/dart-ffi/Cargo.toml @@ -26,10 +26,7 @@ once_cell = "1" lib-dispatch = {path = "../lib-dispatch" } flowy-sdk = {path = "../flowy-sdk"} dart-notify = {path = "../dart-notify" } - flowy-derive = {path = "../../../shared-lib/flowy-derive" } -backend-service = { path = "../../../shared-lib/backend-service" } - [features] flutter = ["dart-notify/dart"] diff --git a/frontend/rust-lib/dart-ffi/src/lib.rs b/frontend/rust-lib/dart-ffi/src/lib.rs index 027ddf5af2..24a87b1519 100644 --- a/frontend/rust-lib/dart-ffi/src/lib.rs +++ b/frontend/rust-lib/dart-ffi/src/lib.rs @@ -8,7 +8,9 @@ use crate::{ c::{extend_front_four_bytes_into_bytes, forget_rust}, model::{FFIRequest, FFIResponse}, }; +use flowy_sdk::get_client_server_configuration; use flowy_sdk::*; +use lib_dispatch::prelude::ToBytes; use lib_dispatch::prelude::*; use once_cell::sync::OnceCell; use std::{ffi::CStr, os::raw::c_char}; @@ -80,9 +82,6 @@ pub extern "C" fn set_stream_port(port: i64) -> i32 { #[no_mangle] pub extern "C" fn link_me_please() {} -use backend_service::configuration::get_client_server_configuration; -use lib_dispatch::prelude::ToBytes; - #[inline(always)] async fn post_to_flutter(response: EventResponse, port: i64) { let isolate = allo_isolate::Isolate::new(port); diff --git a/frontend/rust-lib/flowy-net/src/http_server/core.rs b/frontend/rust-lib/flowy-net/src/http_server/core.rs index a488d630ed..aa5e56a641 100644 --- a/frontend/rust-lib/flowy-net/src/http_server/core.rs +++ b/frontend/rust-lib/flowy-net/src/http_server/core.rs @@ -18,17 +18,17 @@ use lib_infra::future::FutureResult; use std::sync::Arc; use tokio::sync::broadcast; -pub struct CoreHttpCloudService { +pub struct FolderHttpCloudService { config: ClientServerConfiguration, } -impl CoreHttpCloudService { - pub fn new(config: ClientServerConfiguration) -> CoreHttpCloudService { +impl FolderHttpCloudService { + pub fn new(config: ClientServerConfiguration) -> FolderHttpCloudService { Self { config } } } -impl FolderCouldServiceV1 for CoreHttpCloudService { +impl FolderCouldServiceV1 for FolderHttpCloudService { fn init(&self) {} fn create_workspace(&self, token: &str, params: CreateWorkspaceParams) -> FutureResult { diff --git a/frontend/rust-lib/flowy-net/src/lib.rs b/frontend/rust-lib/flowy-net/src/lib.rs index f4c0be577d..9b646d6f5a 100644 --- a/frontend/rust-lib/flowy-net/src/lib.rs +++ b/frontend/rust-lib/flowy-net/src/lib.rs @@ -6,3 +6,5 @@ pub mod local_server; pub mod module; pub mod protobuf; pub mod ws; + +pub use backend_service::configuration::{get_client_server_configuration, ClientServerConfiguration}; diff --git a/frontend/rust-lib/flowy-sdk/Cargo.toml b/frontend/rust-lib/flowy-sdk/Cargo.toml index 4f8b69bdb0..0afae1e70e 100644 --- a/frontend/rust-lib/flowy-sdk/Cargo.toml +++ b/frontend/rust-lib/flowy-sdk/Cargo.toml @@ -26,7 +26,6 @@ parking_lot = "0.11" flowy-collaboration = { path = "../../../shared-lib/flowy-collaboration" } lib-ws = { path = "../../../shared-lib/lib-ws" } -backend-service = { path = "../../../shared-lib/backend-service" } lib-infra = { path = "../../../shared-lib/lib-infra" } [dev-dependencies] diff --git a/frontend/rust-lib/flowy-sdk/src/deps_resolve/document_deps.rs b/frontend/rust-lib/flowy-sdk/src/deps_resolve/document_deps.rs index 1bbc3701a1..453bc50435 100644 --- a/frontend/rust-lib/flowy-sdk/src/deps_resolve/document_deps.rs +++ b/frontend/rust-lib/flowy-sdk/src/deps_resolve/document_deps.rs @@ -1,4 +1,3 @@ -use backend_service::configuration::ClientServerConfiguration; use bytes::Bytes; use flowy_collaboration::entities::ws_data::ClientRevisionWSData; use flowy_database::ConnectionPool; @@ -6,6 +5,7 @@ use flowy_document::{ errors::{internal_error, FlowyError}, DocumentCloudService, DocumentUser, FlowyDocumentManager, }; +use flowy_net::ClientServerConfiguration; use flowy_net::{ http_server::document::DocumentHttpCloudService, local_server::LocalServer, ws::connection::FlowyWebSocketConnect, }; diff --git a/frontend/rust-lib/flowy-sdk/src/deps_resolve/folder_deps.rs b/frontend/rust-lib/flowy-sdk/src/deps_resolve/folder_deps.rs index 1d32ae8629..8e23f64863 100644 --- a/frontend/rust-lib/flowy-sdk/src/deps_resolve/folder_deps.rs +++ b/frontend/rust-lib/flowy-sdk/src/deps_resolve/folder_deps.rs @@ -1,4 +1,3 @@ -use backend_service::configuration::ClientServerConfiguration; use bytes::Bytes; use flowy_collaboration::entities::ws_data::ClientRevisionWSData; use flowy_database::ConnectionPool; @@ -8,8 +7,9 @@ use flowy_folder::{ errors::{internal_error, FlowyError}, event_map::{FolderCouldServiceV1, WorkspaceDatabase, WorkspaceUser}, }; +use flowy_net::ClientServerConfiguration; use flowy_net::{ - http_server::core::CoreHttpCloudService, local_server::LocalServer, ws::connection::FlowyWebSocketConnect, + http_server::core::FolderHttpCloudService, local_server::LocalServer, ws::connection::FlowyWebSocketConnect, }; use flowy_sync::{RevisionWebSocket, WSStateReceiver}; use flowy_user::services::UserSession; @@ -31,7 +31,7 @@ impl FolderDepsResolver { let database: Arc = Arc::new(WorkspaceDatabaseImpl(user_session)); let web_socket = Arc::new(FolderWebSocketImpl(ws_conn.clone())); let cloud_service: Arc = match local_server { - None => Arc::new(CoreHttpCloudService::new(server_config.clone())), + None => Arc::new(FolderHttpCloudService::new(server_config.clone())), Some(local_server) => local_server, }; diff --git a/frontend/rust-lib/flowy-sdk/src/deps_resolve/user_deps.rs b/frontend/rust-lib/flowy-sdk/src/deps_resolve/user_deps.rs index 59890bd0eb..7115c5a2bb 100644 --- a/frontend/rust-lib/flowy-sdk/src/deps_resolve/user_deps.rs +++ b/frontend/rust-lib/flowy-sdk/src/deps_resolve/user_deps.rs @@ -1,4 +1,4 @@ -use backend_service::configuration::ClientServerConfiguration; +use flowy_net::ClientServerConfiguration; use flowy_net::{http_server::user::UserHttpCloudService, local_server::LocalServer}; use flowy_user::event_map::UserCloudService; diff --git a/frontend/rust-lib/flowy-sdk/src/lib.rs b/frontend/rust-lib/flowy-sdk/src/lib.rs index 03c723db27..7e3c0da37b 100644 --- a/frontend/rust-lib/flowy-sdk/src/lib.rs +++ b/frontend/rust-lib/flowy-sdk/src/lib.rs @@ -1,8 +1,11 @@ mod deps_resolve; pub mod module; +pub use flowy_net::get_client_server_configuration; + use crate::deps_resolve::*; -use backend_service::configuration::ClientServerConfiguration; +use flowy_document::FlowyDocumentManager; use flowy_folder::{controller::FolderManager, errors::FlowyError}; +use flowy_net::ClientServerConfiguration; use flowy_net::{ entities::NetworkType, local_server::LocalServer, @@ -10,8 +13,6 @@ use flowy_net::{ }; use flowy_user::services::{notifier::UserStatus, UserSession, UserSessionConfig}; use lib_dispatch::prelude::*; - -use flowy_document::FlowyDocumentManager; use lib_dispatch::util::tokio_default_runtime; use module::mk_modules; pub use module::*; diff --git a/frontend/rust-lib/flowy-test/Cargo.toml b/frontend/rust-lib/flowy-test/Cargo.toml index 2495da3c00..faf85b7c32 100644 --- a/frontend/rust-lib/flowy-test/Cargo.toml +++ b/frontend/rust-lib/flowy-test/Cargo.toml @@ -13,7 +13,6 @@ flowy-folder = { path = "../flowy-folder", default-features = false} lib-dispatch = { path = "../lib-dispatch" } flowy-collaboration = { path = "../../../shared-lib/flowy-collaboration" } -backend-service = { path = "../../../shared-lib/backend-service" } lib-ot = { path = "../../../shared-lib/lib-ot" } lib-infra = { path = "../../../shared-lib/lib-infra" } diff --git a/frontend/rust-lib/flowy-test/src/lib.rs b/frontend/rust-lib/flowy-test/src/lib.rs index c996cd294c..6d02f4f973 100644 --- a/frontend/rust-lib/flowy-test/src/lib.rs +++ b/frontend/rust-lib/flowy-test/src/lib.rs @@ -2,7 +2,7 @@ pub mod event_builder; pub mod helper; use crate::helper::*; -use backend_service::configuration::{get_client_server_configuration, ClientServerConfiguration}; +use flowy_net::{get_client_server_configuration, ClientServerConfiguration}; use flowy_sdk::{FlowySDK, FlowySDKConfig}; use flowy_user::entities::UserProfile; use lib_infra::uuid_string; diff --git a/shared-lib/Cargo.lock b/shared-lib/Cargo.lock index f67087619d..262980c653 100644 --- a/shared-lib/Cargo.lock +++ b/shared-lib/Cargo.lock @@ -1118,7 +1118,6 @@ dependencies = [ name = "lib-ws" version = "0.1.0" dependencies = [ - "backend-service", "bytes", "dashmap", "env_logger 0.8.4", diff --git a/shared-lib/lib-ws/Cargo.toml b/shared-lib/lib-ws/Cargo.toml index 1deef5e0a7..9094e3a334 100644 --- a/shared-lib/lib-ws/Cargo.toml +++ b/shared-lib/lib-ws/Cargo.toml @@ -7,7 +7,6 @@ edition = "2018" [dependencies] flowy-derive = { path = "../flowy-derive" } -backend-service = { path = "../backend-service" } lib-infra = { path = "../lib-infra" } tokio-tungstenite = "0.15" diff --git a/shared-lib/lib-ws/src/errors.rs b/shared-lib/lib-ws/src/errors.rs index e263706b44..318b8fa7de 100644 --- a/shared-lib/lib-ws/src/errors.rs +++ b/shared-lib/lib-ws/src/errors.rs @@ -2,6 +2,7 @@ use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; use futures_channel::mpsc::TrySendError; use std::fmt::Debug; use strum_macros::Display; +use tokio::sync::oneshot::error::RecvError; use tokio_tungstenite::tungstenite::{http::StatusCode, Message}; use url::ParseError; @@ -83,6 +84,12 @@ impl std::convert::From> for WSErro } } +impl std::convert::From for WSError { + fn from(error: RecvError) -> Self { + WSError::internal().context(error) + } +} + impl std::convert::From for WSError { fn from(error: tokio_tungstenite::tungstenite::Error) -> Self { match error { diff --git a/shared-lib/lib-ws/src/protobuf/model/document b/shared-lib/lib-ws/src/protobuf/model/document deleted file mode 100644 index 280e596bde..0000000000 --- a/shared-lib/lib-ws/src/protobuf/model/document +++ /dev/null @@ -1,8 +0,0 @@ -#![cfg_attr(rustfmt, rustfmt::skip)] -// Auto-generated, do not edit - -mod errors; -pub use errors::*; - -mod msg; -pub use msg::*; diff --git a/shared-lib/lib-ws/src/ws.rs b/shared-lib/lib-ws/src/ws.rs index 05e3f98b68..adbb49f9ac 100644 --- a/shared-lib/lib-ws/src/ws.rs +++ b/shared-lib/lib-ws/src/ws.rs @@ -4,7 +4,6 @@ use crate::{ errors::WSError, WSChannel, WebSocketRawMessage, }; -use backend_service::errors::ServerError; use bytes::Bytes; use dashmap::DashMap; use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender}; @@ -73,7 +72,7 @@ impl WSController { Ok(()) } - pub async fn start(&self, addr: String) -> Result<(), ServerError> { + pub async fn start(&self, addr: String) -> Result<(), WSError> { *self.addr.write().await = Some(addr.clone()); let strategy = FixedInterval::from_millis(5000).take(3); self.connect(addr, strategy).await @@ -89,7 +88,7 @@ impl WSController { } } - async fn connect(&self, addr: String, strategy: T) -> Result<(), ServerError> + async fn connect(&self, addr: String, strategy: T) -> Result<(), WSError> where T: IntoIterator, I: Iterator + Send + 'static, @@ -100,7 +99,7 @@ impl WSController { return Ok(()); } - let (ret, rx) = oneshot::channel::>(); + let (ret, rx) = oneshot::channel::>(); *self.addr.write().await = Some(addr.clone()); let action = WSConnectAction { addr, @@ -133,14 +132,14 @@ impl WSController { .write() .await .update_state(WSConnectState::Disconnected); - let _ = ret.send(Err(ServerError::internal().context(e))); + let _ = ret.send(Err(WSError::internal().context(e))); } } }); rx.await? } - pub async fn retry(&self, count: usize) -> Result<(), ServerError> { + pub async fn retry(&self, count: usize) -> Result<(), WSError> { if !self.conn_state_notify.read().await.conn_state.is_disconnected() { return Ok(()); }