outshine84 commited on
Commit
846bb94
·
1 Parent(s): 69bb39e

fix serve

Browse files
Files changed (1) hide show
  1. api.py +40 -1
api.py CHANGED
@@ -195,6 +195,13 @@ def _serve_pwa_index() -> HTMLResponse:
195
  raise HTTPException(status_code=503, detail="Frontend non disponibile.")
196
 
197
 
 
 
 
 
 
 
 
198
  def _format_datetime_display(value: Any) -> Any:
199
  raw_value = str(value or "").strip()
200
  if not raw_value:
@@ -224,7 +231,7 @@ def _normalize_image_path(raw_path: str) -> str:
224
 
225
  FAISS_CONFIDENCE_THRESHOLD = float(os.getenv("FAISS_CONFIDENCE_THRESHOLD", "0.82"))
226
  FAISS_AMBIGUITY_MARGIN = float(os.getenv("FAISS_AMBIGUITY_MARGIN", "0.015"))
227
- RRF_AMBIGUITY_MARGIN = float(os.getenv("RRF_AMBIGUITY_MARGIN", "0.0015"))
228
  FORCE_OPENAI_FALLBACK = os.getenv("FORCE_OPENAI_FALLBACK", "0").strip().lower() in {
229
  "1", "true", "yes", "on"
230
  }
@@ -1055,6 +1062,18 @@ app.add_middleware(
1055
  allow_headers=["*"],
1056
  )
1057
 
 
 
 
 
 
 
 
 
 
 
 
 
1058
 
1059
  def get_search_backend_status():
1060
  checks: dict[str, str] = {}
@@ -1634,6 +1653,26 @@ def search_status():
1634
  return get_search_backend_status()
1635
 
1636
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1637
  @app.get("/species/previews")
1638
  def species_previews(
1639
  names: list[str] = Query(default=[], description="Nomi specie da risolvere per anteprima immagine"),
 
195
  raise HTTPException(status_code=503, detail="Frontend non disponibile.")
196
 
197
 
198
+ def _serve_pwa_file(filename: str, media_type: str | None = None) -> FileResponse:
199
+ path = PWA_DIST_DIR / filename
200
+ if not path.exists() or not path.is_file():
201
+ raise HTTPException(status_code=404, detail=f"File statico non trovato: {filename}")
202
+ return FileResponse(path=str(path), media_type=media_type)
203
+
204
+
205
  def _format_datetime_display(value: Any) -> Any:
206
  raw_value = str(value or "").strip()
207
  if not raw_value:
 
231
 
232
  FAISS_CONFIDENCE_THRESHOLD = float(os.getenv("FAISS_CONFIDENCE_THRESHOLD", "0.82"))
233
  FAISS_AMBIGUITY_MARGIN = float(os.getenv("FAISS_AMBIGUITY_MARGIN", "0.015"))
234
+ RRF_AMBIGUITY_MARGIN = float(os.getenv("RRF_AMBIGUITY_MARGIN", "0.0025"))
235
  FORCE_OPENAI_FALLBACK = os.getenv("FORCE_OPENAI_FALLBACK", "0").strip().lower() in {
236
  "1", "true", "yes", "on"
237
  }
 
1062
  allow_headers=["*"],
1063
  )
1064
 
1065
+ # Serve PWA static assets generated by Vite build.
1066
+ app.mount(
1067
+ "/assets",
1068
+ StaticFiles(directory=str(PWA_DIST_DIR / "assets"), check_dir=False),
1069
+ name="pwa-assets",
1070
+ )
1071
+ app.mount(
1072
+ "/icons",
1073
+ StaticFiles(directory=str(PWA_DIST_DIR / "icons"), check_dir=False),
1074
+ name="pwa-icons",
1075
+ )
1076
+
1077
 
1078
  def get_search_backend_status():
1079
  checks: dict[str, str] = {}
 
1653
  return get_search_backend_status()
1654
 
1655
 
1656
+ @app.get("/sw.js")
1657
+ def pwa_sw_js():
1658
+ return _serve_pwa_file("sw.js", media_type="application/javascript")
1659
+
1660
+
1661
+ @app.get("/registerSW.js")
1662
+ def pwa_register_sw_js():
1663
+ return _serve_pwa_file("registerSW.js", media_type="application/javascript")
1664
+
1665
+
1666
+ @app.get("/manifest.webmanifest")
1667
+ def pwa_manifest():
1668
+ return _serve_pwa_file("manifest.webmanifest", media_type="application/manifest+json")
1669
+
1670
+
1671
+ @app.get("/favicon.ico")
1672
+ def pwa_favicon():
1673
+ return _serve_pwa_file("favicon.ico", media_type="image/x-icon")
1674
+
1675
+
1676
  @app.get("/species/previews")
1677
  def species_previews(
1678
  names: list[str] = Query(default=[], description="Nomi specie da risolvere per anteprima immagine"),