mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: config (#2552)
* feat: save project config * feat: implement dart key value store
This commit is contained in:
23
frontend/rust-lib/flowy-config/Cargo.toml
Normal file
23
frontend/rust-lib/flowy-config/Cargo.toml
Normal file
@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "flowy-config"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
flowy-sqlite = { path = "../flowy-sqlite" }
|
||||
flowy-derive = { path = "../../../shared-lib/flowy-derive" }
|
||||
lib-dispatch = { path = "../lib-dispatch" }
|
||||
protobuf = {version = "2.28.0"}
|
||||
bytes = { version = "1.4" }
|
||||
flowy-error = { path = "../flowy-error" }
|
||||
strum_macros = "0.21"
|
||||
appflowy-integrate = {version = "0.1.0" }
|
||||
|
||||
[build-dependencies]
|
||||
flowy-codegen = { path = "../../../shared-lib/flowy-codegen"}
|
||||
|
||||
[features]
|
||||
dart = ["flowy-codegen/dart"]
|
||||
ts = ["flowy-codegen/ts"]
|
3
frontend/rust-lib/flowy-config/Flowy.toml
Normal file
3
frontend/rust-lib/flowy-config/Flowy.toml
Normal file
@ -0,0 +1,3 @@
|
||||
# Check out the FlowyConfig (located in flowy_toml.rs) for more details.
|
||||
proto_input = ["src/event_map.rs", "src/entities.rs"]
|
||||
event_files = ["src/event_map.rs"]
|
10
frontend/rust-lib/flowy-config/build.rs
Normal file
10
frontend/rust-lib/flowy-config/build.rs
Normal file
@ -0,0 +1,10 @@
|
||||
fn main() {
|
||||
let crate_name = env!("CARGO_PKG_NAME");
|
||||
flowy_codegen::protobuf_file::gen(crate_name);
|
||||
|
||||
#[cfg(feature = "dart")]
|
||||
flowy_codegen::dart_event::gen(crate_name);
|
||||
|
||||
#[cfg(feature = "ts")]
|
||||
flowy_codegen::ts_event::gen(crate_name);
|
||||
}
|
45
frontend/rust-lib/flowy-config/src/entities.rs
Normal file
45
frontend/rust-lib/flowy-config/src/entities.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use flowy_derive::ProtoBuf;
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct KeyValuePB {
|
||||
#[pb(index = 1)]
|
||||
pub key: String,
|
||||
|
||||
#[pb(index = 2, one_of)]
|
||||
pub value: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct KeyPB {
|
||||
#[pb(index = 1)]
|
||||
pub key: String,
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct SupabaseConfigPB {
|
||||
#[pb(index = 1)]
|
||||
supabase_url: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
supabase_key: String,
|
||||
|
||||
#[pb(index = 3)]
|
||||
jwt_secret: String,
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct AppFlowyCollabConfigPB {
|
||||
#[pb(index = 1, one_of)]
|
||||
aws_config: Option<AWSDynamoDBConfigPB>,
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct AWSDynamoDBConfigPB {
|
||||
#[pb(index = 1)]
|
||||
pub access_key_id: String,
|
||||
#[pb(index = 2)]
|
||||
pub secret_access_key: String,
|
||||
// Region list: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html
|
||||
#[pb(index = 3)]
|
||||
pub region: String,
|
||||
}
|
40
frontend/rust-lib/flowy-config/src/event_handler.rs
Normal file
40
frontend/rust-lib/flowy-config/src/event_handler.rs
Normal file
@ -0,0 +1,40 @@
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_sqlite::kv::KV;
|
||||
use lib_dispatch::prelude::{data_result_ok, AFPluginData, DataResult};
|
||||
|
||||
use crate::entities::{KeyPB, KeyValuePB, SupabaseConfigPB};
|
||||
|
||||
pub(crate) async fn set_key_value_handler(data: AFPluginData<KeyValuePB>) -> FlowyResult<()> {
|
||||
let data = data.into_inner();
|
||||
match data.value {
|
||||
None => KV::remove(&data.key),
|
||||
Some(value) => {
|
||||
KV::set_str(&data.key, value);
|
||||
},
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn get_key_value_handler(
|
||||
data: AFPluginData<KeyPB>,
|
||||
) -> DataResult<KeyValuePB, FlowyError> {
|
||||
let data = data.into_inner();
|
||||
let value = KV::get_str(&data.key);
|
||||
data_result_ok(KeyValuePB {
|
||||
key: data.key,
|
||||
value,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) async fn remove_key_value_handler(data: AFPluginData<KeyPB>) -> FlowyResult<()> {
|
||||
let data = data.into_inner();
|
||||
KV::remove(&data.key);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn set_supabase_config_handler(
|
||||
data: AFPluginData<SupabaseConfigPB>,
|
||||
) -> FlowyResult<()> {
|
||||
let _config = data.into_inner();
|
||||
Ok(())
|
||||
}
|
31
frontend/rust-lib/flowy-config/src/event_map.rs
Normal file
31
frontend/rust-lib/flowy-config/src/event_map.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use strum_macros::Display;
|
||||
|
||||
use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
|
||||
use lib_dispatch::prelude::AFPlugin;
|
||||
|
||||
use crate::event_handler::*;
|
||||
|
||||
pub fn init() -> AFPlugin {
|
||||
AFPlugin::new()
|
||||
.name(env!("CARGO_PKG_NAME"))
|
||||
.event(ConfigEvent::SetKeyValue, set_key_value_handler)
|
||||
.event(ConfigEvent::GetKeyValue, get_key_value_handler)
|
||||
.event(ConfigEvent::RemoveKeyValue, remove_key_value_handler)
|
||||
.event(ConfigEvent::SetSupabaseConfig, set_supabase_config_handler)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Display, ProtoBuf_Enum, Flowy_Event)]
|
||||
#[event_err = "FlowyError"]
|
||||
pub enum ConfigEvent {
|
||||
#[event(input = "KeyValuePB")]
|
||||
SetKeyValue = 0,
|
||||
|
||||
#[event(input = "KeyPB", output = "KeyValuePB")]
|
||||
GetKeyValue = 1,
|
||||
|
||||
#[event(input = "KeyPB")]
|
||||
RemoveKeyValue = 2,
|
||||
|
||||
#[event(input = "SupabaseConfigPB")]
|
||||
SetSupabaseConfig = 3,
|
||||
}
|
4
frontend/rust-lib/flowy-config/src/lib.rs
Normal file
4
frontend/rust-lib/flowy-config/src/lib.rs
Normal file
@ -0,0 +1,4 @@
|
||||
mod entities;
|
||||
mod event_handler;
|
||||
pub mod event_map;
|
||||
mod protobuf;
|
Reference in New Issue
Block a user