diff --git a/server.py b/server.py index 8b0e768..a88430c 100644 --- a/server.py +++ b/server.py @@ -32,12 +32,23 @@ from typing import Optional, List # ─── Config ───────────────────────────────────────────────────────────────── -VALID_CATEGORIES = {"Furniture", "Appliances", "Utensils & Serveware", "Equipment", "Other"} -VALID_STATUSES = {"active", "maintenance", "retired"} DB_PATH = os.environ.get("CANTEEN_DB_PATH", str(Path(__file__).parent / "assets.db")) UPLOADS_DIR = Path(os.environ.get("CANTEEN_UPLOADS_DIR", str(Path(__file__).parent / "uploads"))) STATIC_DIR = Path(__file__).parent / "static" +def _load_categories() -> set: + """Load valid category names from the categories lookup table.""" + try: + conn = sqlite3.connect(DB_PATH) + names = {r[0] for r in conn.execute("SELECT name FROM categories").fetchall()} + conn.close() + return names if names else {"Other"} + except Exception: + return {"Furniture", "Appliances", "Utensils & Serveware", "Equipment", "Other"} + +VALID_CATEGORIES = _load_categories() +VALID_STATUSES = {"active", "maintenance", "retired"} + # ─── Database ───────────────────────────────────────────────────────────────