feat(brand-guidelines): route .xlsx uploads to excel_processor

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) <noreply@anthropic.com>
This commit is contained in:
nickviljoen 2026-05-17 21:02:05 +02:00
parent c51e0729ce
commit 295305ef2d

View file

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