From d6dc15b4a3c6e4f57b1195014ca49a110cf1267f Mon Sep 17 00:00:00 2001 From: Nathan Lamy Date: Tue, 26 Aug 2025 00:27:33 +0200 Subject: [PATCH] chore: fix a few issues --- src/api.rs | 2 +- src/main.rs | 16 +++++++++++----- src/parser/auth.rs | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/api.rs b/src/api.rs index e398296..ac09579 100644 --- a/src/api.rs +++ b/src/api.rs @@ -107,7 +107,7 @@ pub async fn post_submittable_meals( pub async fn post_selected_meals( meals: &[Meal], - user_id: &str, + user_id: &i64, config: &Settings, ) -> Result<(), Box> { let api_url = get_config(config, "api"); diff --git a/src/main.rs b/src/main.rs index d59d733..01c3a2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -183,8 +183,14 @@ async fn process_job( } } } else if job["type"] == 4 || job["type"] == 5 { - let user_id = job["user_id"].as_str().unwrap_or_default(); - println!("Submitting meals for user: {}", user_id); + let user_id = job["user_id"].as_number().unwrap().as_i64().unwrap_or(-1); + if user_id == -1 { + eprintln!("Job does not contain a valid user ID."); + return Err(redis::RedisError::from(( + redis::ErrorKind::InvalidClientConfig, + "Job missing valid user ID", + ))); + } // Authenticate (job data contains password and username) let username = job["bj_username"].as_str().unwrap_or_default(); @@ -212,7 +218,7 @@ async fn process_job( if job["type"] == 5 { // Set auth failed in Redis let auth_key = format!("auth_success_{}", user_id); - con.set_ex(&auth_key, false, 300)?; + con.set_ex(&auth_key, "ERROR", 300)?; } eprintln!("Failed to login: {}", err); return Err(redis::RedisError::from(( @@ -273,7 +279,7 @@ async fn process_job( let meals = meals.unwrap(); // Post selected meals to API - let res = post_selected_meals(&meals, user_id, config).await; + let res = post_selected_meals(&meals, &user_id, config).await; if res.is_err() { eprintln!("Failed to post selected meals: {}", res.unwrap_err()); return Err(redis::RedisError::from(( @@ -285,7 +291,7 @@ async fn process_job( } else if job["type"] == 5 { // Set auth successful in Redis let auth_key = format!("auth_success_{}", user_id); - con.set_ex(&auth_key, true, 300)?; + con.set_ex(&auth_key, "SUCCESS", 300)?; } } else { // Authenticate diff --git a/src/parser/auth.rs b/src/parser/auth.rs index 43ee4de..0ddcc34 100644 --- a/src/parser/auth.rs +++ b/src/parser/auth.rs @@ -59,7 +59,7 @@ pub async fn login( .collect(); if session_id.is_empty() { - return Err("Failed to get session ID".into()); + return Err("Invalid credentials".into()); } Ok(session_id.join("; "))