From e75f1892eaf2b3cd5fd9e7fd8d20450939e2fe97 Mon Sep 17 00:00:00 2001 From: Stalin S Date: Thu, 21 May 2026 13:50:34 +0530 Subject: [PATCH] Updated frontend --- backend/database/db.py | 14 ++++++++++++- backend/main.py | 45 ++++++++++++++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/backend/database/db.py b/backend/database/db.py index 5203cf6..bda816c 100644 --- a/backend/database/db.py +++ b/backend/database/db.py @@ -9,7 +9,19 @@ import time import json from typing import Optional -DB_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "archstore.db") +# Determine writable database path based on install directory type +is_system_install = os.path.dirname(os.path.dirname(__file__)).startswith("/usr") +if is_system_install: + xdg_data_home = os.environ.get("XDG_DATA_HOME") + if xdg_data_home: + data_dir = os.path.join(xdg_data_home, "archstore") + else: + data_dir = os.path.join(os.path.expanduser("~"), ".local", "share", "archstore") + os.makedirs(data_dir, exist_ok=True) + DB_PATH = os.path.join(data_dir, "archstore.db") +else: + DB_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "archstore.db") + CACHE_TTL = 900 # 15 minutes in seconds diff --git a/backend/main.py b/backend/main.py index ed88465..50b0635 100644 --- a/backend/main.py +++ b/backend/main.py @@ -12,6 +12,8 @@ sys.path.insert(0, os.path.dirname(__file__)) from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware +from fastapi.staticfiles import StaticFiles +from fastapi.responses import FileResponse from database.db import db from api.routes import packages, updates, categories @@ -55,16 +57,6 @@ app.include_router(updates.router) app.include_router(categories.router) -@app.get("/") -async def root(): - """Health check endpoint.""" - return { - "name": "ArchStore API", - "version": "1.0.0", - "status": "running", - } - - @app.get("/api/health") async def health(): """Detailed health check.""" @@ -80,3 +72,36 @@ async def clear_cache(): """Clear all cached data.""" await db.clear_cache() return {"status": "ok", "message": "Cache cleared"} + + +# Frontend Static Files Serving for Production / Desktop Launch +STATIC_DIR = "/usr/share/archstore/frontend" +if not os.path.exists(STATIC_DIR): + STATIC_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "frontend", "dist") + +if os.path.exists(STATIC_DIR): + assets_dir = os.path.join(STATIC_DIR, "assets") + if os.path.exists(assets_dir): + app.mount("/assets", StaticFiles(directory=assets_dir), name="assets") + + @app.get("/{fallback_path:path}") + async def serve_frontend(fallback_path: str): + # Serve favicon or other root files directly if they exist + file_path = os.path.join(STATIC_DIR, fallback_path) + if fallback_path and os.path.exists(file_path) and os.path.isfile(file_path): + return FileResponse(file_path) + # Otherwise fallback to index.html for React SPA routing + index_path = os.path.join(STATIC_DIR, "index.html") + if os.path.exists(index_path): + return FileResponse(index_path) +else: + @app.get("/") + async def root(): + """Health check fallback when static files are missing.""" + return { + "name": "ArchStore API", + "version": "1.0.0", + "status": "running", + "info": "Frontend static files not found. Run dev server on port 5173." + } +