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) <noreply@anthropic.com>
This commit is contained in:
nickviljoen 2026-03-26 13:10:52 +02:00
parent 06a6562a92
commit f3b09e2a09

View file

@ -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: