-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_status.py
More file actions
32 lines (27 loc) · 949 Bytes
/
Copy pathapi_status.py
File metadata and controls
32 lines (27 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from fastapi import APIRouter
import os
router = APIRouter()
@router.get("/status")
def get_status():
"""Return health and basic metadata for the UI status panel."""
try:
db_path = os.path.join(os.path.dirname(__file__), "vector_db")
documents = 0
last_update = "N/A"
if os.path.isdir(db_path):
files = [f for f in os.listdir(db_path) if os.path.isfile(os.path.join(db_path, f))]
documents = len(files)
mtimes = [os.path.getmtime(os.path.join(db_path, f)) for f in files]
if mtimes:
import datetime
last_update = datetime.datetime.fromtimestamp(
max(mtimes), tz=datetime.timezone.utc
).strftime("%Y-%m-%d")
except Exception:
documents = 0
last_update = "N/A"
return {
"ready": True,
"documents": documents,
"last_update": last_update
}