refactor proto files + added metrics token
All checks were successful
Build and Push Image / build-and-push (push) Successful in 5m24s

This commit is contained in:
2025-07-06 01:28:52 -04:00
parent cc64675c9c
commit 7427bbb576
14 changed files with 170 additions and 112 deletions

View File

@@ -8,8 +8,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.build_server(false)
.build_client(true)
.compile_protos(
&["../AobaServer/Proto/Aoba.proto", "../AobaServer/Proto/Auth.proto"],
&["../AobaServer/Proto/"],
&[
"../AobaServer/Proto/Aoba.proto",
"../AobaServer/Proto/Auth.proto",
"../AobaServer/Proto/Metrics.proto",
"../AobaServer/Proto/Types.proto",
],
&["../AobaServer/"],
)?;
forward_env();
Ok(())

View File

@@ -0,0 +1,25 @@
use dioxus::prelude::*;
use crate::rpc::get_metrics_rpc_client;
#[component]
pub fn MetricsToken() -> Element {
let token = use_resource(async move || {
let response = get_metrics_rpc_client().get_token(()).await;
if let Ok(d) = response {
let jwt = d.into_inner();
return jwt.token;
}
return "".to_string();
});
let token_value = token.cloned().unwrap_or("".to_string());
return rsx! {
pre {
class: "codeSelect",
"{token_value}"
}
};
}

View File

@@ -1,11 +1,13 @@
pub mod basic;
mod media_grid;
mod media_item;
mod metrics_token;
mod navbar;
mod notif;
mod search;
pub use media_grid::*;
pub use media_item::*;
pub use metrics_token::*;
pub use navbar::*;
pub use notif::*;
pub use search::*;

View File

@@ -1,5 +1,3 @@
use std::env;
use dioxus::prelude::*;
use crate::{Route, contexts::AuthContext, env::APP_VERSION};

View File

@@ -1,19 +1,22 @@
use std::sync::RwLock;
use aoba::{aoba_rpc_client::AobaRpcClient, auth_rpc_client::AuthRpcClient};
use aoba::aoba_rpc_client::AobaRpcClient;
use tonic::service::{Interceptor, interceptor::InterceptedService};
use tonic_web_wasm_client::Client;
use crate::RPC_HOST;
use crate::{
RPC_HOST,
rpc::aoba::{auth_rpc_client::AuthRpcClient, metrics_rpc_client::MetricsRpcClient},
};
pub mod aoba {
tonic::include_proto!("aoba");
tonic::include_proto!("aoba.auth");
}
static RPC_CLIENT: RpcConnection = RpcConnection {
aoba: RwLock::new(None),
auth: RwLock::new(None),
metrics: RwLock::new(None),
jwt: RwLock::new(None),
};
@@ -21,6 +24,7 @@ static RPC_CLIENT: RpcConnection = RpcConnection {
pub struct RpcConnection {
aoba: RwLock<Option<AobaRpcClient<InterceptedService<Client, AuthInterceptor>>>>,
auth: RwLock<Option<AuthRpcClient<Client>>>,
metrics: RwLock<Option<MetricsRpcClient<InterceptedService<Client, AuthInterceptor>>>>,
jwt: RwLock<Option<String>>,
}
@@ -35,12 +39,19 @@ impl RpcConnection {
return self.auth.read().unwrap().clone().unwrap();
}
pub fn get_metrics_client(&self) -> MetricsRpcClient<InterceptedService<Client, AuthInterceptor>> {
self.ensure_client();
return self.metrics.read().unwrap().clone().unwrap();
}
fn ensure_client(&self) {
if self.aoba.read().unwrap().is_none() {
let wasm_client = Client::new(RPC_HOST.into());
let aoba_client = AobaRpcClient::with_interceptor(wasm_client.clone(), AuthInterceptor);
*self.aoba.write().unwrap() = Some(aoba_client);
*self.auth.write().unwrap() = Some(AuthRpcClient::new(wasm_client.clone()));
*self.metrics.write().unwrap() =
Some(MetricsRpcClient::with_interceptor(wasm_client.clone(), AuthInterceptor));
}
}
}
@@ -66,6 +77,9 @@ pub fn get_auth_rpc_client() -> AuthRpcClient<Client> {
return RPC_CLIENT.get_auth_client();
}
pub fn get_metrics_rpc_client() -> MetricsRpcClient<InterceptedService<Client, AuthInterceptor>> {
return RPC_CLIENT.get_metrics_client();
}
pub fn login(jwt: String) {
*RPC_CLIENT.jwt.write().unwrap() = Some(jwt);
}

View File

@@ -1,6 +1,6 @@
use dioxus::prelude::*;
use crate::rpc::get_rpc_client;
use crate::{components::MetricsToken, rpc::get_rpc_client};
#[component]
pub fn Settings() -> Element {
@@ -27,5 +27,6 @@ pub fn Settings() -> Element {
div {
pre { class: "codeSelect", "{d}" }
}
MetricsToken { }
}
}