mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-11-13 17:07:40 +00:00
chore: rename data path
This commit is contained in:
parent
d79929d1c9
commit
efb98d28ef
@ -73,10 +73,10 @@ Future<Directory> appFlowyApplicationDataDirectory() async {
|
|||||||
case IntegrationMode.develop:
|
case IntegrationMode.develop:
|
||||||
final Directory documentsDir = await getApplicationSupportDirectory()
|
final Directory documentsDir = await getApplicationSupportDirectory()
|
||||||
.then((directory) => directory.create());
|
.then((directory) => directory.create());
|
||||||
return Directory(path.join(documentsDir.path, 'data_dev')).create();
|
return Directory(path.join(documentsDir.path, 'data_dev'));
|
||||||
case IntegrationMode.release:
|
case IntegrationMode.release:
|
||||||
final Directory documentsDir = await getApplicationSupportDirectory();
|
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.unitTest:
|
||||||
case IntegrationMode.integrationTest:
|
case IntegrationMode.integrationTest:
|
||||||
return Directory(path.join(Directory.current.path, '.sandbox'));
|
return Directory(path.join(Directory.current.path, '.sandbox'));
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
|
|||||||
show SignInPayloadPB, SignUpPayloadPB, UserProfilePB;
|
show SignInPayloadPB, SignUpPayloadPB, UserProfilePB;
|
||||||
import 'package:appflowy_result/appflowy_result.dart';
|
import 'package:appflowy_result/appflowy_result.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flowy_infra/uuid.dart';
|
|
||||||
|
|
||||||
import '../../../generated/locale_keys.g.dart';
|
import '../../../generated/locale_keys.g.dart';
|
||||||
import 'device_id.dart';
|
import 'device_id.dart';
|
||||||
@ -65,13 +64,13 @@ class BackendAuthService implements AuthService {
|
|||||||
Map<String, String> params = const {},
|
Map<String, String> params = const {},
|
||||||
}) async {
|
}) async {
|
||||||
const password = "Guest!@123456";
|
const password = "Guest!@123456";
|
||||||
final uid = uuid();
|
final userEmail = "anon@appflowy.io";
|
||||||
final userEmail = "$uid@appflowy.io";
|
|
||||||
|
|
||||||
final request = SignUpPayloadPB.create()
|
final request = SignUpPayloadPB.create()
|
||||||
..name = LocaleKeys.defaultUsername.tr()
|
..name = LocaleKeys.defaultUsername.tr()
|
||||||
..email = userEmail
|
..email = userEmail
|
||||||
..password = password
|
..password = password
|
||||||
|
..isAnon = true
|
||||||
// When sign up as guest, the auth type is always local.
|
// When sign up as guest, the auth type is always local.
|
||||||
..authType = AuthenticatorPB.Local
|
..authType = AuthenticatorPB.Local
|
||||||
..deviceId = await getDeviceId();
|
..deviceId = await getDeviceId();
|
||||||
|
|||||||
4
frontend/rust-lib/Cargo.lock
generated
4
frontend/rust-lib/Cargo.lock
generated
@ -2604,6 +2604,7 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"url",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -3049,7 +3050,6 @@ dependencies = [
|
|||||||
"collab-user",
|
"collab-user",
|
||||||
"dashmap 6.0.1",
|
"dashmap 6.0.1",
|
||||||
"diesel",
|
"diesel",
|
||||||
"diesel_derives",
|
|
||||||
"fake",
|
"fake",
|
||||||
"fancy-regex 0.11.0",
|
"fancy-regex 0.11.0",
|
||||||
"flowy-codegen",
|
"flowy-codegen",
|
||||||
@ -3064,7 +3064,6 @@ dependencies = [
|
|||||||
"lib-dispatch",
|
"lib-dispatch",
|
||||||
"lib-infra",
|
"lib-infra",
|
||||||
"nanoid",
|
"nanoid",
|
||||||
"once_cell",
|
|
||||||
"protobuf",
|
"protobuf",
|
||||||
"quickcheck",
|
"quickcheck",
|
||||||
"quickcheck_macros",
|
"quickcheck_macros",
|
||||||
@ -3074,7 +3073,6 @@ dependencies = [
|
|||||||
"semver",
|
"semver",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_repr",
|
|
||||||
"strum",
|
"strum",
|
||||||
"strum_macros 0.25.2",
|
"strum_macros 0.25.2",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|||||||
@ -58,6 +58,7 @@ serde_repr.workspace = true
|
|||||||
uuid.workspace = true
|
uuid.workspace = true
|
||||||
sysinfo = "0.30.5"
|
sysinfo = "0.30.5"
|
||||||
semver = { version = "1.0.22", features = ["serde"] }
|
semver = { version = "1.0.22", features = ["serde"] }
|
||||||
|
url = "2.5.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
profiling = ["console-subscriber", "tokio/tracing"]
|
profiling = ["console-subscriber", "tokio/tracing"]
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
use crate::log_filter::create_log_filter;
|
use crate::log_filter::create_log_filter;
|
||||||
use flowy_server_pub::af_cloud_config::AFCloudConfiguration;
|
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 {
|
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
|
// If a URL is provided, try to parse it and extract the domain name.
|
||||||
// the user data folder being shared by different AppFlowy cloud.
|
// This isolates the user data folder by the domain, which prevents data sharing
|
||||||
let storage_path = if !url.is_empty() {
|
// between different AppFlowy cloud instances.
|
||||||
let server_base64 = URL_SAFE_ENGINE.encode(url);
|
print!("Creating user data folder for URL: {}, root:{}", url, root);
|
||||||
format!("{}_{}", root, server_base64)
|
let mut storage_path = if url.is_empty() {
|
||||||
|
PathBuf::from(root)
|
||||||
} else {
|
} 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
|
// 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
|
// The root path without any suffix is the created by the local version AppFlowy
|
||||||
if !Path::new(&storage_path).exists() && Path::new(root).exists() {
|
if !storage_path.exists() && Path::new(root).exists() {
|
||||||
info!("Copy dir from {} to {}", root, storage_path);
|
info!("Copy dir from {} to {:?}", root, storage_path);
|
||||||
let src = Path::new(root);
|
let src = Path::new(root);
|
||||||
match copy_dir_recursive(src, Path::new(&storage_path)) {
|
match copy_dir_recursive(src, &storage_path) {
|
||||||
Ok(_) => storage_path,
|
Ok(_) => storage_path
|
||||||
|
.into_os_string()
|
||||||
|
.into_string()
|
||||||
|
.unwrap_or_else(|_| root.to_string()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// when the copy dir failed, use the root path as the storage path
|
|
||||||
error!("Copy dir failed: {}", err);
|
error!("Copy dir failed: {}", err);
|
||||||
root.to_string()
|
root.to_string()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
storage_path
|
storage_path
|
||||||
|
.into_os_string()
|
||||||
|
.into_string()
|
||||||
|
.unwrap_or_else(|_| root.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -42,6 +42,7 @@ pub struct SignUpParams {
|
|||||||
pub password: String,
|
pub password: String,
|
||||||
pub auth_type: Authenticator,
|
pub auth_type: Authenticator,
|
||||||
pub device_id: String,
|
pub device_id: String,
|
||||||
|
pub is_anon: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
|||||||
@ -31,12 +31,9 @@ tracing.workspace = true
|
|||||||
bytes.workspace = true
|
bytes.workspace = true
|
||||||
serde = { workspace = true, features = ["rc"] }
|
serde = { workspace = true, features = ["rc"] }
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
serde_repr.workspace = true
|
|
||||||
protobuf.workspace = true
|
protobuf.workspace = true
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
diesel.workspace = true
|
diesel.workspace = true
|
||||||
diesel_derives = { version = "2.1.0", features = ["sqlite", "r2d2"] }
|
|
||||||
once_cell = "1.17.1"
|
|
||||||
strum = "0.25"
|
strum = "0.25"
|
||||||
strum_macros = "0.25.2"
|
strum_macros = "0.25.2"
|
||||||
tokio = { workspace = true, features = ["rt"] }
|
tokio = { workspace = true, features = ["rt"] }
|
||||||
|
|||||||
@ -57,6 +57,9 @@ pub struct SignUpPayloadPB {
|
|||||||
|
|
||||||
#[pb(index = 5)]
|
#[pb(index = 5)]
|
||||||
pub device_id: String,
|
pub device_id: String,
|
||||||
|
|
||||||
|
#[pb(index = 6)]
|
||||||
|
pub is_anon: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<SignUpParams> for SignUpPayloadPB {
|
impl TryInto<SignUpParams> for SignUpPayloadPB {
|
||||||
@ -73,6 +76,7 @@ impl TryInto<SignUpParams> for SignUpPayloadPB {
|
|||||||
password: password.0,
|
password: password.0,
|
||||||
auth_type: self.auth_type.into(),
|
auth_type: self.auth_type.into(),
|
||||||
device_id: self.device_id,
|
device_id: self.device_id,
|
||||||
|
is_anon: self.is_anon,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,14 +76,14 @@ pub async fn sign_up(
|
|||||||
let params: SignUpParams = data.into_inner().try_into()?;
|
let params: SignUpParams = data.into_inner().try_into()?;
|
||||||
let authenticator = params.auth_type.clone();
|
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 {
|
match manager.sign_up(authenticator, BoxAny::new(params)).await {
|
||||||
Ok(profile) => data_result_ok(UserProfilePB::from(profile)),
|
Ok(profile) => data_result_ok(UserProfilePB::from(profile)),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
manager
|
manager
|
||||||
.cloud_services
|
.cloud_services
|
||||||
.set_user_authenticator(&old_authenticator);
|
.set_user_authenticator(&prev_authenticator);
|
||||||
return Err(err);
|
Err(err)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -403,7 +403,6 @@ impl UserManager {
|
|||||||
) -> Result<UserProfile, FlowyError> {
|
) -> Result<UserProfile, FlowyError> {
|
||||||
// sign out the current user if there is one
|
// sign out the current user if there is one
|
||||||
let migration_user = self.get_migration_user(&authenticator).await;
|
let migration_user = self.get_migration_user(&authenticator).await;
|
||||||
|
|
||||||
self.cloud_services.set_user_authenticator(&authenticator);
|
self.cloud_services.set_user_authenticator(&authenticator);
|
||||||
let auth_service = self.cloud_services.get_user_service()?;
|
let auth_service = self.cloud_services.get_user_service()?;
|
||||||
let response: AuthResponse = auth_service.sign_up(params).await?;
|
let response: AuthResponse = auth_service.sign_up(params).await?;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use zip::write::FileOptions;
|
|||||||
use zip::ZipWriter;
|
use zip::ZipWriter;
|
||||||
use zip::{CompressionMethod, ZipArchive};
|
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()) {
|
for entry in WalkDir::new(src).into_iter().filter_map(|e| e.ok()) {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
let relative_path = path.strip_prefix(src).unwrap();
|
let relative_path = path.strip_prefix(src).unwrap();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user