mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: integrate postgres storage (#2604)
* chore: env config * chore: get user workspace * feat: enable postgres storage * chore: add new env * chore: add set env ffi * chore: pass env before backend init * chore: update * fix: ci tests * chore: commit the generate env file * chore: remove unused import
This commit is contained in:
@ -1,57 +1,62 @@
|
||||
use nanoid::nanoid;
|
||||
use parking_lot::RwLock;
|
||||
use std::env::temp_dir;
|
||||
use std::sync::Arc;
|
||||
|
||||
use flowy_core::{AppFlowyCore, AppFlowyCoreConfig};
|
||||
use flowy_user::entities::UserProfilePB;
|
||||
|
||||
use crate::helper::*;
|
||||
use flowy_user::entities::{AuthTypePB, UserProfilePB};
|
||||
|
||||
use crate::user_event::{async_sign_up, init_user_setting, SignUpContext};
|
||||
pub mod event_builder;
|
||||
pub mod helper;
|
||||
|
||||
pub mod prelude {
|
||||
pub use lib_dispatch::prelude::*;
|
||||
|
||||
pub use crate::{event_builder::*, helper::*, *};
|
||||
}
|
||||
pub mod folder_event;
|
||||
pub mod user_event;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct FlowySDKTest {
|
||||
pub inner: AppFlowyCore,
|
||||
pub struct FlowyCoreTest {
|
||||
auth_type: Arc<RwLock<AuthTypePB>>,
|
||||
inner: AppFlowyCore,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for FlowySDKTest {
|
||||
impl Default for FlowyCoreTest {
|
||||
fn default() -> Self {
|
||||
let temp_dir = temp_dir();
|
||||
let config =
|
||||
AppFlowyCoreConfig::new(temp_dir.to_str().unwrap(), nanoid!(6)).log_filter("info", vec![]);
|
||||
let inner = std::thread::spawn(|| AppFlowyCore::new(config))
|
||||
.join()
|
||||
.unwrap();
|
||||
let auth_type = Arc::new(RwLock::new(AuthTypePB::Local));
|
||||
std::mem::forget(inner.dispatcher());
|
||||
Self { inner, auth_type }
|
||||
}
|
||||
}
|
||||
|
||||
impl FlowyCoreTest {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub async fn sign_up(&self) -> SignUpContext {
|
||||
let auth_type = self.auth_type.read().clone();
|
||||
async_sign_up(self.inner.dispatcher(), auth_type).await
|
||||
}
|
||||
|
||||
pub fn set_auth_type(&self, auth_type: AuthTypePB) {
|
||||
*self.auth_type.write() = auth_type;
|
||||
}
|
||||
|
||||
pub async fn init_user(&self) -> UserProfilePB {
|
||||
let auth_type = self.auth_type.read().clone();
|
||||
let context = async_sign_up(self.inner.dispatcher(), auth_type).await;
|
||||
init_user_setting(self.inner.dispatcher()).await;
|
||||
context.user_profile
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Deref for FlowyCoreTest {
|
||||
type Target = AppFlowyCore;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl std::default::Default for FlowySDKTest {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl FlowySDKTest {
|
||||
pub fn new() -> Self {
|
||||
let config =
|
||||
AppFlowyCoreConfig::new(temp_dir().to_str().unwrap(), nanoid!(6)).log_filter("info", vec![]);
|
||||
let sdk = std::thread::spawn(|| AppFlowyCore::new(config))
|
||||
.join()
|
||||
.unwrap();
|
||||
std::mem::forget(sdk.dispatcher());
|
||||
Self { inner: sdk }
|
||||
}
|
||||
|
||||
pub async fn sign_up(&self) -> SignUpContext {
|
||||
async_sign_up(self.inner.dispatcher()).await
|
||||
}
|
||||
|
||||
pub async fn init_user(&self) -> UserProfilePB {
|
||||
let context = async_sign_up(self.inner.dispatcher()).await;
|
||||
init_user_setting(self.inner.dispatcher()).await;
|
||||
context.user_profile
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user