chore: add custom folder prompt (#3961)

* chore: add custom folder prompt

* chore: zip collab db

* chore: fix test

* chore: add test

* chore: fmt

* chore: fmt

* chore: fmt
This commit is contained in:
Nathan.fooo
2023-11-20 20:54:47 +08:00
committed by GitHub
parent 6f83f41c2d
commit b9ecc7ceb6
67 changed files with 1423 additions and 551 deletions

View File

@ -1,63 +1,37 @@
use serde::Deserialize;
use serde_repr::Deserialize_repr;
use flowy_server_config::af_cloud_config::AFCloudConfiguration;
use flowy_server_config::supabase_config::SupabaseConfiguration;
use flowy_server_config::AuthenticatorType;
#[derive(Deserialize, Debug)]
pub struct AppFlowyEnv {
cloud_type: CloudType,
supabase_config: SupabaseConfiguration,
appflowy_cloud_config: AFCloudConfiguration,
pub struct AppFlowyDartConfiguration {
/// This path will be used to store the user data
pub custom_app_path: String,
pub origin_app_path: String,
pub device_id: String,
pub cloud_type: AuthenticatorType,
pub(crate) supabase_config: SupabaseConfiguration,
pub(crate) appflowy_cloud_config: AFCloudConfiguration,
}
const CLOUT_TYPE_STR: &str = "APPFLOWY_CLOUD_ENV_CLOUD_TYPE";
#[derive(Deserialize_repr, Debug, Clone)]
#[repr(u8)]
pub enum CloudType {
Local = 0,
Supabase = 1,
AppFlowyCloud = 2,
}
impl CloudType {
fn write_env(&self) {
let s = self.clone() as u8;
std::env::set_var(CLOUT_TYPE_STR, s.to_string());
impl AppFlowyDartConfiguration {
pub fn from_str(s: &str) -> Self {
serde_json::from_str::<AppFlowyDartConfiguration>(s).unwrap()
}
#[allow(dead_code)]
fn from_str(s: &str) -> Self {
match s {
"0" => CloudType::Local,
"1" => CloudType::Supabase,
"2" => CloudType::AppFlowyCloud,
_ => CloudType::Local,
}
}
#[allow(dead_code)]
pub fn from_env() -> Self {
let cloud_type_str = std::env::var(CLOUT_TYPE_STR).unwrap_or_default();
CloudType::from_str(&cloud_type_str)
}
}
impl AppFlowyEnv {
/// Parse the environment variable from the frontend application. The frontend will
/// pass the environment variable as a json string after launching.
pub fn write_env_from(env_str: &str) {
if let Ok(env) = serde_json::from_str::<AppFlowyEnv>(env_str) {
let _ = env.cloud_type.write_env();
let is_valid = env.appflowy_cloud_config.write_env().is_ok();
// Note on Configuration Priority:
// If both Supabase config and AppFlowy cloud config are provided in the '.env' file,
// the AppFlowy cloud config will be prioritized and the Supabase config ignored.
// Ensure only one of these configurations is active at any given time.
if !is_valid {
let _ = env.supabase_config.write_env();
}
let configuration = Self::from_str(env_str);
configuration.cloud_type.write_env();
let is_valid = configuration.appflowy_cloud_config.write_env().is_ok();
// Note on Configuration Priority:
// If both Supabase config and AppFlowy cloud config are provided in the '.env' file,
// the AppFlowy cloud config will be prioritized and the Supabase config ignored.
// Ensure only one of these configurations is active at any given time.
if !is_valid {
let _ = configuration.supabase_config.write_env();
}
}
}

View File

@ -13,7 +13,7 @@ use flowy_notification::{register_notification_sender, unregister_all_notificati
use lib_dispatch::prelude::ToBytes;
use lib_dispatch::prelude::*;
use crate::env_serde::AppFlowyEnv;
use crate::env_serde::AppFlowyDartConfiguration;
use crate::notification::DartNotificationSender;
use crate::{
c::{extend_front_four_bytes_into_bytes, forget_rust},
@ -49,13 +49,29 @@ unsafe impl Sync for MutexAppFlowyCore {}
unsafe impl Send for MutexAppFlowyCore {}
#[no_mangle]
pub extern "C" fn init_sdk(path: *mut c_char) -> i64 {
let c_str: &CStr = unsafe { CStr::from_ptr(path) };
let path: &str = c_str.to_str().unwrap();
pub extern "C" fn init_sdk(data: *mut c_char) -> i64 {
let c_str = unsafe { CStr::from_ptr(data) };
let serde_str = c_str.to_str().unwrap();
let configuration = AppFlowyDartConfiguration::from_str(serde_str);
configuration.cloud_type.write_env();
let is_valid = configuration.appflowy_cloud_config.write_env().is_ok();
// Note on Configuration Priority:
// If both Supabase config and AppFlowy cloud config are provided in the '.env' file,
// the AppFlowy cloud config will be prioritized and the Supabase config ignored.
// Ensure only one of these configurations is active at any given time.
if !is_valid {
let _ = configuration.supabase_config.write_env();
}
let log_crates = vec!["flowy-ffi".to_string()];
let config =
AppFlowyCoreConfig::new(path, DEFAULT_NAME.to_string()).log_filter("info", log_crates);
let config = AppFlowyCoreConfig::new(
configuration.custom_app_path,
configuration.origin_app_path,
configuration.device_id,
DEFAULT_NAME.to_string(),
)
.log_filter("info", log_crates);
*APPFLOWY_CORE.0.lock() = Some(AppFlowyCore::new(config));
0
}
@ -163,5 +179,5 @@ pub extern "C" fn backend_log(level: i64, data: *const c_char) {
pub extern "C" fn set_env(data: *const c_char) {
let c_str = unsafe { CStr::from_ptr(data) };
let serde_str = c_str.to_str().unwrap();
AppFlowyEnv::write_env_from(serde_str);
AppFlowyDartConfiguration::write_env_from(serde_str);
}