Spaces:
Sleeping
Sleeping
File size: 2,777 Bytes
f8a8bc3 06ff3fd f8a8bc3 06ff3fd f8a8bc3 7bee848 f8a8bc3 cf0324d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
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)
@app.route('/compare', methods=['POST'])
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)
@app.route('/auth/logout-everywhere', methods=['POST'])
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) |