From f3b09e2a091f796cfabc7422b256c69e136f14a2 Mon Sep 17 00:00:00 2001 From: nickviljoen Date: Thu, 26 Mar 2026 13:10:52 +0200 Subject: [PATCH] Fix saved output files showing across all clients - Auto-save reports to client-specific subfolder (was saving to root) - Read client_id from form data (matching what frontend sends) - Add Amazon to profile-based client detection fallback - Fix get_client_from_profile matching 'static' as L'Oreal Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/api_server.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/api_server.py b/backend/api_server.py index 589df53..28918f4 100755 --- a/backend/api_server.py +++ b/backend/api_server.py @@ -754,12 +754,14 @@ def get_client_from_profile(profile_id): return 'general' profile_lower = profile_id.lower() - if 'loreal' in profile_lower or 'static' in profile_lower: + if profile_lower.startswith('loreal'): return 'loreal' - elif 'diageo' in profile_lower: + elif profile_lower.startswith('diageo'): return 'diageo' - elif 'unilever' in profile_lower: + elif profile_lower.startswith('unilever'): return 'unilever' + elif profile_lower.startswith('amazon'): + return 'amazon' else: return 'general' @@ -1563,7 +1565,7 @@ def start_analysis(): file.save(file_path) # Derive client from profile if not provided - client = request.form.get('client', 'general').lower() + client = request.form.get('client_id', request.form.get('client', 'general')).lower() if not client or client == 'general': if profile.startswith('diageo_'): client = 'diageo' @@ -1571,6 +1573,8 @@ def start_analysis(): client = 'unilever' elif profile.startswith('loreal_'): client = 'loreal' + elif profile.startswith('amazon_'): + client = 'amazon' else: client = 'general' @@ -3185,10 +3189,11 @@ def api_analyze_with_triage(): # Generate comprehensive HTML report using the same format as the web UI html_report_content = generate_comprehensive_html_report(response_data, file.filename, file_path) - # Create output filename + # Create output filename in client-specific folder safe_filename = re.sub(r'[^a-zA-Z0-9.-]', '_', file.filename) output_filename = f"{session_id}_{safe_filename}_report.html" - output_path = os.path.join(app.config['OUTPUT_FOLDER'], output_filename) + client_output_folder = ensure_client_output_folder(client) + output_path = os.path.join(client_output_folder, output_filename) # Save HTML report to output directory with open(output_path, 'w', encoding='utf-8') as f: