use rustlavel::prelude::*;
use crate::support::settings::Settings;
pub const DEFAULT: &str = "dashboard";
pub async fn path(req: &Request) -> String {
let raw = match req.state::<Settings>() {
Some(settings) => settings.get("menus.home").await,
None => String::new(),
};
resolve(req, raw.trim())
}
fn resolve(req: &Request, raw: &str) -> String {
if raw.starts_with('/') {
return raw.to_string();
}
let name = if raw.is_empty() { DEFAULT } else { raw };
req.state::<rustlavel::NamedRoutes>()
.and_then(|routes| routes.url_for(name, &[]))
.unwrap_or_else(|| "/dashboard".to_string())
}
pub fn is_valid(req: &Request, raw: &str) -> bool {
let raw = raw.trim();
if raw.is_empty() {
return true;
}
if raw.starts_with('/') {
return !raw.starts_with("//");
}
req.state::<rustlavel::NamedRoutes>()
.is_some_and(|routes| routes.url_for(raw, &[]).is_some())
}