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

ambee/giterated-api

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

Update to new structure

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨b49b7cd

Showing ⁨⁨4⁩ changed files⁩ with ⁨⁨42⁩ insertions⁩ and ⁨⁨39⁩ deletions⁩

Cargo.toml

View file
@@ -7,7 +7,7 @@ edition = "2021"
7 7
8 8 [dependencies]
9 9 #giterated-daemon = { git = "https://giterated.dev/ambee/giterated-daemon" }
10 giterated-daemon = { path = "../giterated-daemon" }
10 giterated-models = { path = "../giterated-daemon/giterated-models" }
11 11 tokio-tungstenite = { version = "*", features = ["rustls-tls-native-roots"] }
12 12 tokio = { version = "1.32.0", features = ["full"] }
13 13 tracing = "*"
@@ -22,4 +22,5 @@ reqwest = { version = "0.11" }
22 22 anyhow = "*"
23 23 deadpool = "*"
24 24 async-trait = "*"
25 thiserror = "*"
25 \ No newline at end of file
25 thiserror = "*"
26 semver = "*"
26 \ No newline at end of file

src/lib.rs

View file
@@ -1,11 +1,11 @@
1 1 pub mod request;
2 2
3 3 pub mod model {
4 pub use giterated_daemon::model::*;
4 pub use giterated_models::model::*;
5 5 }
6 6
7 7 pub mod messages {
8 pub use giterated_daemon::messages::*;
8 pub use giterated_models::messages::*;
9 9 }
10 10
11 11 use std::convert::Infallible;
@@ -13,20 +13,15 @@ use std::net::SocketAddr;
13 13 use std::str::FromStr;
14 14 use std::sync::Arc;
15 15
16
17 16 use deadpool::managed::{BuildError, Manager, Pool, RecycleError, RecycleResult};
18 17
19 18 use futures_util::{SinkExt, StreamExt};
20 19
21 use giterated_daemon::messages::handshake::{
22 HandshakeFinalize, HandshakeResponse, InitiateHandshake,
20 use giterated_models::{
21 messages::handshake::{HandshakeFinalize, HandshakeResponse, InitiateHandshake},
22 model::instance::Instance,
23 23 };
24
25
26 use giterated_daemon::model::instance::Instance;
27
28
29 use giterated_daemon::{validate_version, version};
24 use semver::Version;
30 25 use serde::Serialize;
31 26 use tokio::net::TcpStream;
32 27 use tokio_tungstenite::{connect_async, tungstenite::Message, MaybeTlsStream, WebSocketStream};
@@ -646,7 +641,13 @@ impl GiteratedApi {
646 641 _instance: &Instance,
647 642 ) -> Result<(), anyhow::Error> {
648 643 // Send handshake initiation
649 Self::send_message(&InitiateHandshake { version: version() }, socket).await?;
644 Self::send_message(
645 &InitiateHandshake {
646 version: Version::from_str("0.0.0").unwrap(),
647 },
648 socket,
649 )
650 .await?;
650 651
651 652 while let Some(message) = socket.next().await {
652 653 let message = match message {
@@ -684,19 +685,23 @@ impl GiteratedApi {
684 685 } else {
685 686 match serde_json::from_slice::<HandshakeResponse>(&payload) {
686 687 Ok(response) => {
687 let message = if !validate_version(&response.version) {
688 error!(
689 "Version compatibility failure! Our Version: {}, Their Version: {}",
690 version(),
691 response.version
692 );
693
694 HandshakeFinalize { success: false }
695 } else {
696 info!("Connected with a compatible version");
697
698 HandshakeFinalize { success: true }
699 };
688 // let message = if !validate_version(&response.version) {
689 // error!(
690 // "Version compatibility failure! Our Version: {}, Their Version: {}",
691 // version(),
692 // response.version
693 // );
694
695 // HandshakeFinalize { success: false }
696 // } else {
697 // info!("Connected with a compatible version");
698
699 // HandshakeFinalize { success: true }
700 // };
701
702 warn!("Version compatibility has been no-op'd");
703
704 let message = HandshakeFinalize { success: true };
700 705 // Send [`HandshakeFinalize`] to indicate if we're compatible or not
701 706 Self::send_message(&message, socket).await?;
702 707 }

src/main.rs

View file
@@ -1,12 +1,9 @@
1 1 use std::str::FromStr;
2 2
3 3 use giterated_api::DaemonConnectionPool;
4 use giterated_daemon::{
4 use giterated_api::{
5 5 messages::user::{UserBioRequest, UserBioResponse},
6 model::{
7 instance::Instance,
8 user::User,
9 },
6 model::{instance::Instance, user::User},
10 7 };
11 8
12 9 use serde::{Deserialize, Serialize};

src/request.rs

View file
@@ -1,8 +1,11 @@
1 1 use anyhow::Error;
2 2 use futures_util::{SinkExt, StreamExt};
3 use giterated_daemon::model::{
4 authenticated::{Authenticated, AuthenticationSourceProvider},
5 instance::Instance,
3 use giterated_models::{
4 messages::error::ConnectionError,
5 model::{
6 authenticated::{Authenticated, AuthenticationSourceProvider},
7 instance::Instance,
8 },
6 9 };
7 10 use serde::{de::DeserializeOwned, Serialize};
8 11 use tokio_tungstenite::tungstenite::Message;
@@ -65,10 +68,7 @@ impl<'a, T: Serialize + DeserializeOwned> PreparedRequest<'a, T> {
65 68
66 69 if as_target.is_err() {
67 70 // Maybe we got an error payload?
68 if let Ok(error_payload) = serde_json::from_slice::<
69 giterated_daemon::messages::error::ConnectionError,
70 >(&payload)
71 {
71 if let Ok(error_payload) = serde_json::from_slice::<ConnectionError>(&payload) {
72 72 return Err(error_payload.into());
73 73 }
74 74 } else {