Updated frontend

This commit is contained in:
2026-05-21 13:50:34 +05:30
parent 6b3f08383b
commit e75f1892ea
2 changed files with 48 additions and 11 deletions
+13 -1
View File
@@ -9,7 +9,19 @@ import time
import json import json
from typing import Optional 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 CACHE_TTL = 900 # 15 minutes in seconds
+35 -10
View File
@@ -12,6 +12,8 @@ sys.path.insert(0, os.path.dirname(__file__))
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
from database.db import db from database.db import db
from api.routes import packages, updates, categories from api.routes import packages, updates, categories
@@ -55,16 +57,6 @@ app.include_router(updates.router)
app.include_router(categories.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") @app.get("/api/health")
async def health(): async def health():
"""Detailed health check.""" """Detailed health check."""
@@ -80,3 +72,36 @@ async def clear_cache():
"""Clear all cached data.""" """Clear all cached data."""
await db.clear_cache() await db.clear_cache()
return {"status": "ok", "message": "Cache cleared"} 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."
}