mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: deps crates (#4362)
* refactor: rename flowy-folder-deps to flowy-folder-pub * chore: rename crates * chore: move flowy-task to lib-infra * chore: rename crates * refactor: user manager dir
This commit is contained in:
11
frontend/rust-lib/flowy-server-pub/Cargo.toml
Normal file
11
frontend/rust-lib/flowy-server-pub/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "flowy-server-pub"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
flowy-error = { workspace = true }
|
||||
serde.workspace = true
|
||||
serde_repr.workspace = true
|
69
frontend/rust-lib/flowy-server-pub/src/af_cloud_config.rs
Normal file
69
frontend/rust-lib/flowy-server-pub/src/af_cloud_config.rs
Normal file
@ -0,0 +1,69 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use flowy_error::{ErrorCode, FlowyError};
|
||||
|
||||
pub const APPFLOWY_CLOUD_BASE_URL: &str = "APPFLOWY_CLOUD_ENV_APPFLOWY_CLOUD_BASE_URL";
|
||||
pub const APPFLOWY_CLOUD_WS_BASE_URL: &str = "APPFLOWY_CLOUD_ENV_APPFLOWY_CLOUD_WS_BASE_URL";
|
||||
pub const APPFLOWY_CLOUD_GOTRUE_URL: &str = "APPFLOWY_CLOUD_ENV_APPFLOWY_CLOUD_GOTRUE_URL";
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct AFCloudConfiguration {
|
||||
pub base_url: String,
|
||||
pub ws_base_url: String,
|
||||
pub gotrue_url: String,
|
||||
}
|
||||
|
||||
impl Display for AFCloudConfiguration {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!(
|
||||
"base_url: {}, ws_base_url: {}, gotrue_url: {}",
|
||||
self.base_url, self.ws_base_url, self.gotrue_url,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl AFCloudConfiguration {
|
||||
pub fn from_env() -> Result<Self, FlowyError> {
|
||||
let base_url = std::env::var(APPFLOWY_CLOUD_BASE_URL).map_err(|_| {
|
||||
FlowyError::new(
|
||||
ErrorCode::InvalidAuthConfig,
|
||||
"Missing APPFLOWY_CLOUD_BASE_URL",
|
||||
)
|
||||
})?;
|
||||
|
||||
let ws_base_url = std::env::var(APPFLOWY_CLOUD_WS_BASE_URL).map_err(|_| {
|
||||
FlowyError::new(
|
||||
ErrorCode::InvalidAuthConfig,
|
||||
"Missing APPFLOWY_CLOUD_WS_BASE_URL",
|
||||
)
|
||||
})?;
|
||||
|
||||
let gotrue_url = std::env::var(APPFLOWY_CLOUD_GOTRUE_URL)
|
||||
.map_err(|_| FlowyError::new(ErrorCode::InvalidAuthConfig, "Missing AF_CLOUD_GOTRUE_URL"))?;
|
||||
|
||||
if base_url.is_empty() || ws_base_url.is_empty() || gotrue_url.is_empty() {
|
||||
return Err(FlowyError::new(
|
||||
ErrorCode::InvalidAuthConfig,
|
||||
format!(
|
||||
"Invalid APPFLOWY_CLOUD_BASE_URL: {}, APPFLOWY_CLOUD_WS_BASE_URL: {}, APPFLOWY_CLOUD_GOTRUE_URL: {}",
|
||||
base_url, ws_base_url, gotrue_url,
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
base_url,
|
||||
ws_base_url,
|
||||
gotrue_url,
|
||||
})
|
||||
}
|
||||
|
||||
/// Write the configuration to the environment variables.
|
||||
pub fn write_env(&self) {
|
||||
std::env::set_var(APPFLOWY_CLOUD_BASE_URL, &self.base_url);
|
||||
std::env::set_var(APPFLOWY_CLOUD_WS_BASE_URL, &self.ws_base_url);
|
||||
std::env::set_var(APPFLOWY_CLOUD_GOTRUE_URL, &self.gotrue_url);
|
||||
}
|
||||
}
|
37
frontend/rust-lib/flowy-server-pub/src/lib.rs
Normal file
37
frontend/rust-lib/flowy-server-pub/src/lib.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use serde_repr::Deserialize_repr;
|
||||
|
||||
pub mod af_cloud_config;
|
||||
pub mod supabase_config;
|
||||
|
||||
pub const CLOUT_TYPE_STR: &str = "APPFLOWY_CLOUD_ENV_CLOUD_TYPE";
|
||||
|
||||
#[derive(Deserialize_repr, Debug, Clone, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
pub enum AuthenticatorType {
|
||||
Local = 0,
|
||||
Supabase = 1,
|
||||
AppFlowyCloud = 2,
|
||||
}
|
||||
|
||||
impl AuthenticatorType {
|
||||
pub 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" => AuthenticatorType::Local,
|
||||
"1" => AuthenticatorType::Supabase,
|
||||
"2" => AuthenticatorType::AppFlowyCloud,
|
||||
_ => AuthenticatorType::Local,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn from_env() -> Self {
|
||||
let cloud_type_str = std::env::var(CLOUT_TYPE_STR).unwrap_or_default();
|
||||
AuthenticatorType::from_str(&cloud_type_str)
|
||||
}
|
||||
}
|
41
frontend/rust-lib/flowy-server-pub/src/supabase_config.rs
Normal file
41
frontend/rust-lib/flowy-server-pub/src/supabase_config.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use flowy_error::{ErrorCode, FlowyError};
|
||||
|
||||
pub const SUPABASE_URL: &str = "APPFLOWY_CLOUD_ENV_SUPABASE_URL";
|
||||
pub const SUPABASE_ANON_KEY: &str = "APPFLOWY_CLOUD_ENV_SUPABASE_ANON_KEY";
|
||||
|
||||
/// The configuration for the postgres database. It supports deserializing from the json string that
|
||||
/// passed from the frontend application. [AppFlowyEnv::parser]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct SupabaseConfiguration {
|
||||
/// The url of the supabase server.
|
||||
pub url: String,
|
||||
/// The key of the supabase server.
|
||||
pub anon_key: String,
|
||||
}
|
||||
|
||||
impl SupabaseConfiguration {
|
||||
pub fn from_env() -> Result<Self, FlowyError> {
|
||||
let url = std::env::var(SUPABASE_URL)
|
||||
.map_err(|_| FlowyError::new(ErrorCode::InvalidAuthConfig, "Missing SUPABASE_URL"))?;
|
||||
|
||||
let anon_key = std::env::var(SUPABASE_ANON_KEY)
|
||||
.map_err(|_| FlowyError::new(ErrorCode::InvalidAuthConfig, "Missing SUPABASE_ANON_KEY"))?;
|
||||
|
||||
if url.is_empty() || anon_key.is_empty() {
|
||||
return Err(FlowyError::new(
|
||||
ErrorCode::InvalidAuthConfig,
|
||||
"Missing SUPABASE_URL or SUPABASE_ANON_KEY",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(Self { url, anon_key })
|
||||
}
|
||||
|
||||
/// Write the configuration to the environment variables.
|
||||
pub fn write_env(&self) {
|
||||
std::env::set_var(SUPABASE_URL, &self.url);
|
||||
std::env::set_var(SUPABASE_ANON_KEY, &self.anon_key);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user