with open('proxy_server.py', 'r', encoding='utf-8') as f:
    content = f.read()

import re

# Add the /api/midas-status endpoint
target_regex = r"if parsed\.path == '/api/midas-login':"

new_code = """if parsed.path == '/api/midas-status':
            try:
                import os
                session_path = os.path.join(BASE_DIR, 'session_state.json')
                is_active = os.path.exists(session_path)
                self._send_json(200, {'success': True, 'active': is_active})
            except Exception as e:
                self._send_json(500, {'success': False, 'error': str(e)})
            return

        if parsed.path == '/api/midas-login':"""

if '/api/midas-status' not in content:
    content = content.replace("if parsed.path == '/api/midas-login':", new_code)

with open('proxy_server.py', 'w', encoding='utf-8') as f:
    f.write(content)
print("PROXY STATUS EKLENDI!")
