Add servermode
This commit is contained in:
@@ -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) => {
|
||||
|
24
src/main.rs
24
src/main.rs
@@ -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,12 +42,14 @@ 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 user_id = db.add_user(&username).await.expect("Could not add user");
|
||||
println!("UserID for {username}: {user_id}");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let is_empty = db
|
||||
@@ -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
|
||||
|
Reference in New Issue
Block a user