mirror of
https://git.alemi.dev/mumble-stats-api.git
synced 2024-12-19 03:14:53 +01:00
Compare commits
No commits in common. "df185e25177cc1a81437337c323b297e1d17c753" and "40a95b4d0a0ff4d540ac8eb2543c396e7ea22e3a" have entirely different histories.
df185e2517
...
40a95b4d0a
5 changed files with 2 additions and 2020 deletions
4
.tci
4
.tci
|
@ -1,9 +1,9 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
cargo build --release --all-features
|
cargo build --release
|
||||||
echo "stopping service"
|
echo "stopping service"
|
||||||
systemctl --user stop mumble-stats
|
systemctl --user stop mumble-stats
|
||||||
echo "replacing binary"
|
echo "replacing binary"
|
||||||
mv ./target/release/mumble-stats-api /opt/bin/mumble-stats-api
|
cat ./target/release/mumble-stats-api > /opt/bin/mumble-stats-api
|
||||||
echo "restarting service"
|
echo "restarting service"
|
||||||
systemctl --user start mumble-stats
|
systemctl --user start mumble-stats
|
||||||
|
|
1964
Cargo.lock
generated
1964
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -22,14 +22,12 @@ tokio = { version = "1.36", features = ["net", "macros", "rt-multi-thread", "io-
|
||||||
tokio-native-tls = "0.3.1"
|
tokio-native-tls = "0.3.1"
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-subscriber = "0.3.18"
|
tracing-subscriber = "0.3.18"
|
||||||
reqwest = { version = "0.12", optional = true }
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
prost-build = "0.12"
|
prost-build = "0.12"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
ntfy = ["dep:reqwest"]
|
|
||||||
|
|
||||||
[lints.rust]
|
[lints.rust]
|
||||||
unsafe_code = "forbid"
|
unsafe_code = "forbid"
|
||||||
|
|
51
src/main.rs
51
src/main.rs
|
@ -46,14 +46,6 @@ struct CliArgs {
|
||||||
/// disable arbitrary server join and peek
|
/// disable arbitrary server join and peek
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
no_peek: bool,
|
no_peek: bool,
|
||||||
|
|
||||||
/// ntfy.sh server to use for notifications
|
|
||||||
#[arg(long, default_value = "https://ntfy.sh")]
|
|
||||||
ntfy: String,
|
|
||||||
|
|
||||||
/// ntfy.sh topic to use for notifications, leave empty to disable notifications
|
|
||||||
#[arg(long)]
|
|
||||||
topic: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -81,14 +73,6 @@ async fn main() {
|
||||||
// app = app.route("/peek", get(peek_server));
|
// app = app.route("/peek", get(peek_server));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
#[cfg(feature = "ntfy")]
|
|
||||||
if let Some(topic) = args.topic {
|
|
||||||
tracing::info!("starting ntfy worker");
|
|
||||||
let events = session.events();
|
|
||||||
let target = format!("{}/{topic}", args.ntfy);
|
|
||||||
tokio::spawn(async move { handle_ntfy(target, events).await });
|
|
||||||
}
|
|
||||||
|
|
||||||
let app = app
|
let app = app
|
||||||
.route("/info", get(server_info))
|
.route("/info", get(server_info))
|
||||||
.route("/users", get(server_users))
|
.route("/users", get(server_users))
|
||||||
|
@ -116,41 +100,6 @@ async fn server_ws(ws: WebSocketUpgrade, State(session): State<Arc<Session>>) ->
|
||||||
ws.on_upgrade(|socket| handle_ws(socket, sub))
|
ws.on_upgrade(|socket| handle_ws(socket, sub))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ntfy")]
|
|
||||||
async fn handle_ntfy(target: String, mut sub: broadcast::Receiver<session::SessionEvent>) {
|
|
||||||
use std::collections::HashMap;
|
|
||||||
let client = reqwest::Client::new();
|
|
||||||
let mut users = HashMap::new();
|
|
||||||
|
|
||||||
while let Ok(event) = sub.recv().await {
|
|
||||||
if let Err(e) = match event {
|
|
||||||
session::SessionEvent::AddUser(user) => {
|
|
||||||
users.insert(user.session, user.name.clone());
|
|
||||||
client
|
|
||||||
.post(&target)
|
|
||||||
.body(format!("user {} connected", user.name))
|
|
||||||
.header("Title", "mumble")
|
|
||||||
.header("Priority", "default")
|
|
||||||
.header("Tags", "studio_microphone")
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
},
|
|
||||||
session::SessionEvent::RemoveUser(id) =>
|
|
||||||
client
|
|
||||||
.post(&target)
|
|
||||||
.body(format!("user {} left", users.remove(&id).unwrap_or_default()))
|
|
||||||
.header("Title", "mumble")
|
|
||||||
.header("Priority", "default")
|
|
||||||
.header("Tags", "x")
|
|
||||||
.send()
|
|
||||||
.await,
|
|
||||||
} {
|
|
||||||
tracing::debug!("events channel closed: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tracing::info!("stopping ntfy worker");
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn handle_ws(mut socket: WebSocket, mut sub: broadcast::Receiver<session::SessionEvent>) {
|
async fn handle_ws(mut socket: WebSocket, mut sub: broadcast::Receiver<session::SessionEvent>) {
|
||||||
while let Ok(event) = sub.recv().await {
|
while let Ok(event) = sub.recv().await {
|
||||||
if let Err(e) = match event {
|
if let Err(e) = match event {
|
||||||
|
|
|
@ -41,7 +41,6 @@ impl ControlChannel {
|
||||||
let size = rx.read_u32().await?;
|
let size = rx.read_u32().await?;
|
||||||
let mut buffer = vec![0u8; size as usize];
|
let mut buffer = vec![0u8; size as usize];
|
||||||
rx.read_exact(&mut buffer).await?;
|
rx.read_exact(&mut buffer).await?;
|
||||||
drop(rx);
|
|
||||||
super::proto::Packet::decode(id, &buffer)
|
super::proto::Packet::decode(id, &buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue