Spaces:
Sleeping
Sleeping
| import os | |
| from flask import Flask, render_template, request, jsonify, send_from_directory | |
| from flask_cors import CORS | |
| from werkzeug.utils import secure_filename | |
| from pdf_logic import process_comparison | |
| app = Flask(__name__) | |
| CORS(app) | |
| # Configuration | |
| UPLOAD_FOLDER = 'static/uploads' | |
| OUTPUT_FOLDER = 'static/output' | |
| os.makedirs(UPLOAD_FOLDER, exist_ok=True) | |
| os.makedirs(OUTPUT_FOLDER, exist_ok=True) | |
| def compare(): | |
| if 'source' not in request.files or 'destination' not in request.files: | |
| return jsonify({'error': 'Missing files'}), 400 | |
| source_file = request.files['source'] | |
| dest_file = request.files['destination'] | |
| s_path = os.path.join(UPLOAD_FOLDER, secure_filename(source_file.filename)) | |
| d_path = os.path.join(UPLOAD_FOLDER, secure_filename(dest_file.filename)) | |
| source_file.save(s_path) | |
| dest_file.save(d_path) | |
| try: | |
| # Run the comparison logic | |
| src_out, dest_out, changes, total_pages = process_comparison(s_path, d_path, OUTPUT_FOLDER) | |
| return jsonify({ | |
| 'status': 'success', | |
| 'source_pdf': f"/static/output/{src_out}", | |
| 'dest_pdf': f"/static/output/{dest_out}", | |
| 'changes': changes, | |
| 'total_pages': total_pages | |
| }) | |
| except Exception as e: | |
| print(e) | |
| return jsonify({'error': str(e)}), 500 | |
| # WorkOS Configuration | |
| import workos | |
| from workos import WorkOSClient | |
| # Initialize WorkOS Client | |
| # In production, use environment variables: os.environ.get('WORKOS_API_KEY') | |
| # For now we will check if they exist, otherwise these endpoints will fail gracefully or you can hardcode for testing if needed | |
| workos.api_key = os.environ.get('WORKOS_API_KEY', 'placeholder_key') | |
| workos.client_id = os.environ.get('WORKOS_CLIENT_ID', 'placeholder_id') | |
| workos_client = WorkOSClient(api_key=workos.api_key, client_id=workos.client_id) | |
| def logout_everywhere(): | |
| """ | |
| Revokes ALL sessions for the user. | |
| Expects JSON: { "userId": "user_..." } | |
| """ | |
| data = request.json | |
| user_id = data.get('userId') | |
| if not user_id: | |
| return jsonify({'error': 'Missing userId'}), 400 | |
| try: | |
| # List all sessions | |
| sessions_list = workos_client.user_management.list_sessions(user_id=user_id) | |
| # Revoke all | |
| for session in sessions_list.data: | |
| workos_client.user_management.revoke_session(session_id=session.id) | |
| return jsonify({'status': 'success', 'message': 'All sessions revoked.'}) | |
| except Exception as e: | |
| print(f"WorkOS Error: {e}") | |
| return jsonify({'error': str(e)}), 500 | |
| app.run(host="0.0.0.0", port=7860, debug=True) |