mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-10-29 00:51:24 +00:00
chore: remove unused code
This commit is contained in:
parent
e5b6393257
commit
c89f33e2f8
@ -1,9 +1,7 @@
|
||||
import 'package:appflowy/plugins/database/application/defines.dart';
|
||||
import 'package:appflowy_backend/dispatch/dispatch.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
|
||||
import 'package:appflowy_result/appflowy_result.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
@ -22,20 +20,10 @@ class WorkspaceErrorBloc
|
||||
void _dispatch() {
|
||||
on<WorkspaceErrorEvent>(
|
||||
(event, emit) async {
|
||||
await event.when(
|
||||
event.when(
|
||||
init: () {
|
||||
// _loadSnapshots();
|
||||
},
|
||||
resetWorkspace: () async {
|
||||
emit(state.copyWith(loadingState: const LoadingState.loading()));
|
||||
final payload = ResetWorkspacePB.create()
|
||||
..workspaceId = userFolder.workspaceId
|
||||
..uid = userFolder.uid;
|
||||
final result = await UserEventResetWorkspace(payload).send();
|
||||
if (!isClosed) {
|
||||
add(WorkspaceErrorEvent.didResetWorkspace(result));
|
||||
}
|
||||
},
|
||||
didResetWorkspace: (result) {
|
||||
result.fold(
|
||||
(_) {
|
||||
@ -68,7 +56,6 @@ class WorkspaceErrorBloc
|
||||
class WorkspaceErrorEvent with _$WorkspaceErrorEvent {
|
||||
const factory WorkspaceErrorEvent.init() = _Init;
|
||||
const factory WorkspaceErrorEvent.logout() = _DidLogout;
|
||||
const factory WorkspaceErrorEvent.resetWorkspace() = _ResetWorkspace;
|
||||
const factory WorkspaceErrorEvent.didResetWorkspace(
|
||||
FlowyResult<void, FlowyError> result,
|
||||
) = _DidResetWorkspace;
|
||||
|
||||
@ -86,7 +86,6 @@ class WorkspaceErrorScreen extends StatelessWidget {
|
||||
const VSpace(50),
|
||||
const LogoutButton(),
|
||||
const VSpace(20),
|
||||
const ResetWorkspaceButton(),
|
||||
]);
|
||||
|
||||
return Center(
|
||||
@ -157,43 +156,3 @@ class LogoutButton extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ResetWorkspaceButton extends StatelessWidget {
|
||||
const ResetWorkspaceButton({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
width: 200,
|
||||
height: 40,
|
||||
child: BlocBuilder<WorkspaceErrorBloc, WorkspaceErrorState>(
|
||||
builder: (context, state) {
|
||||
final isLoading = state.loadingState?.isLoading() ?? false;
|
||||
final icon = isLoading
|
||||
? const Center(
|
||||
child: CircularProgressIndicator.adaptive(),
|
||||
)
|
||||
: null;
|
||||
|
||||
return FlowyButton(
|
||||
text: FlowyText.medium(
|
||||
LocaleKeys.workspace_reset.tr(),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
onTap: () {
|
||||
NavigatorAlertDialog(
|
||||
title: LocaleKeys.workspace_resetWorkspacePrompt.tr(),
|
||||
confirm: () {
|
||||
context.read<WorkspaceErrorBloc>().add(
|
||||
const WorkspaceErrorEvent.resetWorkspace(),
|
||||
);
|
||||
},
|
||||
).show(context);
|
||||
},
|
||||
rightIcon: icon,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
29
frontend/rust-lib/Cargo.lock
generated
29
frontend/rust-lib/Cargo.lock
generated
@ -2957,7 +2957,6 @@ dependencies = [
|
||||
"arc-swap",
|
||||
"assert-json-diff",
|
||||
"bytes",
|
||||
"chrono",
|
||||
"client-api",
|
||||
"collab",
|
||||
"collab-database",
|
||||
@ -2966,7 +2965,6 @@ dependencies = [
|
||||
"collab-folder",
|
||||
"collab-plugins",
|
||||
"collab-user",
|
||||
"dashmap 6.0.1",
|
||||
"dotenv",
|
||||
"flowy-ai-pub",
|
||||
"flowy-database-pub",
|
||||
@ -2975,33 +2973,25 @@ dependencies = [
|
||||
"flowy-folder-pub",
|
||||
"flowy-search-pub",
|
||||
"flowy-server-pub",
|
||||
"flowy-sqlite",
|
||||
"flowy-storage",
|
||||
"flowy-storage-pub",
|
||||
"flowy-user-pub",
|
||||
"futures",
|
||||
"futures-util",
|
||||
"hex",
|
||||
"hyper 0.14.27",
|
||||
"lazy_static",
|
||||
"lib-dispatch",
|
||||
"lib-infra",
|
||||
"mime_guess",
|
||||
"postgrest",
|
||||
"rand 0.8.5",
|
||||
"reqwest 0.11.27",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 1.0.64",
|
||||
"tokio",
|
||||
"tokio-retry",
|
||||
"tokio-stream",
|
||||
"tokio-util",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"url",
|
||||
"uuid",
|
||||
"yrs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3138,6 +3128,7 @@ name = "flowy-user-pub"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"arc-swap",
|
||||
"base64 0.21.5",
|
||||
"chrono",
|
||||
"client-api",
|
||||
@ -5382,15 +5373,6 @@ dependencies = [
|
||||
"postgres-protocol",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "postgrest"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a966c650b47a064e7082170b4be74fca08c088d893244fc4b70123e3c1f3ee7"
|
||||
dependencies = [
|
||||
"reqwest 0.11.27",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
@ -6130,7 +6112,6 @@ dependencies = [
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-streams",
|
||||
"web-sys",
|
||||
"webpki-roots 0.25.2",
|
||||
"winreg 0.50.0",
|
||||
]
|
||||
|
||||
@ -8443,12 +8424,6 @@ dependencies = [
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.25.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc"
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.26.7"
|
||||
|
||||
@ -581,6 +581,7 @@ impl Chat {
|
||||
author_type: record.author_type,
|
||||
author_id: record.author_id,
|
||||
reply_message_id: record.reply_message_id,
|
||||
metadata: record.metadata,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@ -641,7 +642,7 @@ fn save_chat_message_disk(
|
||||
author_type: message.author.author_type as i64,
|
||||
author_id: message.author.author_id.to_string(),
|
||||
reply_message_id: message.reply_message_id,
|
||||
metadata: None,
|
||||
metadata: Some(serde_json::to_string(&message.metadata).unwrap_or_default()),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
insert_chat_messages(conn, &records)?;
|
||||
|
||||
@ -296,6 +296,9 @@ pub struct ChatMessagePB {
|
||||
|
||||
#[pb(index = 6, one_of)]
|
||||
pub reply_message_id: Option<i64>,
|
||||
|
||||
#[pb(index = 7, one_of)]
|
||||
pub metadata: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||
@ -316,6 +319,7 @@ impl From<ChatMessage> for ChatMessagePB {
|
||||
author_type: chat_message.author.author_type as i64,
|
||||
author_id: chat_message.author.author_id.to_string(),
|
||||
reply_message_id: None,
|
||||
metadata: Some(serde_json::to_string(&chat_message.metadata).unwrap_or_default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ use crate::deps_resolve::*;
|
||||
use crate::log_filter::init_log;
|
||||
use crate::server_layer::{current_server_type, Server, ServerProvider};
|
||||
use deps_resolve::reminder_deps::CollabInteractImpl;
|
||||
use flowy_sqlite::DBConnection;
|
||||
use user_state_callback::UserStatusCallbackImpl;
|
||||
|
||||
pub mod config;
|
||||
@ -334,4 +335,12 @@ impl ServerUser for ServerUserImpl {
|
||||
fn workspace_id(&self) -> FlowyResult<Uuid> {
|
||||
self.upgrade_user()?.workspace_id()
|
||||
}
|
||||
|
||||
fn user_id(&self) -> FlowyResult<i64> {
|
||||
self.upgrade_user()?.user_id()
|
||||
}
|
||||
|
||||
fn get_sqlite_db(&self, uid: i64) -> Result<DBConnection, FlowyError> {
|
||||
self.upgrade_user()?.get_sqlite_connection(uid)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
use arc_swap::ArcSwapOption;
|
||||
use dashmap::DashMap;
|
||||
use diesel::Connection;
|
||||
use serde_repr::*;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
|
||||
use std::sync::{Arc, Weak};
|
||||
|
||||
use serde_repr::*;
|
||||
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_server::af_cloud::define::ServerUser;
|
||||
use flowy_server::af_cloud::AppFlowyCloudServer;
|
||||
use flowy_server::local_server::{LocalServer, LocalServerDB};
|
||||
use flowy_server::local_server::LocalServer;
|
||||
use flowy_server::{AppFlowyEncryption, AppFlowyServer, EncryptionImpl};
|
||||
use flowy_server_pub::AuthenticatorType;
|
||||
use flowy_sqlite::kv::KVStorePreferences;
|
||||
@ -115,10 +115,7 @@ impl ServerProvider {
|
||||
|
||||
let server = match server_type {
|
||||
Server::Local => {
|
||||
let local_db = Arc::new(LocalServerDBImpl {
|
||||
storage_path: self.config.storage_path.clone(),
|
||||
});
|
||||
let server = Arc::new(LocalServer::new(local_db));
|
||||
let server = Arc::new(LocalServer::new(self.user.clone()));
|
||||
Ok::<Arc<dyn AppFlowyServer>, FlowyError>(server)
|
||||
},
|
||||
Server::AppFlowyCloud => {
|
||||
@ -171,24 +168,3 @@ pub fn current_server_type() -> Server {
|
||||
AuthenticatorType::AppFlowyCloud => Server::AppFlowyCloud,
|
||||
}
|
||||
}
|
||||
|
||||
struct LocalServerDBImpl {
|
||||
#[allow(dead_code)]
|
||||
storage_path: String,
|
||||
}
|
||||
|
||||
impl LocalServerDB for LocalServerDBImpl {
|
||||
fn get_user_profile(&self, _uid: i64) -> Result<UserProfile, FlowyError> {
|
||||
Err(
|
||||
FlowyError::local_version_not_support()
|
||||
.with_context("LocalServer doesn't support get_user_profile"),
|
||||
)
|
||||
}
|
||||
|
||||
fn get_user_workspace(&self, _uid: i64) -> Result<Option<UserWorkspace>, FlowyError> {
|
||||
Err(
|
||||
FlowyError::local_version_not_support()
|
||||
.with_context("LocalServer doesn't support get_user_workspace"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,20 +12,15 @@ crate-type = ["cdylib", "rlib"]
|
||||
tracing.workspace = true
|
||||
futures.workspace = true
|
||||
futures-util = "0.3.26"
|
||||
reqwest = { version = "0.11.20", features = ["native-tls-vendored", "multipart", "blocking"] }
|
||||
hyper = "0.14"
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
thiserror = "1.0"
|
||||
tokio = { workspace = true, features = ["sync"] }
|
||||
lazy_static = "1.4.0"
|
||||
bytes = { workspace = true, features = ["serde"] }
|
||||
tokio-retry = "0.3"
|
||||
anyhow.workspace = true
|
||||
arc-swap.workspace = true
|
||||
dashmap.workspace = true
|
||||
uuid.workspace = true
|
||||
chrono = { workspace = true, default-features = false, features = ["clock", "serde"] }
|
||||
collab = { workspace = true }
|
||||
collab-plugins = { workspace = true }
|
||||
collab-document = { workspace = true }
|
||||
@ -33,8 +28,6 @@ collab-entity = { workspace = true }
|
||||
collab-folder = { workspace = true }
|
||||
collab-database = { workspace = true }
|
||||
collab-user = { workspace = true }
|
||||
hex = "0.4.3"
|
||||
postgrest = "1.0"
|
||||
lib-infra = { workspace = true }
|
||||
flowy-user-pub = { workspace = true }
|
||||
flowy-folder-pub = { workspace = true }
|
||||
@ -46,14 +39,11 @@ flowy-search-pub = { workspace = true }
|
||||
flowy-storage = { workspace = true }
|
||||
flowy-storage-pub = { workspace = true }
|
||||
flowy-ai-pub = { workspace = true }
|
||||
mime_guess = "2.0"
|
||||
url = "2.4"
|
||||
tokio-util = "0.7"
|
||||
tokio-stream = { workspace = true, features = ["sync"] }
|
||||
lib-dispatch = { workspace = true }
|
||||
yrs.workspace = true
|
||||
rand = "0.8.5"
|
||||
semver = "1.0.23"
|
||||
flowy-sqlite = { workspace = true }
|
||||
|
||||
[dependencies.client-api]
|
||||
workspace = true
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_sqlite::DBConnection;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub const USER_SIGN_IN_URL: &str = "sign_in_url";
|
||||
@ -10,4 +11,8 @@ pub const USER_DEVICE_ID: &str = "device_id";
|
||||
pub trait ServerUser: Send + Sync {
|
||||
/// different user might return different workspace id.
|
||||
fn workspace_id(&self) -> FlowyResult<Uuid>;
|
||||
|
||||
fn user_id(&self) -> FlowyResult<i64>;
|
||||
|
||||
fn get_sqlite_db(&self, uid: i64) -> Result<DBConnection, FlowyError>;
|
||||
}
|
||||
|
||||
@ -378,10 +378,6 @@ where
|
||||
Arc::into_inner(rx)
|
||||
}
|
||||
|
||||
async fn reset_workspace(&self, _collab_object: CollabObject) -> Result<(), FlowyError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn create_collab_object(
|
||||
&self,
|
||||
collab_object: &CollabObject,
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
use crate::af_cloud::define::ServerUser;
|
||||
use client_api::entity::ai_dto::{LocalAIConfig, RepeatedRelatedQuestion};
|
||||
use flowy_ai_pub::cloud::{
|
||||
AIModel, ChatCloudService, ChatMessage, ChatMessageMetadata, ChatMessageType, ChatSettings,
|
||||
@ -10,9 +11,12 @@ use lib_infra::util::timestamp;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub(crate) struct LocalServerChatServiceImpl;
|
||||
pub struct LocalServerChatServiceImpl {
|
||||
pub user: Arc<dyn ServerUser>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ChatCloudService for LocalServerChatServiceImpl {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#![allow(unused_variables)]
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::local_server::LocalServerDB;
|
||||
use client_api::entity::workspace_dto::PublishInfoView;
|
||||
use client_api::entity::PublishInfo;
|
||||
use collab_entity::CollabType;
|
||||
@ -14,10 +13,7 @@ use flowy_folder_pub::entities::PublishPayload;
|
||||
use lib_infra::async_trait::async_trait;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub(crate) struct LocalServerFolderCloudServiceImpl {
|
||||
#[allow(dead_code)]
|
||||
pub db: Arc<dyn LocalServerDB>,
|
||||
}
|
||||
pub(crate) struct LocalServerFolderCloudServiceImpl;
|
||||
|
||||
#[async_trait]
|
||||
impl FolderCloudService for LocalServerFolderCloudServiceImpl {
|
||||
|
||||
@ -18,24 +18,19 @@ use lib_infra::box_any::BoxAny;
|
||||
use lib_infra::util::timestamp;
|
||||
|
||||
use crate::local_server::uid::UserIDGenerator;
|
||||
use crate::local_server::LocalServerDB;
|
||||
|
||||
lazy_static! {
|
||||
//FIXME: seriously, userID generation should work using lock-free algorithm
|
||||
static ref ID_GEN: Mutex<UserIDGenerator> = Mutex::new(UserIDGenerator::new(1));
|
||||
}
|
||||
|
||||
pub(crate) struct LocalServerUserAuthServiceImpl {
|
||||
#[allow(dead_code)]
|
||||
pub db: Arc<dyn LocalServerDB>,
|
||||
}
|
||||
|
||||
pub(crate) struct LocalServerUserServiceImpl;
|
||||
#[async_trait]
|
||||
impl UserCloudService for LocalServerUserAuthServiceImpl {
|
||||
impl UserCloudService for LocalServerUserServiceImpl {
|
||||
async fn sign_up(&self, params: BoxAny) -> Result<AuthResponse, FlowyError> {
|
||||
let params = params.unbox_or_error::<SignUpParams>()?;
|
||||
let uid = ID_GEN.lock().await.next_id();
|
||||
let workspace_id = uuid::Uuid::new_v4().to_string();
|
||||
let workspace_id = Uuid::new_v4().to_string();
|
||||
let user_workspace = UserWorkspace::new_local(&workspace_id, uid);
|
||||
let user_name = if params.name.is_empty() {
|
||||
DEFAULT_USER_NAME()
|
||||
@ -58,13 +53,9 @@ impl UserCloudService for LocalServerUserAuthServiceImpl {
|
||||
}
|
||||
|
||||
async fn sign_in(&self, params: BoxAny) -> Result<AuthResponse, FlowyError> {
|
||||
let db = self.db.clone();
|
||||
let params: SignInParams = params.unbox_or_error::<SignInParams>()?;
|
||||
let uid = ID_GEN.lock().await.next_id();
|
||||
|
||||
let user_workspace = db
|
||||
.get_user_workspace(uid)?
|
||||
.unwrap_or_else(make_user_workspace);
|
||||
let user_workspace = make_user_workspace();
|
||||
Ok(AuthResponse {
|
||||
user_id: uid,
|
||||
user_uuid: Uuid::new_v4(),
|
||||
@ -132,16 +123,7 @@ impl UserCloudService for LocalServerUserAuthServiceImpl {
|
||||
}
|
||||
|
||||
async fn get_user_profile(&self, credential: UserCredentials) -> Result<UserProfile, FlowyError> {
|
||||
match credential.uid {
|
||||
None => Err(FlowyError::record_not_found()),
|
||||
Some(uid) => {
|
||||
self.db.get_user_profile(uid).map(|mut profile| {
|
||||
// We don't want to expose the email in the local server
|
||||
profile.email = "".to_string();
|
||||
profile
|
||||
})
|
||||
},
|
||||
}
|
||||
Err(FlowyError::local_version_not_support().with_context("Not support"))
|
||||
}
|
||||
|
||||
async fn open_workspace(&self, workspace_id: &Uuid) -> Result<UserWorkspace, FlowyError> {
|
||||
@ -155,6 +137,32 @@ impl UserCloudService for LocalServerUserAuthServiceImpl {
|
||||
Ok(vec![])
|
||||
}
|
||||
|
||||
async fn create_workspace(&self, _workspace_name: &str) -> Result<UserWorkspace, FlowyError> {
|
||||
Err(
|
||||
FlowyError::local_version_not_support()
|
||||
.with_context("local server doesn't support multiple workspaces"),
|
||||
)
|
||||
}
|
||||
|
||||
async fn patch_workspace(
|
||||
&self,
|
||||
workspace_id: &Uuid,
|
||||
new_workspace_name: Option<&str>,
|
||||
new_workspace_icon: Option<&str>,
|
||||
) -> Result<(), FlowyError> {
|
||||
Err(
|
||||
FlowyError::local_version_not_support()
|
||||
.with_context("local server doesn't support multiple workspaces"),
|
||||
)
|
||||
}
|
||||
|
||||
async fn delete_workspace(&self, workspace_id: &Uuid) -> Result<(), FlowyError> {
|
||||
Err(
|
||||
FlowyError::local_version_not_support()
|
||||
.with_context("local server doesn't support multiple workspaces"),
|
||||
)
|
||||
}
|
||||
|
||||
async fn get_user_awareness_doc_state(
|
||||
&self,
|
||||
uid: i64,
|
||||
@ -172,10 +180,6 @@ impl UserCloudService for LocalServerUserAuthServiceImpl {
|
||||
Ok(encode_collab.doc_state.to_vec())
|
||||
}
|
||||
|
||||
async fn reset_workspace(&self, _collab_object: CollabObject) -> Result<(), FlowyError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn create_collab_object(
|
||||
&self,
|
||||
_collab_object: &CollabObject,
|
||||
@ -194,32 +198,6 @@ impl UserCloudService for LocalServerUserAuthServiceImpl {
|
||||
.with_context("local server doesn't support batch create collab object"),
|
||||
)
|
||||
}
|
||||
|
||||
async fn create_workspace(&self, _workspace_name: &str) -> Result<UserWorkspace, FlowyError> {
|
||||
Err(
|
||||
FlowyError::local_version_not_support()
|
||||
.with_context("local server doesn't support multiple workspaces"),
|
||||
)
|
||||
}
|
||||
|
||||
async fn delete_workspace(&self, workspace_id: &Uuid) -> Result<(), FlowyError> {
|
||||
Err(
|
||||
FlowyError::local_version_not_support()
|
||||
.with_context("local server doesn't support multiple workspaces"),
|
||||
)
|
||||
}
|
||||
|
||||
async fn patch_workspace(
|
||||
&self,
|
||||
workspace_id: &Uuid,
|
||||
new_workspace_name: Option<&str>,
|
||||
new_workspace_icon: Option<&str>,
|
||||
) -> Result<(), FlowyError> {
|
||||
Err(
|
||||
FlowyError::local_version_not_support()
|
||||
.with_context("local server doesn't support multiple workspaces"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn make_user_workspace() -> UserWorkspace {
|
||||
|
||||
@ -1,40 +1,30 @@
|
||||
use flowy_search_pub::cloud::SearchCloudService;
|
||||
use std::sync::Arc;
|
||||
|
||||
use flowy_ai_pub::cloud::ChatCloudService;
|
||||
use flowy_database_pub::cloud::{DatabaseAIService, DatabaseCloudService};
|
||||
use flowy_document_pub::cloud::DocumentCloudService;
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_folder_pub::cloud::FolderCloudService;
|
||||
use flowy_storage_pub::cloud::StorageCloudService;
|
||||
use tokio::sync::mpsc;
|
||||
// use flowy_user::services::database::{
|
||||
// get_user_profile, get_user_workspace, open_collab_db, open_user_db,
|
||||
// };
|
||||
use flowy_user_pub::cloud::UserCloudService;
|
||||
use flowy_user_pub::entities::*;
|
||||
|
||||
use crate::af_cloud::define::ServerUser;
|
||||
use crate::local_server::impls::{
|
||||
LocalServerChatServiceImpl, LocalServerDatabaseCloudServiceImpl,
|
||||
LocalServerDocumentCloudServiceImpl, LocalServerFolderCloudServiceImpl,
|
||||
LocalServerUserAuthServiceImpl,
|
||||
LocalServerUserServiceImpl,
|
||||
};
|
||||
use crate::AppFlowyServer;
|
||||
|
||||
pub trait LocalServerDB: Send + Sync + 'static {
|
||||
fn get_user_profile(&self, uid: i64) -> Result<UserProfile, FlowyError>;
|
||||
fn get_user_workspace(&self, uid: i64) -> Result<Option<UserWorkspace>, FlowyError>;
|
||||
}
|
||||
use flowy_ai_pub::cloud::ChatCloudService;
|
||||
use flowy_database_pub::cloud::{DatabaseAIService, DatabaseCloudService};
|
||||
use flowy_document_pub::cloud::DocumentCloudService;
|
||||
use flowy_folder_pub::cloud::FolderCloudService;
|
||||
use flowy_storage_pub::cloud::StorageCloudService;
|
||||
use flowy_user_pub::cloud::UserCloudService;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
pub struct LocalServer {
|
||||
local_db: Arc<dyn LocalServerDB>,
|
||||
user: Arc<dyn ServerUser>,
|
||||
stop_tx: Option<mpsc::Sender<()>>,
|
||||
}
|
||||
|
||||
impl LocalServer {
|
||||
pub fn new(local_db: Arc<dyn LocalServerDB>) -> Self {
|
||||
pub fn new(user: Arc<dyn ServerUser>) -> Self {
|
||||
Self {
|
||||
local_db,
|
||||
user,
|
||||
stop_tx: Default::default(),
|
||||
}
|
||||
}
|
||||
@ -49,38 +39,36 @@ impl LocalServer {
|
||||
|
||||
impl AppFlowyServer for LocalServer {
|
||||
fn user_service(&self) -> Arc<dyn UserCloudService> {
|
||||
Arc::new(LocalServerUserAuthServiceImpl {
|
||||
db: self.local_db.clone(),
|
||||
})
|
||||
Arc::new(LocalServerUserServiceImpl)
|
||||
}
|
||||
|
||||
fn folder_service(&self) -> Arc<dyn FolderCloudService> {
|
||||
Arc::new(LocalServerFolderCloudServiceImpl {
|
||||
db: self.local_db.clone(),
|
||||
})
|
||||
Arc::new(LocalServerFolderCloudServiceImpl)
|
||||
}
|
||||
|
||||
fn database_service(&self) -> Arc<dyn DatabaseCloudService> {
|
||||
Arc::new(LocalServerDatabaseCloudServiceImpl())
|
||||
}
|
||||
|
||||
fn database_ai_service(&self) -> Option<Arc<dyn DatabaseAIService>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn document_service(&self) -> Arc<dyn DocumentCloudService> {
|
||||
Arc::new(LocalServerDocumentCloudServiceImpl())
|
||||
}
|
||||
|
||||
fn file_storage(&self) -> Option<Arc<dyn StorageCloudService>> {
|
||||
None
|
||||
fn chat_service(&self) -> Arc<dyn ChatCloudService> {
|
||||
Arc::new(LocalServerChatServiceImpl {
|
||||
user: self.user.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
fn search_service(&self) -> Option<Arc<dyn SearchCloudService>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn database_ai_service(&self) -> Option<Arc<dyn DatabaseAIService>> {
|
||||
fn file_storage(&self) -> Option<Arc<dyn StorageCloudService>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn chat_service(&self) -> Arc<dyn ChatCloudService> {
|
||||
Arc::new(LocalServerChatServiceImpl)
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,14 +3,14 @@ use semver::Version;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use flowy_error::FlowyResult;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::setup_log;
|
||||
use flowy_server::af_cloud::define::ServerUser;
|
||||
use flowy_server::af_cloud::AppFlowyCloudServer;
|
||||
use flowy_server_pub::af_cloud_config::AFCloudConfiguration;
|
||||
|
||||
use crate::setup_log;
|
||||
use flowy_sqlite::DBConnection;
|
||||
|
||||
/// To run the test, create a .env.ci file in the 'flowy-server' directory and set the following environment variables:
|
||||
///
|
||||
@ -42,6 +42,14 @@ impl ServerUser for FakeServerUserImpl {
|
||||
fn workspace_id(&self) -> FlowyResult<Uuid> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn user_id(&self) -> FlowyResult<i64> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_sqlite_db(&self, uid: i64) -> Result<DBConnection, FlowyError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn generate_sign_in_url(user_email: &str, config: &AFCloudConfiguration) -> String {
|
||||
|
||||
@ -23,3 +23,4 @@ collab-folder = { workspace = true }
|
||||
tracing.workspace = true
|
||||
base64 = "0.21"
|
||||
client-api = { workspace = true }
|
||||
arc-swap = "1.7.1"
|
||||
|
||||
@ -263,8 +263,6 @@ pub trait UserCloudService: Send + Sync + 'static {
|
||||
None
|
||||
}
|
||||
|
||||
async fn reset_workspace(&self, collab_object: CollabObject) -> Result<(), FlowyError>;
|
||||
|
||||
async fn create_collab_object(
|
||||
&self,
|
||||
collab_object: &CollabObject,
|
||||
|
||||
@ -614,24 +614,6 @@ pub async fn get_all_reminder_event_handler(
|
||||
data_result_ok(reminders.into())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip_all, err)]
|
||||
pub async fn reset_workspace_handler(
|
||||
data: AFPluginData<ResetWorkspacePB>,
|
||||
manager: AFPluginState<Weak<UserManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let manager = upgrade_manager(manager)?;
|
||||
let reset_pb = data.into_inner();
|
||||
if reset_pb.workspace_id.is_empty() {
|
||||
return Err(FlowyError::new(
|
||||
ErrorCode::WorkspaceInitializeError,
|
||||
"The workspace id is empty",
|
||||
));
|
||||
}
|
||||
let _session = manager.get_session()?;
|
||||
manager.reset_workspace(reset_pb).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip_all, err)]
|
||||
pub async fn remove_reminder_event_handler(
|
||||
data: AFPluginData<ReminderIdentifierPB>,
|
||||
|
||||
@ -49,7 +49,6 @@ pub fn init(user_manager: Weak<UserManager>) -> AFPlugin {
|
||||
.event(UserEvent::GetAllReminders, get_all_reminder_event_handler)
|
||||
.event(UserEvent::RemoveReminder, remove_reminder_event_handler)
|
||||
.event(UserEvent::UpdateReminder, update_reminder_event_handler)
|
||||
.event(UserEvent::ResetWorkspace, reset_workspace_handler)
|
||||
.event(UserEvent::SetDateTimeSettings, set_date_time_settings)
|
||||
.event(UserEvent::GetDateTimeSettings, get_date_time_settings)
|
||||
.event(UserEvent::SetNotificationSettings, set_notification_settings)
|
||||
@ -183,9 +182,6 @@ pub enum UserEvent {
|
||||
#[event(input = "ReminderPB")]
|
||||
UpdateReminder = 31,
|
||||
|
||||
#[event(input = "ResetWorkspacePB")]
|
||||
ResetWorkspace = 32,
|
||||
|
||||
/// Change the Date/Time formats globally
|
||||
#[event(input = "DateTimeSettingsPB")]
|
||||
SetDateTimeSettings = 33,
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
use crate::migrations::session_migration::migrate_session_with_user_uuid;
|
||||
use crate::services::db::UserDB;
|
||||
use crate::services::entities::{UserConfig, UserPaths};
|
||||
use crate::services::sqlite_sql::user_sql::vacuum_database;
|
||||
use collab_integrate::CollabKVDB;
|
||||
|
||||
use arc_swap::ArcSwapOption;
|
||||
@ -18,8 +17,6 @@ use std::sync::{Arc, Weak};
|
||||
use tracing::{error, info};
|
||||
use uuid::Uuid;
|
||||
|
||||
const SQLITE_VACUUM_042: &str = "sqlite_vacuum_042_version";
|
||||
|
||||
pub struct AuthenticateUser {
|
||||
pub user_config: UserConfig,
|
||||
pub(crate) database: Arc<UserDB>,
|
||||
@ -44,23 +41,6 @@ impl AuthenticateUser {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vacuum_database_if_need(&self) {
|
||||
if !self
|
||||
.store_preferences
|
||||
.get_bool_or_default(SQLITE_VACUUM_042)
|
||||
{
|
||||
if let Ok(session) = self.get_session() {
|
||||
let _ = self.store_preferences.set_bool(SQLITE_VACUUM_042, true);
|
||||
if let Ok(conn) = self.database.get_connection(session.user_id) {
|
||||
info!("vacuum database 042");
|
||||
if let Err(err) = vacuum_database(conn) {
|
||||
error!("vacuum database error: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn user_id(&self) -> FlowyResult<i64> {
|
||||
let session = self.get_session()?;
|
||||
Ok(session.user_id)
|
||||
|
||||
@ -148,10 +148,3 @@ pub fn select_user_profile(uid: i64, mut conn: DBConnection) -> Result<UserProfi
|
||||
|
||||
Ok(user)
|
||||
}
|
||||
|
||||
pub(crate) fn vacuum_database(mut conn: DBConnection) -> Result<(), FlowyError> {
|
||||
sql_query("VACUUM")
|
||||
.execute(&mut *conn)
|
||||
.map_err(internal_error)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -268,7 +268,6 @@ impl UserManager {
|
||||
},
|
||||
_ => error!("Failed to get collab db or sqlite pool"),
|
||||
}
|
||||
self.authenticate_user.vacuum_database_if_need();
|
||||
|
||||
// migrations should run before set the first time installed version
|
||||
self.set_first_time_installed_version();
|
||||
|
||||
@ -414,24 +414,6 @@ impl UserManager {
|
||||
Ok(workspaces)
|
||||
}
|
||||
|
||||
/// Reset the remote workspace using local workspace data. This is useful when a user wishes to
|
||||
/// open a workspace on a new device that hasn't fully synchronized with the server.
|
||||
pub async fn reset_workspace(&self, reset: ResetWorkspacePB) -> FlowyResult<()> {
|
||||
let collab_object = CollabObject::new(
|
||||
reset.uid,
|
||||
reset.workspace_id.clone(),
|
||||
CollabType::Folder,
|
||||
reset.workspace_id.clone(),
|
||||
self.authenticate_user.user_config.device_id.clone(),
|
||||
);
|
||||
self
|
||||
.cloud_services
|
||||
.get_user_service()?
|
||||
.reset_workspace(collab_object)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument(level = "info", skip(self), err)]
|
||||
pub async fn subscribe_workspace(
|
||||
&self,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user