From 295305ef2dc47aa65fcea771afaaff136bcf7b24 Mon Sep 17 00:00:00 2001 From: nickviljoen Date: Sun, 17 May 2026 21:02:05 +0200 Subject: [PATCH] feat(brand-guidelines): route .xlsx uploads to excel_processor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The /api/brand_guidelines POST handler now dispatches by extension: .pdf → pdf_processor.process_pdf_file (existing), .xlsx → excel_processor.process_excel_file (new). Same DB record shape; cover image is null for Excel since there's no first-page analogue. Co-Authored-By: Claude Opus 4.7 (1M context) --- backend/api_server.py | 48 +++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/backend/api_server.py b/backend/api_server.py index 8f47d04..18df27c 100755 --- a/backend/api_server.py +++ b/backend/api_server.py @@ -4832,47 +4832,31 @@ def upload_brand_guideline(): ).start() file_record['processing_status'] = 'processing' - # Trigger localization matrix parsing for Excel files - elif file_record.get('file_type') in ('.xlsx', '.xls'): + # Trigger Excel file processing for .xlsx files + elif file_record.get('file_type') == '.xlsx': import threading - def _process_localization_bg(fid, spath, fdir): + def _process_excel_bg(fid, spath): try: - from localization_processor import parse_localization_matrix - parsed = parse_localization_matrix(spath) - if parsed: - # Save parsed JSON - json_path = os.path.join(fdir, f"{fid}_localization.json") - with open(json_path, 'w', encoding='utf-8') as f: - json.dump(parsed, f, indent=2, ensure_ascii=False) - brand_db.update_file_record(fid, { - 'processed': True, - 'processed_at': datetime.now().isoformat(), - 'localization_path': json_path, - 'localization_messages': list(parsed.get('messages', {}).keys()), - 'localization_countries': parsed.get('countries', []), - 'asset_type': 'localization_matrix', - }) - print(f"Localization matrix parsing complete for {fid}: " - f"{len(parsed.get('messages', {}))} messages, " - f"{len(parsed.get('countries', []))} countries") - else: - brand_db.update_file_record(fid, { - 'processed': True, - 'processed_at': datetime.now().isoformat(), - 'asset_type': 'excel_file', - }) - print(f"Excel file {fid} is not a localization matrix, stored as-is") + from excel_processor import process_excel_file + summary_text, summary_path = process_excel_file(spath, fid) + brand_db.update_file_record(fid, { + 'processed': True, + 'processed_at': datetime.now().isoformat(), + 'summary_path': summary_path, + 'summary_length': len(summary_text), + 'cover_image_path': None, + }) + print(f"Excel processing complete for {fid}") except Exception as e: - print(f"Localization matrix parsing failed for {fid}: {e}") + print(f"Excel processing failed for {fid}: {e}") brand_db.update_file_record(fid, { 'processed': 'error', 'processing_error': str(e) }) threading.Thread( - target=_process_localization_bg, - args=(file_record['id'], file_record['stored_path'], - str(brand_db.files_dir)), + target=_process_excel_bg, + args=(file_record['id'], file_record['stored_path']), daemon=True ).start() file_record['processing_status'] = 'processing'