feat: show server url (#3956)

* chore: data folder for cloud

* chore: display server url

* chore: fix test
This commit is contained in:
Nathan.fooo
2023-11-17 15:38:56 +08:00
committed by GitHub
parent 4a1a143a66
commit 8179419f8b
42 changed files with 425 additions and 313 deletions

View File

@ -17,6 +17,7 @@ byteorder = { version = "1.4.3" }
protobuf.workspace = true
tokio = { workspace = true, features = ["full", "rt-multi-thread", "tracing"] }
serde.workspace = true
serde_repr.workspace = true
serde_json.workspace = true
bytes.workspace = true
crossbeam-utils = "0.8.15"

View File

@ -1,21 +1,63 @@
use serde::Deserialize;
use serde_repr::Deserialize_repr;
use flowy_server_config::af_cloud_config::AFCloudConfiguration;
use flowy_server_config::supabase_config::SupabaseConfiguration;
#[derive(Deserialize, Debug)]
pub struct AppFlowyEnv {
cloud_type: CloudType,
supabase_config: SupabaseConfiguration,
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());
}
#[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) {
env.supabase_config.write_env();
env.appflowy_cloud_config.write_env();
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();
}
}
}
}

View File

@ -7,6 +7,7 @@ use lazy_static::lazy_static;
use parking_lot::Mutex;
use tracing::{error, trace};
use flowy_core::config::AppFlowyCoreConfig;
use flowy_core::*;
use flowy_notification::{register_notification_sender, unregister_all_notification_sender};
use lib_dispatch::prelude::ToBytes;