Skip to content

Commit 9c5dda4

Browse files
committed
FIX proxying
1 parent b684bef commit 9c5dda4

File tree

6 files changed

+296
-89
lines changed

6 files changed

+296
-89
lines changed

theia/proxy-rs/Cargo.lock

+104
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

theia/proxy-rs/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ edition = "2021"
99
anyhow = "1.0.82"
1010
axum = { version = "0.7.5", features = ["ws"] }
1111
axum-extra = { version = "0.9.3", features = ["cookie"] }
12+
chrono = "0.4.38"
1213
futures-util = "0.3.30"
1314
hyper = "1.3.1"
14-
hyper-util = { version = "0.1.3", features = ["tokio"] }
15+
hyper-tungstenite = "0.13.0"
16+
hyper-util = { version = "0.1.3", features = ["client", "client-legacy"] }
1517
jsonwebtoken = "9.3.0"
1618
lazy_static = "1.4.0"
1719
serde = "1.0.200"

theia/proxy-rs/src/db.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use anyhow::Result;
2+
use serde::{Deserialize, Serialize};
3+
use sqlx::{prelude::FromRow, MySqlPool};
4+
5+
#[derive(Deserialize, Serialize, FromRow)]
6+
struct TheiaSession {
7+
cluster_address: Option<String>,
8+
}
9+
10+
pub async fn get_cluster_address(pool: &MySqlPool, session_id: &str) -> Result<String> {
11+
let row: Option<TheiaSession> = sqlx::query_as(
12+
r#"
13+
SELECT cluster_address
14+
FROM theia_session
15+
WHERE id = ? AND active = 1
16+
"#,
17+
)
18+
.bind(session_id)
19+
.fetch_optional(pool)
20+
.await?;
21+
22+
match row {
23+
Some(session) => {
24+
if let Some(cluster_address) = session.cluster_address {
25+
Ok(cluster_address)
26+
} else {
27+
Err(anyhow::anyhow!("cluster address not found"))
28+
}
29+
}
30+
None => Err(anyhow::anyhow!("session not found")),
31+
}
32+
}
33+
34+
pub async fn update_last_proxy_time(session_id: &str, pool: &MySqlPool) -> Result<()> {
35+
sqlx::query(
36+
r#"
37+
UPDATE theia_session
38+
SET last_proxy = NOW()
39+
WHERE id = ?
40+
"#,
41+
)
42+
.bind(session_id)
43+
.execute(pool)
44+
.await?;
45+
46+
Ok(())
47+
}

0 commit comments

Comments
 (0)