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.
This commit is contained in:
parent
c4bf6ff0f3
commit
7dfc10eb0b
1 changed files with 10 additions and 28 deletions
|
|
@ -17388,41 +17388,23 @@ def start_missing_downloads():
|
||||||
# ===============================
|
# ===============================
|
||||||
|
|
||||||
def _load_sync_status_file():
|
def _load_sync_status_file():
|
||||||
"""Helper function to read the sync status JSON file."""
|
"""Load sync statuses from database."""
|
||||||
# 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 {}
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(status_file, 'r') as f:
|
database = get_database()
|
||||||
content = f.read()
|
raw = database.get_preference('sync_statuses')
|
||||||
if not content:
|
if raw:
|
||||||
print(f"⚠️ Sync status file is empty")
|
data = json.loads(raw)
|
||||||
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')}")
|
|
||||||
return data
|
return data
|
||||||
except (json.JSONDecodeError, FileNotFoundError) as e:
|
return {}
|
||||||
|
except Exception as e:
|
||||||
print(f"❌ Error loading sync status: {e}")
|
print(f"❌ Error loading sync status: {e}")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def _save_sync_status_file(sync_statuses):
|
def _save_sync_status_file(sync_statuses):
|
||||||
"""Helper function to save the sync status JSON file."""
|
"""Save sync statuses to database."""
|
||||||
try:
|
try:
|
||||||
# Storage folder is at the same level as web_server.py
|
database = get_database()
|
||||||
storage_dir = os.path.join(os.path.dirname(__file__), 'storage')
|
database.set_preference('sync_statuses', json.dumps(sync_statuses))
|
||||||
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}")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"❌ Error saving sync status: {e}")
|
print(f"❌ Error saving sync status: {e}")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue