Add servermode

This commit is contained in:
2025-04-18 10:32:00 +02:00
parent 41c0dd1957
commit 218a73a1e0
2 changed files with 20 additions and 6 deletions

View File

@@ -105,6 +105,8 @@ async fn add_userid_by_card(
let rating = shared.rating.load(Ordering::Relaxed);
eprintln!("Received: Usercard: {user_card}, with associated rating: {rating}");
let user_id = match shared.database.user_get_id(&user_card).await {
Ok(id) => id,
Err(e) => {

View File

@@ -5,7 +5,7 @@ mod userinterface;
use std::{env::args, sync::Arc, thread::sleep, time::Duration};
use tokio::sync::watch;
use tokio::{join, sync::watch};
#[tokio::main]
async fn main() {
@@ -19,6 +19,8 @@ async fn main() {
// Create the tables on an empty database
db.create_tables().await.unwrap();
let mut servermode = false;
if args().len() > 1 {
// Add a new user
let username = args().nth(1).unwrap();
@@ -40,13 +42,15 @@ async fn main() {
.await
.expect("Could not get ratings");
return;
}
} else if username == "-s" {
servermode = true;
} else {
let user_id = db.add_user(&username).await.expect("Could not add user");
println!("UserID for {username}: {user_id}");
}
return;
}
}
}
let is_empty = db
.users_empty()
@@ -78,10 +82,18 @@ async fn main() {
// Create the HTTP backend
let db_http = db.clone();
tokio::spawn(async move {
let http_handle = tokio::spawn(async move {
http_server::http_serve(&db_http, mpris_tx_http).await;
});
if servermode {
eprintln!("Servermode...");
let res = join!(http_handle);
if let Err(e) = res.0 {
eprintln!("{e}");
}
}
loop {
let (usernumber, userrating) = userinterface::get_user_rating(&db)
.await