Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
chore: rename data path
Nathanefb98d28ef2d
diff --git a/frontend/appflowy_flutter/lib/startup/tasks/rust_sdk.dart b/frontend/appflowy_flutter/lib/startup/tasks/rust_sdk.dartindex 55f2f53512..c406dd161a 100644--- a/frontend/appflowy_flutter/lib/startup/tasks/rust_sdk.dart+++ b/frontend/appflowy_flutter/lib/startup/tasks/rust_sdk.dart@@ -73,10 +73,10 @@ Future<Directory> appFlowyApplicationDataDirectory() async {case IntegrationMode.develop:final Directory documentsDir = await getApplicationSupportDirectory().then((directory) => directory.create());- return Directory(path.join(documentsDir.path, 'data_dev')).create();+ return Directory(path.join(documentsDir.path, 'data_dev'));case IntegrationMode.release:final Directory documentsDir = await getApplicationSupportDirectory();- return Directory(path.join(documentsDir.path, 'data')).create();+ return Directory(path.join(documentsDir.path, 'data'));case IntegrationMode.unitTest:case IntegrationMode.integrationTest:return Directory(path.join(Directory.current.path, '.sandbox'));diff --git a/frontend/appflowy_flutter/lib/user/application/auth/backend_auth_service.dart b/frontend/appflowy_flutter/lib/user/application/auth/backend_auth_service.dartindex 9147fb4fb9..b5cf413603 100644--- a/frontend/appflowy_flutter/lib/user/application/auth/backend_auth_service.dart+++ b/frontend/appflowy_flutter/lib/user/application/auth/backend_auth_service.dart@@ -8,7 +8,6 @@ import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'show SignInPayloadPB, SignUpPayloadPB, UserProfilePB;import 'package:appflowy_result/appflowy_result.dart';import 'package:easy_localization/easy_localization.dart';-import 'package:flowy_infra/uuid.dart';import '../../../generated/locale_keys.g.dart';import 'device_id.dart';@@ -65,13 +64,13 @@ class BackendAuthService implements AuthService {Map<String, String> params = const {},}) async {const password = "Guest!@123456";- final uid = uuid();- final userEmail = "[email protected]";+ final userEmail = "[email protected]";final request = SignUpPayloadPB.create()..name = LocaleKeys.defaultUsername.tr()..email = userEmail..password = password+ ..isAnon = true// When sign up as guest, the auth type is always local...authType = AuthenticatorPB.Local..deviceId = await getDeviceId();diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lockindex baa5c5ee6d..a72f4596f6 100644--- a/frontend/rust-lib/Cargo.lock+++ b/frontend/rust-lib/Cargo.lock@@ -2604,6 +2604,7 @@ dependencies = ["tokio","tokio-stream","tracing",+ "url","uuid",]@@ -3049,7 +3050,6 @@ dependencies = ["collab-user","dashmap 6.0.1","diesel",- "diesel_derives","fake","fancy-regex 0.11.0","flowy-codegen",@@ -3064,7 +3064,6 @@ dependencies = ["lib-dispatch","lib-infra","nanoid",- "once_cell","protobuf","quickcheck","quickcheck_macros",@@ -3074,7 +3073,6 @@ dependencies = ["semver","serde","serde_json",- "serde_repr","strum","strum_macros 0.25.2","tokio",diff --git a/frontend/rust-lib/flowy-core/Cargo.toml b/frontend/rust-lib/flowy-core/Cargo.tomlindex 6225652078..6499f79284 100644--- a/frontend/rust-lib/flowy-core/Cargo.toml+++ b/frontend/rust-lib/flowy-core/Cargo.toml@@ -58,6 +58,7 @@ serde_repr.workspace = trueuuid.workspace = truesysinfo = "0.30.5"semver = { version = "1.0.22", features = ["serde"] }+url = "2.5.0"[features]profiling = ["console-subscriber", "tokio/tracing"]diff --git a/frontend/rust-lib/flowy-core/src/config.rs b/frontend/rust-lib/flowy-core/src/config.rsindex 0067eff5a1..27f658de8d 100644--- a/frontend/rust-lib/flowy-core/src/config.rs+++ b/frontend/rust-lib/flowy-core/src/config.rs@@ -1,9 +1,10 @@use std::fmt;-use std::path::Path;+use std::path::{Path, PathBuf};use base64::Engine;use semver::Version;use tracing::{error, info};+use url::Url;use crate::log_filter::create_log_filter;use flowy_server_pub::af_cloud_config::AFCloudConfiguration;@@ -46,30 +47,60 @@ impl fmt::Debug for AppFlowyCoreConfig {}fn make_user_data_folder(root: &str, url: &str) -> String {- // Isolate the user data folder by using the base url of AppFlowy cloud. This is to avoid- // the user data folder being shared by different AppFlowy cloud.- let storage_path = if !url.is_empty() {- let server_base64 = URL_SAFE_ENGINE.encode(url);- format!("{}_{}", root, server_base64)+ // If a URL is provided, try to parse it and extract the domain name.+ // This isolates the user data folder by the domain, which prevents data sharing+ // between different AppFlowy cloud instances.+ print!("Creating user data folder for URL: {}, root:{}", url, root);+ let mut storage_path = if url.is_empty() {+ PathBuf::from(root)} else {- root.to_string()+ let server_base64 = URL_SAFE_ENGINE.encode(url);+ PathBuf::from(format!("{}_{}", root, server_base64))};+ // Only use new storage path if the old one doesn't exist+ if !storage_path.exists() {+ let anon_path = format!("{}_anonymous", root);+ // We use domain name as suffix to isolate the user data folder since version 0.8.9+ let new_storage_path = if url.is_empty() {+ // if the url is empty, then it's anonymous mode+ anon_path+ } else {+ match Url::parse(url) {+ Ok(parsed_url) => {+ if let Some(domain) = parsed_url.host_str() {+ format!("{}_{}", root, domain)+ } else {+ anon_path+ }+ },+ Err(_) => anon_path,+ }+ };++ storage_path = PathBuf::from(new_storage_path);+ }+// Copy the user data folder from the root path to the isolated path// The root path without any suffix is the created by the local version AppFlowy- if !Path::new(&storage_path).exists() && Path::new(root).exists() {- info!("Copy dir from {} to {}", root, storage_path);+ if !storage_path.exists() && Path::new(root).exists() {+ info!("Copy dir from {} to {:?}", root, storage_path);let src = Path::new(root);- match copy_dir_recursive(src, Path::new(&storage_path)) {- Ok(_) => storage_path,+ match copy_dir_recursive(src, &storage_path) {+ Ok(_) => storage_path+ .into_os_string()+ .into_string()+ .unwrap_or_else(|_| root.to_string()),Err(err) => {- // when the copy dir failed, use the root path as the storage patherror!("Copy dir failed: {}", err);root.to_string()},}} else {storage_path+ .into_os_string()+ .into_string()+ .unwrap_or_else(|_| root.to_string())}}diff --git a/frontend/rust-lib/flowy-user-pub/src/entities.rs b/frontend/rust-lib/flowy-user-pub/src/entities.rsindex 857a735edb..fce59b7994 100644--- a/frontend/rust-lib/flowy-user-pub/src/entities.rs+++ b/frontend/rust-lib/flowy-user-pub/src/entities.rs@@ -42,6 +42,7 @@ pub struct SignUpParams {pub password: String,pub auth_type: Authenticator,pub device_id: String,+ pub is_anon: bool,}#[derive(Serialize, Deserialize, Debug, Clone)]diff --git a/frontend/rust-lib/flowy-user/Cargo.toml b/frontend/rust-lib/flowy-user/Cargo.tomlindex 5ad579a0fb..4d021161ac 100644--- a/frontend/rust-lib/flowy-user/Cargo.toml+++ b/frontend/rust-lib/flowy-user/Cargo.toml@@ -31,12 +31,9 @@ tracing.workspace = truebytes.workspace = trueserde = { workspace = true, features = ["rc"] }serde_json.workspace = true-serde_repr.workspace = trueprotobuf.workspace = truelazy_static = "1.4.0"diesel.workspace = true-diesel_derives = { version = "2.1.0", features = ["sqlite", "r2d2"] }-once_cell = "1.17.1"strum = "0.25"strum_macros = "0.25.2"tokio = { workspace = true, features = ["rt"] }diff --git a/frontend/rust-lib/flowy-user/src/entities/auth.rs b/frontend/rust-lib/flowy-user/src/entities/auth.rsindex dbfd9b811a..09b71eb6d4 100644--- a/frontend/rust-lib/flowy-user/src/entities/auth.rs+++ b/frontend/rust-lib/flowy-user/src/entities/auth.rs@@ -57,6 +57,9 @@ pub struct SignUpPayloadPB {#[pb(index = 5)]pub device_id: String,++ #[pb(index = 6)]+ pub is_anon: bool,}impl TryInto<SignUpParams> for SignUpPayloadPB {@@ -73,6 +76,7 @@ impl TryInto<SignUpParams> for SignUpPayloadPB {password: password.0,auth_type: self.auth_type.into(),device_id: self.device_id,+ is_anon: self.is_anon,})}}diff --git a/frontend/rust-lib/flowy-user/src/event_handler.rs b/frontend/rust-lib/flowy-user/src/event_handler.rsindex dfd166b1a6..4d2ee57ce8 100644--- a/frontend/rust-lib/flowy-user/src/event_handler.rs+++ b/frontend/rust-lib/flowy-user/src/event_handler.rs@@ -76,14 +76,14 @@ pub async fn sign_up(let params: SignUpParams = data.into_inner().try_into()?;let authenticator = params.auth_type.clone();- let old_authenticator = manager.cloud_services.get_user_authenticator();+ let prev_authenticator = manager.cloud_services.get_user_authenticator();match manager.sign_up(authenticator, BoxAny::new(params)).await {Ok(profile) => data_result_ok(UserProfilePB::from(profile)),Err(err) => {manager.cloud_services- .set_user_authenticator(&old_authenticator);- return Err(err);+ .set_user_authenticator(&prev_authenticator);+ Err(err)},}}diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager.rsindex c41485f6c9..864629d169 100644--- a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs+++ b/frontend/rust-lib/flowy-user/src/user_manager/manager.rs@@ -403,7 +403,6 @@ impl UserManager {) -> Result<UserProfile, FlowyError> {// sign out the current user if there is onelet migration_user = self.get_migration_user(&authenticator).await;-self.cloud_services.set_user_authenticator(&authenticator);let auth_service = self.cloud_services.get_user_service()?;let response: AuthResponse = auth_service.sign_up(params).await?;diff --git a/frontend/rust-lib/lib-infra/src/file_util.rs b/frontend/rust-lib/lib-infra/src/file_util.rsindex 6de14b2304..b088256c26 100644--- a/frontend/rust-lib/lib-infra/src/file_util.rs+++ b/frontend/rust-lib/lib-infra/src/file_util.rs@@ -10,7 +10,7 @@ use zip::write::FileOptions;use zip::ZipWriter;use zip::{CompressionMethod, ZipArchive};-pub fn copy_dir_recursive(src: &Path, dst: &Path) -> io::Result<()> {+pub fn copy_dir_recursive(src: &Path, dst: &PathBuf) -> io::Result<()> {for entry in WalkDir::new(src).into_iter().filter_map(|e| e.ok()) {let path = entry.path();let relative_path = path.strip_prefix(src).unwrap();