Move sse route to separate module
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
Sijmen 2023-12-23 10:55:18 +01:00
parent 59bc10a329
commit 8a01102302
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48
3 changed files with 21 additions and 19 deletions

View file

@ -2,24 +2,6 @@ mod crate_version;
mod mpd;
mod routes;
async fn sse(_req: tide::Request<()>, sender: tide::sse::Sender) -> tide::Result<()> {
// Update everything on connect
sender.send("playlist", "", None).await?;
sender.send("player", "", None).await?;
let mut mpd = mpd::Mpd::new();
mpd.connect().await.unwrap();
loop {
let systems = mpd
.idle(&["playlist", "player", "database", "options"])
.await?;
for system in systems {
sender.send(&system, "", None).await?;
}
}
}
#[async_std::main]
async fn main() -> tide::Result<()> {
tracing_subscriber::fmt()
@ -34,7 +16,7 @@ async fn main() -> tide::Result<()> {
app.at("/browser").get(routes::browser::get_browser);
app.at("/art").get(routes::art::get_art);
app.at("/sse").get(tide::sse::endpoint(sse));
app.at("/sse").get(tide::sse::endpoint(routes::sse::sse));
app.at("/queue").get(routes::queue::get_queue);
app.at("/queue").post(routes::queue::post_queue);

View file

@ -4,3 +4,4 @@ pub mod index;
pub mod player;
pub mod queue;
pub mod controls;
pub mod sse;

19
src/routes/sse.rs Normal file
View file

@ -0,0 +1,19 @@
use crate::mpd;
pub async fn sse(_req: tide::Request<()>, sender: tide::sse::Sender) -> tide::Result<()> {
// Update everything on connect
sender.send("playlist", "", None).await?;
sender.send("player", "", None).await?;
let mut mpd = mpd::Mpd::new();
mpd.connect().await.unwrap();
loop {
let systems = mpd
.idle(&["playlist", "player", "database", "options"])
.await?;
for system in systems {
sender.send(&system, "", None).await?;
}
}
}