From 00ade1af4018a2432085eefa5aca7b8c4aa35b50 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Wed, 29 May 2024 10:34:45 -0500 Subject: [PATCH] fix: Do not allow empty values for db_url or site_url --- actix/src/main.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/actix/src/main.rs b/actix/src/main.rs index 4b8b56f..9a444c3 100644 --- a/actix/src/main.rs +++ b/actix/src/main.rs @@ -60,7 +60,10 @@ async fn getall(data: web::Data, session: Session) -> HttpResponse { // Get the site URL #[get("/api/siteurl")] async fn siteurl() -> HttpResponse { - let site_url = env::var("site_url").unwrap_or(String::from("unset")); + let site_url = env::var("site_url") + .ok() + .filter(|s| !s.trim().is_empty()) + .unwrap_or(String::from("unset")); HttpResponse::Ok().body(site_url) } @@ -151,7 +154,11 @@ async fn main() -> Result<()> { // Generate session key in runtime so that restart invalidates older logins let secret_key = Key::generate(); - let db_location = env::var("db_url").unwrap_or(String::from("/urls.sqlite")); + let db_location = env::var("db_url") + .ok() + .filter(|s| !s.trim().is_empty()) + .unwrap_or(String::from("unset")); + let port = env::var("port") .unwrap_or(String::from("4567")) .parse::() @@ -170,7 +177,7 @@ async fn main() -> Result<()> { ) // Maintain a single instance of database throughout .app_data(web::Data::new(AppState { - db: database::open_db(env::var("db_url").unwrap_or(db_location.clone())), + db: database::open_db(db_location.clone()), })) .service(link_handler) .service(getall)