JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Add support for networked GetSetting to Unified Stack refactor

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨da6d78e

Showing ⁨⁨6⁩ changed files⁩ with ⁨⁨64⁩ insertions⁩ and ⁨⁨8⁩ deletions⁩

README.md

View file
@@ -3,6 +3,8 @@
3 3 [![Roadmap](https://img.shields.io/badge/roadmap-ROADMAP.md-pink)](https://giterated.dev/ambee/giterated/blob/master/ROADMAP.md)
4 4 [![Chat with us](https://img.shields.io/badge/chat-matrix.org-green)](https://matrix.to/#/#giterated:matrix.org)
5 5
6
7
6 8 Giterated is a federated solution for hosting, collaboration, and discovery for Git repositories.
7 9
8 10 There are many benefits to self-hosting your Git repositories, and Giterated makes it easy to do that without sacrificing the ease of collaboration and discovery centralized Git platforms provide.

giterated-daemon/src/connection/wrapper.rs

View file
@@ -123,7 +123,7 @@ pub async fn connection_wrapper(
123 123 verified_instance
124 124 };
125 125
126 let _user = {
126 let user = {
127 127 let mut verified_user = None;
128 128 if let Some(verified_instance) = &instance {
129 129 for source in &message.source {
@@ -157,6 +157,9 @@ pub async fn connection_wrapper(
157 157 verified_user
158 158 };
159 159
160 operation_state.user = user;
161 operation_state.instance = instance;
162
160 163 let result = runtime
161 164 .handle_network_message(message, &operation_state)
162 165 .await;

giterated-daemon/src/main.rs

View file
@@ -20,7 +20,6 @@ use tokio::{
20 20 io::{AsyncRead, AsyncReadExt, AsyncWrite},
21 21 net::{TcpListener, TcpStream},
22 22 sync::Mutex,
23 task::LocalSet,
24 23 };
25 24 use tokio_tungstenite::{accept_async, WebSocketStream};
26 25 use tokio_util::task::LocalPoolHandle;

giterated-models/src/user/values.rs

View file
@@ -17,6 +17,12 @@ impl GiteratedObjectValue for Bio {
17 17 }
18 18 }
19 19
20 impl Display for Bio {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 f.write_str(&self.0)
23 }
24 }
25
20 26 #[derive(Debug, Hash, Clone, PartialEq, Eq, Serialize, Deserialize)]
21 27 pub struct DisplayName(pub String);
22 28

giterated-stack/src/handler.rs

View file
@@ -11,7 +11,7 @@ use giterated_models::{
11 11 },
12 12 object_backend::ObjectBackend,
13 13 operation::{AnyOperation, GiteratedOperation},
14 settings::{GetSetting, SetSetting, Setting},
14 settings::{GetSetting, GetSettingError, SetSetting, Setting},
15 15 value::{AnyValue, GetValue, GetValueTyped, GiteratedObjectValue},
16 16 };
17 17 use tracing::trace;
@@ -208,7 +208,7 @@ impl<S: GiteratedStackState + 'static> SubstackBuilder<S> {
208 208 ///
209 209 /// # Type Registration
210 210 /// This will register the provided setting type.
211 pub fn setting<T: Setting>(&mut self) -> &mut Self {
211 pub fn setting<T: Setting + 'static>(&mut self) -> &mut Self {
212 212 self.metadata.register_setting::<T>();
213 213
214 214 self
@@ -427,7 +427,7 @@ impl RuntimeMetadata {
427 427 }
428 428 }
429 429
430 fn register_setting<S: Setting>(&mut self) {
430 fn register_setting<S: Setting + 'static>(&mut self) {
431 431 let setting_name = S::name().to_string();
432 432
433 433 if self
@@ -437,6 +437,9 @@ impl RuntimeMetadata {
437 437 SettingMeta {
438 438 name: setting_name,
439 439 deserialize: Box::new(|bytes| Ok(Box::new(serde_json::from_slice(bytes)?))),
440 serialize: Box::new(|source| {
441 serde_json::to_value(source.downcast::<S>().unwrap())
442 }),
440 443 },
441 444 )
442 445 .is_some()
@@ -619,10 +622,50 @@ impl GiteratedStack {
619 622
620 623 pub async fn network_get_setting(
621 624 &self,
622 _operation: GetSetting,
623 _operation_state: &StackOperationState,
625 object: Box<dyn Any + Send + Sync>,
626 object_kind: String,
627 operation: GetSetting,
628 operation_state: &StackOperationState,
624 629 ) -> Result<Vec<u8>, OperationError<Vec<u8>>> {
625 todo!()
630 trace!(
631 "Handling network {}::get_setting for {}",
632 object_kind,
633 operation.setting_name
634 );
635
636 let setting_meta = self
637 .metadata
638 .settings
639 .get(&object_kind)
640 .ok_or_else(|| OperationError::Unhandled)?;
641
642 let setting_getter = self
643 .setting_getters
644 .get(&object_kind)
645 .ok_or_else(|| OperationError::Unhandled)?;
646
647 let raw_result = setting_getter
648 .handle(&object, &(Box::new(operation) as Box<_>), operation_state)
649 .await;
650
651 match raw_result {
652 Ok(setting) => {
653 // We need to serialize this to Value
654 let value = (setting_meta.serialize)(setting).unwrap();
655
656 Ok(serde_json::to_vec(&value).unwrap())
657 }
658 Err(err) => Err(match err {
659 OperationError::Operation(failure) => {
660 // This will get GetSettingError
661 let error: GetSettingError = *failure.downcast().unwrap();
662
663 OperationError::Operation(serde_json::to_vec(&error).unwrap())
664 }
665 OperationError::Internal(internal) => OperationError::Internal(internal),
666 OperationError::Unhandled => OperationError::Unhandled,
667 }),
668 }
626 669 }
627 670
628 671 pub async fn network_set_setting(

giterated-stack/src/lib.rs

View file
@@ -1,5 +1,6 @@
1 1 mod handler;
2 2 pub use handler::{GiteratedStack, GiteratedStackState, *};
3 use serde_json::Value;
3 4
4 5 pub mod state;
5 6 pub mod update;
@@ -32,6 +33,8 @@ struct ObjectOperationPair {
32 33 pub struct SettingMeta {
33 34 pub name: String,
34 35 pub deserialize: Box<dyn Fn(&[u8]) -> Result<Box<dyn Any>, serde_json::Error> + Send + Sync>,
36 pub serialize:
37 Box<dyn Fn(Box<dyn Any + Send + Sync>) -> Result<Value, serde_json::Error> + Send + Sync>,
35 38 }
36 39
37 40 pub struct ValueMeta {