mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-11-01 18:43:22 +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:
|
||||
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'));
|
||||
|
||||
@ -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 = "$uid@appflowy.io";
|
||||
final userEmail = "anon@appflowy.io";
|
||||
|
||||
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();
|
||||
|
||||
4
frontend/rust-lib/Cargo.lock
generated
4
frontend/rust-lib/Cargo.lock
generated
@ -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",
|
||||
|
||||
@ -58,6 +58,7 @@ serde_repr.workspace = true
|
||||
uuid.workspace = true
|
||||
sysinfo = "0.30.5"
|
||||
semver = { version = "1.0.22", features = ["serde"] }
|
||||
url = "2.5.0"
|
||||
|
||||
[features]
|
||||
profiling = ["console-subscriber", "tokio/tracing"]
|
||||
|
||||
@ -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 path
|
||||
error!("Copy dir failed: {}", err);
|
||||
root.to_string()
|
||||
},
|
||||
}
|
||||
} else {
|
||||
storage_path
|
||||
.into_os_string()
|
||||
.into_string()
|
||||
.unwrap_or_else(|_| root.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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)]
|
||||
|
||||
@ -31,12 +31,9 @@ tracing.workspace = true
|
||||
bytes.workspace = true
|
||||
serde = { workspace = true, features = ["rc"] }
|
||||
serde_json.workspace = true
|
||||
serde_repr.workspace = true
|
||||
protobuf.workspace = true
|
||||
lazy_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"] }
|
||||
|
||||
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -403,7 +403,6 @@ impl UserManager {
|
||||
) -> Result<UserProfile, FlowyError> {
|
||||
// sign out the current user if there is one
|
||||
let 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?;
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user