From 7dfc10eb0b405fa3d3d98851f477a4b30f8372eb Mon Sep 17 00:00:00 2001 From: Broque Thomas Date: Fri, 27 Feb 2026 08:50:50 -0800 Subject: [PATCH] Store sync status in database instead of JSON file Sync status was being saved to storage/sync_status.json on disk, which fails in Docker with permission denied errors. Moved to the existing database preference system so it works in all environments. --- web_server.py | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/web_server.py b/web_server.py index 632ed440..6b0a1c03 100644 --- a/web_server.py +++ b/web_server.py @@ -17388,41 +17388,23 @@ def start_missing_downloads(): # =============================== def _load_sync_status_file(): - """Helper function to read the sync status JSON file.""" - # Storage folder is at the same level as web_server.py - status_file = os.path.join(os.path.dirname(__file__), 'storage', 'sync_status.json') - print(f"🔍 Loading sync status from: {status_file}") - - if not os.path.exists(status_file): - print(f"❌ Sync status file does not exist: {status_file}") - return {} - + """Load sync statuses from database.""" try: - with open(status_file, 'r') as f: - content = f.read() - if not content: - print(f"⚠️ Sync status file is empty") - return {} - - data = json.loads(content) - print(f"✅ Loaded {len(data)} sync statuses from file") - for playlist_id, status in list(data.items())[:3]: # Show first 3 - print(f" - {playlist_id}: {status.get('name', 'N/A')} -> {status.get('last_synced', 'N/A')}") + database = get_database() + raw = database.get_preference('sync_statuses') + if raw: + data = json.loads(raw) return data - except (json.JSONDecodeError, FileNotFoundError) as e: + return {} + except Exception as e: print(f"❌ Error loading sync status: {e}") return {} def _save_sync_status_file(sync_statuses): - """Helper function to save the sync status JSON file.""" + """Save sync statuses to database.""" try: - # Storage folder is at the same level as web_server.py - storage_dir = os.path.join(os.path.dirname(__file__), 'storage') - os.makedirs(storage_dir, exist_ok=True) - status_file = os.path.join(storage_dir, 'sync_status.json') - with open(status_file, 'w') as f: - json.dump(sync_statuses, f, indent=4) - print(f"✅ Sync status saved to {status_file}") + database = get_database() + database.set_preference('sync_statuses', json.dumps(sync_statuses)) except Exception as e: print(f"❌ Error saving sync status: {e}")