diff --git a/README.md b/README.md index 363dcad..be71bf8 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ [![Roadmap](https://img.shields.io/badge/roadmap-ROADMAP.md-pink)](https://giterated.dev/ambee/giterated/blob/master/ROADMAP.md) [![Chat with us](https://img.shields.io/badge/chat-matrix.org-green)](https://matrix.to/#/#giterated:matrix.org) + + Giterated is a federated solution for hosting, collaboration, and discovery for Git repositories. 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. diff --git a/giterated-daemon/src/connection/wrapper.rs b/giterated-daemon/src/connection/wrapper.rs index f0402f3..c55fdc7 100644 --- a/giterated-daemon/src/connection/wrapper.rs +++ b/giterated-daemon/src/connection/wrapper.rs @@ -123,7 +123,7 @@ pub async fn connection_wrapper( verified_instance }; - let _user = { + let user = { let mut verified_user = None; if let Some(verified_instance) = &instance { for source in &message.source { @@ -157,6 +157,9 @@ pub async fn connection_wrapper( verified_user }; + operation_state.user = user; + operation_state.instance = instance; + let result = runtime .handle_network_message(message, &operation_state) .await; diff --git a/giterated-daemon/src/main.rs b/giterated-daemon/src/main.rs index 29eb3a5..bfebbaf 100644 --- a/giterated-daemon/src/main.rs +++ b/giterated-daemon/src/main.rs @@ -20,7 +20,6 @@ use tokio::{ io::{AsyncRead, AsyncReadExt, AsyncWrite}, net::{TcpListener, TcpStream}, sync::Mutex, - task::LocalSet, }; use tokio_tungstenite::{accept_async, WebSocketStream}; use tokio_util::task::LocalPoolHandle; diff --git a/giterated-models/src/user/values.rs b/giterated-models/src/user/values.rs index 7e47342..291860e 100644 --- a/giterated-models/src/user/values.rs +++ b/giterated-models/src/user/values.rs @@ -17,6 +17,12 @@ impl GiteratedObjectValue for Bio { } } +impl Display for Bio { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(&self.0) + } +} + #[derive(Debug, Hash, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct DisplayName(pub String); diff --git a/giterated-stack/src/handler.rs b/giterated-stack/src/handler.rs index 30d84cb..4bc0520 100644 --- a/giterated-stack/src/handler.rs +++ b/giterated-stack/src/handler.rs @@ -11,7 +11,7 @@ use giterated_models::{ }, object_backend::ObjectBackend, operation::{AnyOperation, GiteratedOperation}, - settings::{GetSetting, SetSetting, Setting}, + settings::{GetSetting, GetSettingError, SetSetting, Setting}, value::{AnyValue, GetValue, GetValueTyped, GiteratedObjectValue}, }; use tracing::trace; @@ -208,7 +208,7 @@ impl SubstackBuilder { /// /// # Type Registration /// This will register the provided setting type. - pub fn setting(&mut self) -> &mut Self { + pub fn setting(&mut self) -> &mut Self { self.metadata.register_setting::(); self @@ -427,7 +427,7 @@ impl RuntimeMetadata { } } - fn register_setting(&mut self) { + fn register_setting(&mut self) { let setting_name = S::name().to_string(); if self @@ -437,6 +437,9 @@ impl RuntimeMetadata { SettingMeta { name: setting_name, deserialize: Box::new(|bytes| Ok(Box::new(serde_json::from_slice(bytes)?))), + serialize: Box::new(|source| { + serde_json::to_value(source.downcast::().unwrap()) + }), }, ) .is_some() @@ -619,10 +622,50 @@ impl GiteratedStack { pub async fn network_get_setting( &self, - _operation: GetSetting, - _operation_state: &StackOperationState, + object: Box, + object_kind: String, + operation: GetSetting, + operation_state: &StackOperationState, ) -> Result, OperationError>> { - todo!() + trace!( + "Handling network {}::get_setting for {}", + object_kind, + operation.setting_name + ); + + let setting_meta = self + .metadata + .settings + .get(&object_kind) + .ok_or_else(|| OperationError::Unhandled)?; + + let setting_getter = self + .setting_getters + .get(&object_kind) + .ok_or_else(|| OperationError::Unhandled)?; + + let raw_result = setting_getter + .handle(&object, &(Box::new(operation) as Box<_>), operation_state) + .await; + + match raw_result { + Ok(setting) => { + // We need to serialize this to Value + let value = (setting_meta.serialize)(setting).unwrap(); + + Ok(serde_json::to_vec(&value).unwrap()) + } + Err(err) => Err(match err { + OperationError::Operation(failure) => { + // This will get GetSettingError + let error: GetSettingError = *failure.downcast().unwrap(); + + OperationError::Operation(serde_json::to_vec(&error).unwrap()) + } + OperationError::Internal(internal) => OperationError::Internal(internal), + OperationError::Unhandled => OperationError::Unhandled, + }), + } } pub async fn network_set_setting( diff --git a/giterated-stack/src/lib.rs b/giterated-stack/src/lib.rs index 0602016..9240e93 100644 --- a/giterated-stack/src/lib.rs +++ b/giterated-stack/src/lib.rs @@ -1,5 +1,6 @@ mod handler; pub use handler::{GiteratedStack, GiteratedStackState, *}; +use serde_json::Value; pub mod state; pub mod update; @@ -32,6 +33,8 @@ struct ObjectOperationPair { pub struct SettingMeta { pub name: String, pub deserialize: Box Result, serde_json::Error> + Send + Sync>, + pub serialize: + Box) -> Result + Send + Sync>, } pub struct ValueMeta {