diff --git a/scripts/api.py b/scripts/api.py index 9af2251..a903fc4 100644 --- a/scripts/api.py +++ b/scripts/api.py @@ -420,11 +420,12 @@ async def get_status(): watcher_running = False last_indexed = "Unknown" try: - result = subprocess.run( - ["systemctl", "is-active", "aaronai-watcher"], - capture_output=True, text=True - ) - watcher_running = result.stdout.strip() == "active" + import time as _time, json as _json + _sp = Path("/home/aaron/aaronai/watcher_status.json") + if _sp.exists(): + _s = _json.loads(_sp.read_text()) + _age = _time.time() - _s.get("timestamp", 0) + watcher_running = _s.get("running", False) and _age < 30 except: pass @@ -446,6 +447,12 @@ async def get_status(): if state_path.exists(): state = json.loads(state_path.read_text()) file_count = len(state) + else: + # Count files in Nextcloud directly + nc_path = Path(NEXTCLOUD_PATH) + if nc_path.exists(): + file_count = sum(1 for f in nc_path.rglob("*") + if f.is_file() and f.suffix.lower() in {'.pdf','.docx','.pptx','.txt','.md'}) except: pass diff --git a/scripts/watcher.py b/scripts/watcher.py index 7a5afd2..4121b2b 100644 --- a/scripts/watcher.py +++ b/scripts/watcher.py @@ -14,6 +14,7 @@ STATE_FILE = "/home/aaron/aaronai/watcher_state.json" SUPPORTED = {'.pdf', '.docx', '.pptx', '.txt', '.md'} DEBOUNCE_SECONDS = 120 +STATUS_FILE = "/home/aaron/aaronai/watcher_status.json" logging.basicConfig( level=logging.INFO, @@ -109,6 +110,13 @@ def main(): try: while True: + import json as _json + _json.dump({ + "running": True, + "timestamp": time.time(), + "pending": handler.pending, + "last_event": handler.last_event + }, open(STATUS_FILE, 'w')) if handler.pending: elapsed = time.time() - handler.last_event if elapsed >= DEBOUNCE_SECONDS: